暂停在TTS android中

时间:2012-06-17 07:43:53

标签: android text-to-speech

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

2 个答案:

答案 0 :(得分:5)

有一种方法可以暂停。只需致电TextToSpeech.playSilence(),请参阅here中的以下代码。

它会说一些实际的文字以及一些沉默。

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);

}

答案 1 :(得分:3)

TextToSpeech类可以添加setOnUtteranceCompletedListener(或api级别15+ setOnUtteranceProgressListener),可以让你在TTS语言完成时附加一个监听器然后你可以启动你的第二个话题,或你的停顿,或任何你需要的......