为什么会TextToSpeech.getLanguage()* *有时返回NULL? [英] Why would TextToSpeech.getLanguage() *sometimes* return null?
问题描述
在我的应用程序,我称之为<一个href=\"http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#getLanguage%28%29\">TextToSpeech.getLanguage()以及实例化文字转语音(根据LogCat中〜800毫秒),但之后的有时(不总是)返回null,尽管在系统的文字转语音设置正确设置语言:
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)
这只是发生在果冻豆(Android的 4.1.1 )。
它不会在Android 2.2的发生。
This only happens in Jelly Bean (Android 4.1.1). It doesn't happen in Android 2.2.
这是一个已知的Android错误?
还是我做错了什么?
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);
和两个实例,并调用<一个href=\"http://developer.android.com/reference/android/speech/tts/TextToSpeech.html#getLanguage%28%29\">TextToSpeech.getLanguage()在同一个线程(因此呼叫顺序保证的)制成。
And both instantiation and the call to TextToSpeech.getLanguage() are made in the same thread (thus order of calls is guaranteed).
推荐答案
您必须调用使用getLanguage()中的OnInit(),有时需要对OnInit的几秒钟()被调用。
You have to call getLanguage () in onInit (), sometimes it takes a few second for onInit () to be called.
这篇关于为什么会TextToSpeech.getLanguage()* *有时返回NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!