In Android TextToSpeech, How come we know either Speech is finished. I want to change icon after speech finished. I declared tts.speak() in Button Onclick Listener. i used thread postdelayed handler to change icon after some time. but the text to read changes different at different times.It didnt worked out. CheckThemestart(),ChangeThemeStop() are functions to change the icon.
i declared the following in OnCreate() :
tts = new TextToSpeech(getContext(), new
TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(Locale.UK);
tts.speak("",TextToSpeech.QUEUE_FLUSH,null);
}
Button-onClickListener :
if (!tts.isSpeaking()) {
CheckThemeStart();
tts.speak(plainText, TextToSpeech.QUEUE_FLUSH, null);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//change icon after spoken
CheckThemeStop();
}
}, 15000);
} else {
CheckThemeStop();
tts.stop();
}