6

I have an activity in which there is a continuous updation of display on the screen and also updation of text to speech. The problem here is while the UI is updating, if I press home button then also the text to speech is not stopped. It is running continuously. I have tried to write the stop() and also shutdown() in pause() and also in destroy() but still its not working. Can anyone please let me know how to stop that?

Please help me.

Thanks a lot.

Lavanya
  • 3,903
  • 6
  • 31
  • 57

3 Answers3

15

It is hard to tell without looking at your code what you are doing wrong, but you should be able to call TextToSpeech.stop() or TextToSpeech.shutdown() in your onPause and make that work. It is possible the stop fails for any number of reasons, and if it does then you're just out of luck. This works for me consistently on 6 different models of Android device (mTts is my TextToSpeech instance):

@Override
    protected void onStop()
    {
        super.onStop();

        if(mTts != null){
            mTts.shutdown();
        }       
    }
Femi
  • 64,273
  • 8
  • 118
  • 148
  • I tried this too but it didnt work. I have made mTts shutdown in onStop() and tried, onPause() and tried and also in onDestroy() tried – Lavanya Aug 25 '11 at 08:15
  • thanks a lot... This worked for me now... Before I have tried with many tts objects thats why it didnt work. If i am working on a single tts object then its working absolutely fine – Lavanya Aug 28 '11 at 07:36
2
@Override
public void onDestroy() {
    if (tts != null) {
        tts.stop();
        tts.shutdown();

    }
    super.onDestroy();
}

(try do like this code, it's work with me)

1

The TTS SDK doesn't have any pause functionality that I know of. But you could use synthesizeToFile() to create an audio file that contains the TTS output. Then, you would use a MediaPlayer object to play, pause, and stop playing the file. Depending on how long the text string is, it might take a little longer for audio to be produced because the synthesizeToFile() function would have to complete the entire file before you could play it, but this delay should be acceptable for most applications.

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
  • its different its a wastage to again store it and again retrieveing.... I dont want like this – Lavanya Aug 25 '11 at 07:47
  • Are you sure about it because many tts applications are there and i dont understand why is the stop() or shutdown() not working as how it should – Lavanya Aug 25 '11 at 08:18
  • http://stackoverflow.com/questions/4970204/how-to-pause-android-speech-tts-texttospeech – Niranj Patel Aug 25 '11 at 09:04