Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically download android TTS engine

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?

like image 253
poiuytrez Avatar asked May 30 '13 12:05

poiuytrez


1 Answers

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 + ")");
    }
}
like image 143
ozbek Avatar answered Sep 27 '22 22:09

ozbek