onUtteranceCompleted不会被调用? [英] onUtteranceCompleted does not get called?
问题描述
即使我正确设置它:
HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "utid");
mTts.speak("Speak something", TextToSpeech.QUEUE_ADD, myHashRender);
也
mTts.setOnUtteranceCompletedListener(this);
在OnInit函数返回成功。 仍然是onUtteranceCompleted不会被调用。虽然有重复的问题,但没有在那里我能找到答案。
in the onInit function return success. Still the onUtteranceCompleted does not get called. Though there are duplicate questions, but no where I could find the answer.
我的动态也实现OnUtteranceCompletedListener。
My Activity also implements OnUtteranceCompletedListener.
请帮忙。
推荐答案
调用setOnUtteranceCompletedListener的TTS对象的OnInit函数中。
Call the setOnUtteranceCompletedListener inside the onInit function of the tts object.
如果您想进行任何更改的onUtteranceCompleted函数的调用用户界面,添加code进行runOnUIThread方法中。
If you want to make any changes to the UI on the call of the onUtteranceCompleted function, add the code inside a runOnUIThread method.
和千万要记得添加HashMap的参数值,同时调用说话()函数
And do remember to add the Hashmap param value while calling the speak() function
例如:
TextToSpeech tts= new TextToSpeech(context, new OnInitListener() {
@Override
public void onInit(int status) {
mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//UI changes
}
});
}
});
}
});
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");
tts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH, params);
这篇关于onUtteranceCompleted不会被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!