文本转语音停止问题
我有一个活动,其中屏幕上的显示不断更新,文本到语音也不断更新。这里的问题是,当用户界面更新时,如果我按主页按钮,那么文本到语音也不会停止。它正在连续运行。我尝试在 pause()
和 destroy()
中编写 stop()
和 shutdown()
代码> 但它仍然不起作用。谁能告诉我如何阻止它?
请帮我。
多谢。
I have an activity in which there is a continuous updation of display on the screen and also updation of text to speech. The problem here is while the UI is updating, if I press home button then also the text to speech is not stopped. It is running continuously. I have tried to write the stop()
and also shutdown()
in pause()
and also in destroy()
but still its not working. Can anyone please let me know how to stop that?
Please help me.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果不查看代码,很难判断您做错了什么,但您应该能够调用 TextToSpeech.stop() 或 TextToSpeech.shutdown() 在您的
onPause
并使其工作。由于多种原因,止损可能会失败,如果确实如此,那么你只是运气不好。这对我来说在 6 种不同型号的 Android 设备上始终有效(mTts
是我的TextToSpeech
实例):It is hard to tell without looking at your code what you are doing wrong, but you should be able to call TextToSpeech.stop() or TextToSpeech.shutdown() in your
onPause
and make that work. It is possible the stop fails for any number of reasons, and if it does then you're just out of luck. This works for me consistently on 6 different models of Android device (mTts
is myTextToSpeech
instance):(尝试像这段代码一样,它对我有用)
(try do like this code, it's work with me)
据我所知,TTS SDK 没有任何暂停功能。但您可以使用
synthesizeToFile()
创建包含 TTS 输出的音频文件。然后,您将使用 MediaPlayer 对象来播放、暂停和停止播放文件。根据文本字符串的长度,生成音频可能需要更长的时间,因为synthesizeToFile()
函数必须先完成整个文件才能播放它,但这种延迟应该对于大多数应用来说是可以接受的。The TTS SDK doesn't have any pause functionality that I know of. But you could use
synthesizeToFile()
to create an audio file that contains the TTS output. Then, you would use a MediaPlayer object to play, pause, and stop playing the file. Depending on how long the text string is, it might take a little longer for audio to be produced because thesynthesizeToFile()
function would have to complete the entire file before you could play it, but this delay should be acceptable for most applications.