How to use text to speech in android

Reading text out loud using Android TTS should be an easy task. However, it wasn’t really easy for me. I spent the whole evening to get the phone to speak some text in Spanish. So, to save some time for someone who are searching, here is the way.

First, you need to create a class that implements TextToSpeech.OnInitListener. This is the class you will use to speak the text in your activities later. Let’s call it Speaker, we have the Speaker class like this:

pay close attention to this line:

This is where you set the language for the speaker. More details can be found here

Now, in your activity, you can make the phone speak with this:

Make sure you call:

On activity’s onDestroy.