我已经为Android 2.3开发了一个基于TTS的应用程序。
我注意到,例如,在最新版本的Android(4.2.2)中,默认情况下未安装默认的TTS语言,您必须通过以下步骤手动下载它们:
设置->语言和输入->文本到语音输出-> Google文本到语音->安装语音数据
有没有一种自动安装语言的方法?
最佳答案
是的,但这不会自动发生(未经用户同意),如docs所述:
无论如何,您可以使用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 + ")");
}
}