Using Google text-to-speech synthesis
TTS has been available on Android devices since Android 1.6 (API Level 4).The components of the Google TTS API (package android.speech.tts
) are documented at http://developer.android.com/reference/android/speech/tts/package-summary.html. Interfaces and classes are listed and further details can be obtained by clicking on these.
Starting the TTS engine
Starting the TTS engine involves creating an instance of the TextToSpeech
class along with the method that will be executed when the TTS engine is initialized. Checking that TTS has been initialized is done through an interface called OnInitListener
. If TTS initialization is complete, the method onInit
is invoked.
The following lines of code create a TextToSpeech
object that implements the onInit
method of the onInitListener
interface.
TextToSpeech tts = new TextToSpeech(this, new OnInitListener(){ public void onInit(int status){ if (status == TextToSpeech.SUCCESS) speak("Hello...