Automatically download android TTS engine

别说谁变了你拦得住时间么 提交于 2019-12-21 02:36:32

问题


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?


回答1:


Is there a way to install a language automatically?

Yes, but that will not happen automatically (without user consent) as mentioned in the 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...

Anyhow, you can trigger the installation with something like 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 + ")");
    }
}


来源:https://stackoverflow.com/questions/16835847/automatically-download-android-tts-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!