即使我正确设置它:
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);
我的活动还实现了OnUtteranceCompletedListener。
请帮忙。
答案 0 :(得分:18)
在tts对象的onInit函数内调用setOnUtteranceCompletedListener。
如果要在调用onUtteranceCompleted函数时对UI进行任何更改,请在runOnUIThread方法中添加代码。
并且记得在调用speak()函数时添加Hashmap参数值
示例:
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);