In my app, I call TextToSpeech.getLanguage() well after instantiating TextToSpeech (~800ms according to LogCat), yet it sometimes (not always) return null, despite the language set properly in the system's TextToSpeech settings:
System Settings > Language & input >
Text-to-speech output > Google Text-to-speech > English (United Kingdom)
This only happens in Jelly Bean (Android 4.1.1). It doesn't happen in Android 2.2.
Is this a known Android bug? Or am I doing something wrong?
I instantiate, BTW, TextToSpeech in my app's main activity with:
new TextToSpeech(this, this);
And both instantiation and the call to TextToSpeech.getLanguage() are made in the same thread (thus order of calls is guaranteed).
You have to call getLanguage () in onInit (), sometimes it takes a few second for onInit () to be called.
I also discovered this bug today on an Asus TF700T running Android 4.1.1. I tried to resolve the issue by calling getLanguage()
again as Eternal Learner suggested in a comment, but it still returns null no matter how many times I call it.
The easiest workaround for me was to abandon the current broken instance of TextToSpeech and create a new instance. The second instance seems to work reliably.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With