我想在tts中添加暂停和播放功能。到目前为止所做的是,当我停止tts说话并想获取最后一个说话的单词时,正在运行的循环没有停止。请解决我的问题。
public void toggleAudioMode() {
isPlayerVisible = !isPlayerVisible;
ivToggleAudioModeAnswer.setImageResource(isPlayerVisible ? R.drawable.ic_audio_off : R.drawable.ic_audio_on);
if (isPlayerVisible) {
splitspeech = result.split(" ");
if (j > 0) {
speakSpeech(j, "run");
} else {
speakSpeech(0, "run");
}
} else {
keepGoing = false;
speakSpeech(0, "stop");
}
}
public void speakSpeech(int m, String type) {
myHash.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "done");
while (i < splitspeech.length) {
if (type.equals("run")) {
if (i == 0) { // Use for the first splited text to flush on audio stream
textToSpeech.speak(splitspeech[i].trim(), QUEUE_FLUSH, myHash);
} else { // add the new text on previous then play the TTS
textToSpeech.speak(splitspeech[i].trim(), QUEUE_ADD, myHash);
j = i;
}
}
i++;
}
if (type.equals("stop")) {
textToSpeech.stop();
}
}
我想要播放和暂停功能。