onUtteranceCompleted 在模拟器上触发,但在硬件上不触发

发布于 2025-01-06 03:29:55 字数 1277 浏览 0 评论 0原文

我无法在 Galaxy Nexus 4.0.2 上触发 onUtteranceCompleted()。 我的 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"); 
}
(...)

I can't get my onUtteranceCompleted() get fired on my Galaxy Nexus 4.0.2.
My emulators with api 8, 10 and 15 do fire onUtteranceCompleted().

edit: well.. the statement above is true for most cases, I just got it to work on my Hardware 4.0.2. Then I closed it and started it again, and onUtteranceCompleted() did not get fired again. Had the same thing yesterday (before some code changes), so it's not working 90% of the time. Can't figure it out ;(

edit2:FYI: the mTts.setOnUtteranceCompletedListener(this); returns TextToSpeech.SUCCESS

Here is my code:

(...)
    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"); 
}
(...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琴流音 2025-01-13 03:29:55

由于您遇到的问题仅有时发生,因此该问题必定是由于 TextToSpeech 初始化的异步性质造成的。当我的代码在调用 onInit() 之前设置 TextToSpeech 的属性时,我有时会看到 TextToSpeech 失败。

我怀疑您在 TextToSpeech 调用 onInit() 之前激活了 SayText()。这种情况只会发生几次。

看起来您拥有在 onInit() 期间设置 onUtteranceCompletedListener 的正确代码,但也许也存在计时问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文