This sample uses Android's text to speech capabilities to speak the phrase Hello.
Inside any Activity
private TextToSpeech textToSpeech;
public void saySomething() {
textToSpeech = new TextToSpeech(this, new OnInitListener() {
@Override
public void onInit(int status) {
// Note: If the code calls speak() before initialization has finished, nothing will happen
textToSpeech.speak("Hello", TextToSpeech.QUEUE_FLUSH, null, null);
}
});
}
Important imports
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
Other notes
textToSpeech.shutdown()
should be called inside the Activity's onDestroy.