Reputation: 2832
My requirement: To convert a list of strings into Text to speech.and the start of each string it should play a sound
Problem:Whenever I run this only the last one gets executed and also no music is played inbetween the strings? How should I modify such that the loop will go to next string only when the TexttoSpeech of first string is completed..
for(int m=0;m<c1;m++)
{
mp = MediaPlayer.create(Web4.this, R.raw.music1);
mp.start();
tts.setOnUtteranceCompletedListener(this);
HashMap<String, String> myHashRender = new HashMap();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"end of wakeup message ID");
tts.speak(question1[m],TextToSpeech.QUEUE_FLUSH,myHashRender);
tts.speak("Completed", TextToSpeech.QUEUE_ADD, myHashRender);
mp.stop();
}
Upvotes: 0
Views: 619
Reputation: 52956
Store the index in a field, and only call the next speak() from onUntteranceCompleted() (except the first one of course).
Upvotes: 2