I have an ArrayList of an Object "Words" that has two Strings attributes, which are a word in one language and its translation in another language. The words are taken from txt files that have them separated by the symbol "=" and so there is a word and its translation in each line. Like this:
word1Language1=word1language2
word2Language1=word2Language2
word3Language1=word3Language2
So, I read those words with a method that successfully puts them in the previously mentioned ArrayList. But now I want a bot to pronounce those words when I press a button (and I'd like it to stop too when I press the button again). This is my code currently, "wordsList" is the name of the ArrayList. I don't know how to tell the bot to wait between words (so it pronounces them properly):
mTTS = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR){
mTTS.setLanguage(Locale.US);
}
}
});
imageButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
for(int i=0; i <= wordsList.size(); i++){
mTTS.setLanguage(Locale.US);
String toSpeak1 = wordsList.get(i).getLanguage1();
mTTS.speak(toSpeak1, TextToSpeech.QUEUE_FLUSH, null);
mTTS.setLanguage(Locale.ITALIAN);
String toSpeak2 = wordsList.get(i).getLanguage2();
mTTS.speak(toSpeak2, TextToSpeech.QUEUE_FLUSH, null);
}
mTTS.shutdown();
}
});
Thanks!