我想让它在一个服务中工作。所以现在它运行得很好。但它有一个问题。在工作之后,tts突然开始了。我不确定我认为tts没有很好地完成。但我不知道源代码中的错误在哪里。请告诉我
hear是代码。
public class servishuo1 extends Service implements TextToSpeech.OnInitListener {
private TextToSpeech mTts;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
if (mTts != null) {
mTts.stop();
mTts.shutdown();
}
super.onDestroy();
}
@Override
public void onStart(Intent intent, int startId) {
mTts = new TextToSpeech(this, this);
speakOut();
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS)
{
int result = mTts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
{
Log.e("TTS", "This Language is not supported");
}
speakOut();
}
else
{
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
mTts.speak("hello", TextToSpeech.QUEUE_FLUSH, null);
}
}发布于 2014-05-03 23:04:40
代码中的一个错误如下:
mTts = new TextToSpeech(this, this);
speakOut();
^^^^^^^^^^^ <--- !!!在调用带有TextToSpeech.SUCCESS的onInit回调之前,不应该调用mTts.speak。
https://stackoverflow.com/questions/23445963
复制相似问题