I am implementing TTS (Text to Speech) support in my Android app. I am showing my code :
TextSpeech textSpeech = new TextSpeech();
textToSpeech = new TextToSpeech(this, textSpeech);
private class TextSpeech implements TextToSpeech.OnInitListener {
@Override
public void onInit(final int status) {
if (status != TextToSpeech.ERROR) {
if (TextToSpeech.LANG_AVAILABLE == textToSpeech.isLanguageAvailable(Locale.ENGLISH)) {
Thread thread = new Thread() {
@Override
public void run() {
super.run();
textToSpeech.setLanguage(Locale.ENGLISH);
try {
for (int i = 0; i < 10; i++) {
if (Util.isGreaterThanApi21()) {
textToSpeech.speak("" + i, TextToSpeech.QUEUE_FLUSH, null, null);
} else {
textToSpeech.speak("" + i, TextToSpeech.QUEUE_FLUSH, null);
}
Thread.sleep(1000);
}
} catch (Exception exception) {
}
}
};
thread.start();
} else {
Toast.makeText(ViewWorkplanActivity.this, "Language Not Supported", Toast.LENGTH_SHORT).show();
}
}
}
}
When I run this code, some devices missing 3-4 number or taking 3-4 seconds for initialization. Can any body tell me how can I remove this error?