android - 文字转语音停止说话,但循环暂停并没有停止
问题描述
我想在 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();
}
}
我想要播放和暂停功能。
解决方案
推荐阅读
- python - 如何在 Python 中对图例标签进行分组?
- javascript - 在 NodeJs Express 中集成服务器发送的事件
- python - 在 Anaconda 本地运行 github 存储库
- php - 从 PHP 中的多维数组中删除包含键和值的所有单引号时遇到问题
- javascript - 按顺序初始化类
- react-dnd - React-Dnd - 如何控制相对于光标的拖动预览位置并获取相对于放置目标的放置位置
- javascript - 如何使用cordova在后台拨打电话?
- istio - 特使代理使用什么语言?
- django - 我的 linux 服务器中的 Django 和帐户问题
- python - Python:矩形参数无效