Skip to content Skip to sidebar Skip to footer

How To Check If A Specific Language Data For Text To Speech(TTS) Is Installed On A Device?

I am creating an app which uses Text to Speech and I want the user to have the ability to use it offline so I make a check to see if the TTS data is installed on the device, here i

Solution 1:

Use EXTRA_CHECK_VOICE_DATA_FOR

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
    if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
        tts = new TextToSpeech(this, this);
    }
    else {
        Intent installTTSIntent = new Intent();
        installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        ArrayList<String> languages = new ArrayList<String>();
        languages.add("it-IT"); // non sure if "it" is the right abbr for italian
        installTTSIntent.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR, 
                                                    languages);
        startActivity(installTTSIntent);
    }
    }
}

Document link http://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine.html#EXTRA_CHECK_VOICE_DATA_FOR


Post a Comment for "How To Check If A Specific Language Data For Text To Speech(TTS) Is Installed On A Device?"