6

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

4

2 回答 2

5

有一种方法可以暂停。只需从这里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);

}

于 2012-06-18T08:33:21.710 回答
3

TextToSpeech 类能够添加一个setOnUtteranceCompletedListener(或对于 api 级别 15+ setOnUtteranceProgressListener),它可以让你在 TTS 话语完成时附加一个监听器,然后你可以开始你的第二个话语,或者你的暂停,或者你需要的任何东西..

于 2012-06-17T07:56:51.937 回答