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>();
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) {
Intent ttsInstallCheck = new Intent(); ttsInstallCheck.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(ttsInstallCheck, TTS_REQUEST_CODE);
});