2

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.

Fluppe
  • 479
  • 7
  • 22
  • So if you turn internet off, it won't speak anymore?? Is this an emulator or a real device? I think that's a terrible idea to require an internet connection. – Nerdy Bunz Jun 11 '18 at 11:41
  • It would still speak without internet connection, but you can only use the languages that are installed (and that can be used while offline) on the device. – Fluppe Jun 11 '18 at 13:29

2 Answers2

1

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.

Community
  • 1
  • 1
Fluppe
  • 479
  • 7
  • 22
0

Try

tts.setLanguage(new Locale("nl", "NL"));
A Honey Bustard
  • 3,433
  • 2
  • 22
  • 38
  • Won't work unless Dutch speech synthesis is installed and supported. You can check this by going to the Language and Input settings of your Android device, and then by checking the supported languages of the Text-To-Speech/Speech Synthesis. It was not supported on my device (and probably on a lot of other devices as well), but you can install it by updating your Google TTS from the Play Store – Fluppe Apr 22 '15 at 09:57