Jenix
Jenix

Reputation: 3076

Available languages for TTS on Android

I'm trying to check if a certain language is available for TTS using isLanguageAvailable(). The possible return values of the method are below.

LANG_AVAILABLE

LANG_COUNTRY_AVAILABLE

LANG_COUNTRY_VAR_AVAILABLE

LANG_MISSING_DATA

LANG_NOT_SUPPORTED

It's easy to understand that I don't have to care about the last two ones by their name. But I'm really confused what the rest of them mean even after reading the explanations here.

public static final int LANG_AVAILABLE

Denotes the language is available for the language by the locale, but not the country and variant.

public static final int LANG_COUNTRY_AVAILABLE

Denotes the language is available for the language and country specified by the locale, but not the variant.

public static final int LANG_COUNTRY_VAR_AVAILABLE

Denotes the language is available exactly as specified by the locale.

What does this mean? All threes are available for TTS?

I don't understand the sentence "by the locale, but not the country and variant".

I'm testing TTS with some code like this.

for( Locale each : Locale.getAvailableLocales() )
    if( TextToSpeech.LANG_AVAILABLE == myTTS.isLanguageAvailable(each)
    && SOME_OTHER_ADDITIONAL_CONDITIONS ) {    
        myTTS.setLanguage(each);
        break;
    }

As you can see, I just put one constant LANG_AVAILABLE.

Do I need the other two constants too, just in case?

Upvotes: 1

Views: 1427

Answers (1)

geokavel
geokavel

Reputation: 619

Well, as you can see here (http://developer.android.com/reference/java/util/Locale.html) there is a locale called en (English) and there is also en_GB and en_US, so English is the base locale and GB and US specify the country for the locale. If you look at the three-pararmeter constructor for locale there is also a parameter called variant. I'm guessing that is possible to have something like en_US_southern, and southern would be a variant of American English.

To answer your question, if all you want is to see if the TTS speaks a certain language regardless of country or dialect, you could just check myTTS.isLanguageAvailable(each) >= 0 because that will check for all three possible "success" results.

Upvotes: 2

Related Questions