文本转语音停止问题

发布于 2024-12-01 10:47:19 字数 236 浏览 1 评论 0原文

我有一个活动,其中屏幕上的显示不断更新,文本到语音也不断更新。这里的问题是,当用户界面更新时,如果我按主页按钮,那么文本到语音也不会停止。它正在连续运行。我尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紫瑟鸿黎 2024-12-08 10:47:19

如果不查看代码,很难判断您做错了什么,但您应该能够调用 TextToSpeech.stop()TextToSpeech.shutdown() 在您的 onPause 并使其工作。由于多种原因,止损可能会失败,如果确实如此,那么你只是运气不好。这对我来说在 6 种不同型号的 Android 设备上始终有效(mTts 是我的 TextToSpeech 实例):

@Override
    protected void onStop()
    {
        super.onStop();

        if(mTts != null){
            mTts.shutdown();
        }       
    }

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 my TextToSpeech instance):

@Override
    protected void onStop()
    {
        super.onStop();

        if(mTts != null){
            mTts.shutdown();
        }       
    }
画离情绘悲伤 2024-12-08 10:47:19
@Override
public void onDestroy() {
    if (tts != null) {
        tts.stop();
        tts.shutdown();

    }
    super.onDestroy();
}

(尝试像这段代码一样,它对我有用)

@Override
public void onDestroy() {
    if (tts != null) {
        tts.stop();
        tts.shutdown();

    }
    super.onDestroy();
}

(try do like this code, it's work with me)

懒的傷心 2024-12-08 10:47:19

据我所知,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 the synthesizeToFile() function would have to complete the entire file before you could play it, but this delay should be acceptable for most applications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文