TTS 未正确循环
我的要求:将字符串列表转换为文本到语音。并且每个字符串的开头应该播放声音
问题:每当我运行此命令时,仅执行最后一个字符串,并且字符串之间也不会播放音乐?我应该如何修改,以便仅当第一个字符串的 TexttoSpeech 完成时循环才会转到下一个字符串。
for(int m=0;m<c1;m++)
{
mp = MediaPlayer.create(Web4.this, R.raw.music1);
mp.start();
tts.setOnUtteranceCompletedListener(this);
HashMap<String, String> myHashRender = new HashMap();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"end of wakeup message ID");
tts.speak(question1[m],TextToSpeech.QUEUE_FLUSH,myHashRender);
tts.speak("Completed", TextToSpeech.QUEUE_ADD, myHashRender);
mp.stop();
}
My requirement: To convert a list of strings into Text to speech.and the start of each string it should play a sound
Problem:Whenever I run this only the last one gets executed and also no music is played inbetween the strings? How should I modify such that the loop will go to next string only when the TexttoSpeech of first string is completed..
for(int m=0;m<c1;m++)
{
mp = MediaPlayer.create(Web4.this, R.raw.music1);
mp.start();
tts.setOnUtteranceCompletedListener(this);
HashMap<String, String> myHashRender = new HashMap();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"end of wakeup message ID");
tts.speak(question1[m],TextToSpeech.QUEUE_FLUSH,myHashRender);
tts.speak("Completed", TextToSpeech.QUEUE_ADD, myHashRender);
mp.stop();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将索引存储在一个字段中,并且仅从 onUntteranceCompleted() 调用下一个spoke()(当然第一个除外)。
Store the index in a field, and only call the next speak() from onUntteranceCompleted() (except the first one of course).
尝试在每次通话之间添加延迟,这可能会有所帮助。
Try adding delay between each call, it might help.