I’ve been working on an Android app lately that uses the Text to Speech functionality and I wanted to have a spinner that can display all available languages on an Android device. Now I’m going to show you how to get a list of supported languages in this short Android tutorial.

Option #1: RecognizerIntent

One way to do it is via broadcasting a RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS intent. See example here. Unfortunately, this didn’t work for me as the result Intent didn’t contain value for the RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES key.

Option #2: isLanguageAvailable() method

This is the option that did the trick for me. Nothing fancy, I used the isLanguageAvailable() method of the TextToSpeech class:

TextToSpeech tts = ...
// let's assume tts is already inited at this point:
Locale[] locales = Locale.getAvailableLocales();
List<Locale> localeList = new ArrayList<Locale>();
for (Locale locale : locales) {
    int res = tts.isLanguageAvailable(locale);
    if (res == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
        localeList.add(locale);
    }
}
// at this point the localeList object will contain
// all available languages for Text to Speech

For more details on how to initialize the Android TTS engine, you’ll find a tutorial here.