I am new to the android platform. Now I am working on TTS(Text to Speech)
.If I enter the text in a TextArea and I would like it to be converted to speech when i
// variable declaration
TextToSpeech tts;
// TextToSpeech initialization, must go within the onCreate method
tts = new TextToSpeech(getActivity(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Lenguage not supported");
}
} else {
Log.e("TTS", "Initialization failed");
}
}
});
// method call
public void buttonSpeak().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
speak();
}
});
}
private void speak() {
tts.speak("Text to Speech Test", TextToSpeech.QUEUE_ADD, null);
}
@Override
public void onDestroy() {
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
taken from: Text to Speech Youtube Tutorial