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.