I am using the source code of a Text-To-Speech app. I would like the content of a TextView to be read aloud automatically (i.e. without the use of setOnClickListener). Does anyone know how to approach this? Thanks in advance!
EDIT: This is the final result, and it works:
mVoiceOutputTv.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String text = charSequence.toString();
if (text.contains(text)) {
if (timer != null) {
timer.cancel();
}
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
toSpeak = mVoiceOutputTv.getText().toString();
textToSpeech.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
}
}, 1000);
}
}
@Override
public void afterTextChanged (Editable editable) {
}
});
I have not tested this code.Let me know if it doesn't work: