1

I'm a newbie in android dev and this is my first time in stackoverflow.
Im currently developing a simple workout app for my Software Engineering subject and I implemented Text-to-Speech to read out the workout steps. I have a button named "Play/Pause Audio"
This is my onclick listener:

  speak.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!tts.isSpeaking()) {
                HashMap<String, String> params = new HashMap<String, String>();
                params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "sampletext");
                tts.speak(tv.getText().toString(), TextToSpeech.QUEUE_ADD, params);
            } else {
                tts.stop();
            }
        }
    });

But when i try to pause it, it stops and restarts the process. Is there a way to pause TTS?
Thank you so much!!

  • You can use [TextToSpeech.playSilence()](https://github.com/gast-lib/gast-lib/blob/master/app/src/root/gast/playground/speech/tts/TextToSpeechDemo.java) also you can take a look on [this](http://wptrafficanalyzer.in/blog/android-text-to-speech-implementing-pause-and-resume-in-tts-using-mediaplayer/) – Skizo-ozᴉʞS ツ Feb 23 '15 at 09:44
  • Please look here: http://stackoverflow.com/questions/4970204/how-to-pause-android-speech-tts-texttospeech – Thomas Vos Feb 23 '15 at 11:30

2 Answers2

0

Use can use the playSilence() method to pause:

public void pause(long duration){
        tts.playSilence(duration, TextToSpeech.QUEUE_FLUSH, null);
    }

Where duration is in milliseconds.

So calling for example, pause(5000) will pause for 5 seconds

Nana Ghartey
  • 7,901
  • 1
  • 24
  • 26
0

You can't!

After the call of speak, the TextToSpeech will play for you the generated audio.

But, you can generate the audio in a File using synthesizeToFile and play it.

Victor
  • 8,309
  • 14
  • 80
  • 129