0

我无法onUtteranceCompleted()在我的 Galaxy Nexus 4.0.2 上被解雇。我的带有 api 8、10 和 15 的模拟器会开火onUtteranceCompleted()

编辑:嗯..上面的陈述在大多数情况下都是正确的,我只是让它在我的硬件 4.0.2 上工作。然后我关闭它并再次启动它,并且 onUtteranceCompleted() 没有再次被解雇。昨天有同样的事情(在一些代码更改之前),所以它在 90% 的时间里都没有工作。想不通;(

编辑2:仅供参考:mTts.setOnUtteranceCompletedListener(this); 返回 TextToSpeech.SUCCESS

这是我的代码:

(...)
    public void onInit(int status) {            
mTts.setOnUtteranceCompletedListener(this);

if (status == TextToSpeech.SUCCESS) {    
    int result = mTts.setLanguage(Locale.US);
    if (result == TextToSpeech.LANG_MISSING_DATA ||
        result == TextToSpeech.LANG_NOT_SUPPORTED) {
        Log.e(TAG, "Language is not available.");
    } else {
        TTSAusgabe.setEnabled(true);
    }
} else {
    Log.e(TAG, "TTS failed");
}    
}


SayText() {  (....)
MundAnimation.start();
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "utterance");
mTts.speak("Ma Text", TextToSpeech.QUEUE_FLUSH, params);
  } 
}


// That's the bad boy!
public void onUtteranceCompleted(String utterance) 
{
MundAnimation.stop();
    //startVoiceRecognitionActivity();
System.out.println("drin"); 
}
(...)
4

1 回答 1

0

Since you have a problem that only occurs sometimes the problem must be due to the asynchronous nature of the TextToSpeech initialization. I have seen TextToSpeech fail sometimes when my code sets a property of TextToSpeech before onInit() is called.

I suspect that you activated SayText() before TextToSpeech called onInit(). This will happen only some times.

It looks like you have the right code that sets the onUtteranceCompletedListener during onInit() though, but perhaps that has a timing problem as well.

于 2012-03-01T13:36:40.433 回答