5

I have developed an app based on TTS for Android 2.3. I am noticing that in recent version of Android (4.2.2) for example, no default TTS language where installed by default, you have to manually download them by going into: Settings --> Language and input --> Text to speech output --> Google Text-To-speech --> Install voice data

Is there a way to install a language automatically?

4

1 回答 1

9

有没有办法自动安装语言?

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

由于用户可能会中断或拒绝数据的安装,因此应用程序不应期望在从该意图返回时成功安装......

无论如何,您可以使用以下方式触发安装

/**
 * 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 + ")");
    }
}
于 2013-05-30T12:43:39.870 回答