谷歌tts android手机自带引擎,自动下载android TTS引擎

乜建柏
2023-12-01

Is there a way to install a language automatically?

是的,但这不会自动发生(未经用户同意),如docs所述:

Since the installation of the data can be interrupted or declined by the user,the application shouldn’t expect successful installation upon return from that intent…

无论如何,你可以用this之类的东西触发安装:

/**

* Ask the current default engine to launch the matching INSTALL_TTS_DATA activity

* so the required TTS files are properly installed.

*/

private void installVoiceData() {

Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent.setPackage("com.google.android.tts"/*replace with the package name of the target TTS engine*/);

try {

Log.v(TAG,"Installing voice data: " + intent.toUri(0));

startActivity(intent);

} catch (ActivityNotFoundException ex) {

Log.e(TAG,"Failed to install TTS data,no acitivty found for " + intent + ")");

}

}

 类似资料: