如何知道 TTS 何时完成?
我正在 Android 上实现交互式语音响应应用程序。我想知道如何确定 tts.speak() 函数何时完成通话,以便我可以调用我的语音识别器函数。
I'm implementing an Interactive Voice Response application on Android. I would like to know how to determine when the tts.speak()
function has done talking so I can call my speech recognizer function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
阅读 A很好的教程
Read A good tutorial
自 API 级别 15 起,setOnUtteranceCompletedListener 已被弃用。相反,请使用 setOnUtteranceProgressListener。
我找到了一个代码片段(此处),它确实实现了我很容易知道文本到语音何时完成:
http:// www.codota.com/android/scenarios/52fcbd34da0ae25e0f855408/android.speech.tts.TextToSpeech?tag=dragonfly
The setOnUtteranceCompletedListener is deprecated since API level 15. Instead, use setOnUtteranceProgressListener.
I found a code snippet (here) that made it really easy for me to know when text to speech is finished:
http://www.codota.com/android/scenarios/52fcbd34da0ae25e0f855408/android.speech.tts.TextToSpeech?tag=dragonfly
要知道 TTS 何时完成,您必须调用
setOnUtteranceProgressListener
,它有 3 个回调方法onStart
、onDone
和onError
>然后将话语 ID 添加到 talk 方法
代码片段中
To know when TTS is finished you have to call the
setOnUtteranceProgressListener
which has 3 call back methodsonStart
,onDone
andonError
then include a Utterance Id to the speak method
Code Snippet
我注意到有人在使用TextToSpeech时遇到问题来询问您的解决方案
如何知道TTS何时完成?
不使用 setOnUtteranceCompletedListener
I noticed that there are people having problems in the use of TextToSpeech to ask that the solution to you
How to know when TTS is finished?
without use setOnUtteranceCompletedListener
尝试下面的代码,它会在 TTS 完成后显示一个祝酒词。用自己的行动代替吐司。
Try this following code which shows a toast after TTS completed. Replace toast with your own action.
通过这段代码我解决了这个问题。我希望只要有人说话,开始按钮就一直亮着。也许这会对某人有所帮助。
With this code I solved the problem. I wanted the start button to stay lit as long as someone was speaking. Maybe this will help someone.
使用这个监听器:
use this listener :
当文本说话时使用 SpeakableListener。
use a SpeakableListener when do text to speak.