如何暂停android.speech.tts.TextToSpeech?speech、android、TextToSpeech、tts

2023-09-12 09:24:18 作者:浮夸爷们

我在玩文字与Android TTS - android.speech.tts.TextToSpeech

I'm playing text with android TTS - android.speech.tts.TextToSpeech

我用: TextToSpeech.speak 来说话, .stop 停止。有没有一种方法也暂停文字?

I use: TextToSpeech.speak to speak and .stop to stop. Is there a way to pause the text also?

推荐答案

该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.