Call {@link TextToSpeech#setOnUtteranceProgressListener} if ICS-MR1 or newer.
On pre ICS-MR1 devices,{@link TextToSpeech#setOnUtteranceCompletedListener} is
used to emulate its behavior - at the end of synthesis we call
{@link UtteranceProgressListenerICSMR1#onStart(String)} and
{@link UtteranceProgressListenerICSMR1#onDone(String)} one after the other.
Errors can't be detected.
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
listener.onStart(utteranceId);
}
@Override
public void onError(String utteranceId) {
listener.onError(utteranceId);
}
@Override
public void onDone(String utteranceId) {
listener.onDone(utteranceId);
}
});
} else {
tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
// Emulate onStart. Clients are expecting it will happen.
listener.onStart(utteranceId);
listener.onDone(utteranceId);
}
});
}