Skip to content Skip to sidebar Skip to footer

Android Tts Checking For Supported Locale With Missing/not Downloaded Voice Data

I'm using Android's TextToSpeech class. Everything is working normally. However, there are languages/locales that aren't installed by default but supported by the TTS engine and I

Solution 1:

You can find all available Locale of the device using following function. hope this code will help you.

 Locale loc = new Locale("en");
 Locale[] availableLocales= loc.getAvailableLocales();
 Boolean available=Boolean.FALSE;
 for (int i=0;i<availableLocales.length;i++)
 {
  if(availableLocales[i].getDisplayLanguage().equals("your_locale_language"))
   {
        available=Boolean.TRUE;
        // TODO:
   }
 }

Solution 2:

I have this implementation as part of a wrapper class to work with TextToSpeech, I hope it helps:

publicbooleanisLanguageAvailable(Locale language)
{
    if(language == null) returnfalse;
    boolean available = false;
    switch (tts.isLanguageAvailable(language))
    {
        caseTextToSpeech.LANG_AVAILABLE:
        caseTextToSpeech.LANG_COUNTRY_AVAILABLE:
        caseTextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
            if(Build.VERSION.SDK_INT >= 21){
                tts.setLanguage(language);
                Voice voice = tts.getVoice();
                if(voice != null){
                    Set<String> features = voice.getFeatures();
                    if (features != null && !features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED))
                        available = true;
                } else available = false;
                tts.setLanguage(this.language);
            }
            break;

        caseTextToSpeech.LANG_MISSING_DATA:
        caseTextToSpeech.LANG_NOT_SUPPORTED:
        default:
            break;
    }
    return available;
}

Solution 3:

It looks like a long waiting question but anyway. It seems that you have to check voice features to find it out:

Set<String> features = voice.getFeatures();
if (features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED)) {
//Voice data needs to be downloaded
...
}

Post a Comment for "Android Tts Checking For Supported Locale With Missing/not Downloaded Voice Data"