Search code examples
javaandroidlocaletext-to-speech

Android - TTS set language to Locale.getDefault not possible without internet?


I'm trying to set the language of my TextToSpeech-object to Dutch. This is the default language of my Android tablet on which the app will run, and when I log Locale.getDefault() I get "nl_NL"so this is correct.

I've read that for TTS you need to supply the ISO Language Code and ISO Country Code when setting the language with Locale. But here is the problem: when the tablet does not have an Internet connection, the TTS doesn't seem to be able to set the language to Dutch. Here is my code for setting the language:

int result = tts.setLanguage(new Locale(Locale.getDefault().getISO3Language(),
 Locale.getDefault().getISO3Country()));
// this equals to "nld","NLD"
        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED)
        {
            tts.setLanguage(Locale.UK);
        }else{
            dutch = true;
        }

Without Internet connection, the language is always set to Locale.UK. With Internet connection, it works as intended and the language is set to Dutch (I don't even have to provide the ISO-notation, just new Locale("nl_BE") or "nl_NL" will do).

Further in my code when the TTS.speak is called I always check if Dutch is true, and then a Dutch string is providedfor the speak method, otherwise an English string is provided.

How can I fix this that I can set the TextToSpeech language to Dutch without Internet connection?

EDIT: for other people experiencing my issue, check out the edited part of my answer below.


Solution

  • After a lot of research it seems that the standard languages that are installed with TTS do not contain the Dutch language. I ran some test using the method isLanguageAvailable(Locale loc) and thereby checking for Dutch language etc., and it seems that the Dutch language is not supported (the returned value is LANG_NOT_SUPPORTED ).

    I'll have to find another TTS-client to meet my needs or to play .mp3-files with the correct message (this could work because the values that the TTS had to pronounce were predefined).

    Some links that helped me:
    http://igordcard.blogspot.be/2014/02/changing-android-text-to-speech-tts.html
    Missing languages in TTS android
    How to check if a specific language data for Text to Speech(TTS) is installed on a device?
    http://code.tutsplus.com/tutorials/android-sdk-using-the-text-to-speech-engine--mobile-8540

    And an image showing which languages were installed:
    TextToSpeech standard installed languages

    EDIT: after updating the "Google TTS"-app from Google Play Store, Dutch BECAME available. If you're looking for Dutch offline TTS and you're using the Google TTS for it, just update it to the latest version.