暂停在TTS的android(Pause in TTS android)

2019-06-25 13:06发布

我开发一个应用程序,它会读出文档中的文本,我想添加一个暂停和恢复功能,但我无法找到任何TTS pause()方法。 有没有办法,我可以暂停任何方式..?

Answer 1:

有一个办法暂停。 只需拨打TextToSpeech.playSilence()请参见下面的代码在这里 。

它讲一些实际的文字有些沉默一起。

private void playScript()
{
    Log.d(TAG, "started script");
// setup

// id to send back when saying the last phrase
// so the app can re-enable the "speak" button
HashMap<String, String> lastSpokenWord = new HashMap<String, String>();
lastSpokenWord.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
        LAST_SPOKEN);

// add earcon
final String EARCON_NAME = "[tone]";
tts.addEarcon(EARCON_NAME, "root.gast.playground", R.raw.tone);

// add prerecorded speech
final String CLOSING = "[Thank you]";
tts.addSpeech(CLOSING, "root.gast.playground",
        R.raw.enjoytestapplication);

// pass in null to most of these because we do not want a callback to
// onDone
tts.playEarcon(EARCON_NAME, TextToSpeech.QUEUE_ADD, null);
tts.playSilence(1000, TextToSpeech.QUEUE_ADD, null);
tts.speak("Attention readers: Use the try button to experiment with"
        + " Text to Speech. Use the diagnostics button to see "
        + "detailed Text to Speech engine information.",
        TextToSpeech.QUEUE_ADD, null);
tts.playSilence(500, TextToSpeech.QUEUE_ADD, null);
tts.speak(CLOSING, TextToSpeech.QUEUE_ADD, lastSpokenWord);

}



Answer 2:

将文字转语音类有添加的能力setOnUtteranceCompletedListener (或API级别15+ setOnUtteranceProgressListener ),这将让你连接时,TTS utterence完成了监听器,然后你就可以开始你的第二个utterence,或者你暂停,或任何你需要..



文章来源: Pause in TTS android