Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause in TTS android

I'm developing an app which would read out the text in the document and I want to add a pause and resume functionality but I can't find any pause() method in TTS. Is there any way that I can pause..?

like image 967
Rookie Avatar asked Jun 17 '12 07:06

Rookie


People also ask

How do you pause TTS?

You can make the TTS pause between sentences, or anywhere you want by adding up to three periods (".") all followed by a single space " ". thanks.

What is Android TTS features?

We've introduced a new feature in version 1.6 of the Android platform: Text-To-Speech (TTS). Also known as "speech synthesis", TTS enables your Android device to "speak" text of different languages.


2 Answers

There is a way to pause. Just call TextToSpeech.playSilence() see the code below from here.

It speaks some actual text along with some silence.

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

}

like image 149
gregm Avatar answered Oct 05 '22 06:10

gregm


the TextToSpeech class has the ability to add a setOnUtteranceCompletedListener (or for api level 15+ setOnUtteranceProgressListener) which will let you attach a listener for when the TTS utterence is completed and then you can start your second utterence, or your pause, or whatever you need..

like image 43
MikeIsrael Avatar answered Oct 05 '22 06:10

MikeIsrael