Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends,
i want to customize google text to speech engine to pause and resume where ever i want.
I'm done with playing my text string to speech on button click and now i want to pause and resume the same.
Thanks

What I have tried:

Here i have broken my string into lines baes on dot or full stop
rr = new String[i];
rr = Html.fromHtml((String) mylarge_string_text_here).toString().split("\\.");




on button click i call:

Intent ttsInstallCheck = new Intent();
                     ttsInstallCheck.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(ttsInstallCheck, TTS_REQUEST_CODE);



//then it goes to init block where i have broken string and passed to speaking code
    public void onInit(int i) {
rr = new String[i];
rr = Html.fromHtml((String) mylarge_string_text_here).toString().split("\\.");

  a = rr[counter];
doSpeak(a);
}




private void doSpeak(String text) {
    try {
        HashMap<String, String> params = new HashMap<String, String>();
        // use the actual text as the key to ID the utterance
        params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,text);
        tts.setLanguage(Locale.UK);
        tts.speak(text, TextToSpeech.QUEUE_FLUSH, params);
    } catch (Exception e) {
        e.printStackTrace();
    }
}



      tts.setOnUtteranceCompletedListener(new TextToSpeech.OnUtteranceCompletedListener() {
                    @Override
                    public void onUtteranceCompleted(String utteranceId) {
//called when tts has finished speaking and againg called with new line and updated counter
                     Intent ttsInstallCheck = new Intent();                            ttsInstallCheck.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(ttsInstallCheck, TTS_REQUEST_CODE);
                });
Posted
Updated 6-Nov-17 19:18pm
v2

1 solution

Such a pause method does not exist. Have you considered synthesizing the TTS output to a file, then you would use a MediaPlayer object to play, pause, and stop playing the file?
 
Share this answer
 
Comments
Member 10960567 7-Nov-17 1:14am    
hello sir thanks for the revert,can you help in synthesizing the TTS output to a file,maybe with an example or something.
Thanks
David Crow 7-Nov-17 8:18am    
See here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900