Android Text to Speech (TTS)

This post describes how to use Android text to speech (TTS) . Do you want to add text to speech in Android? Android text to speech is very interesting because it can add some nice features to an android app. What is text to speech? Text to Speech is a feature of Android platform that can be used to “read” the words and make the app talking, or more in detail to synthesise text.
This post covers how to implement TTS in Android and how to control some interesting properties of speech engine. We want to code an app that has a EditText widget so that we write the words that have to be read and some controls to modify the speech engine.


Android Text to Speech tutorial

The final result of the Android app is shown here.

android text to speech

Android Text to Speech: Text to speech Engine

The first thing we have to do to use the TTS in our app is initializing the engine. The class that controls the engine is called TextToSpeech,

engine = new TextToSpeech(this, this);

where the first parameter is the Context and the other one is the listener. The listener is used to inform our app that the engine is ready to be used. In order to be notified we have to implement TextToSpeech.OnInitListener, so we have:

public class MainActivity extends Activity implements TextToSpeech.OnInitListener {
  public void onInit(int status) {
   Log.d("Speech", "OnInit - Status ["+status+"]");

   if (status == TextToSpeech.SUCCESS) {
     Log.d("Speech", "Success!");

We use the onInit as callback method, and when the engine is ready, we set the default language that the engine used to read our sentence.

You can use Android Voice feature in several scenarios.  Learn how to use Android Voice to control a device

Read the words

Now our engine is ready to be used, we need simply pass the string we want to read. To this purpose, we use an EditText so that the user can edit his string and when he clicks on the microphone the app starts reading. Without detailing too much the code because is trivial we focus our attention when a user clicks on the microphone button:

speechButton.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {


private void speech() {
                TextToSpeech.QUEUE_FLUSH, null, null);

we simply have to call the speak method to make our app reading the text!

Make your Android app talking using this step by step guide. #androiddev Click To Tweet

Control Text to Speech Engine parameters

We can have more control over how the engine read the sentence. We can modify for example the pitch and the speech rate.
In the app, for example, we used two seek bars to control the pitch and rate. If we want to set the voice pitch we can use setPitch passing a float value.
On the other hand, if we want to change the speech rate we can use setSpeechRate.
In our app, we read this value from two seek bars and the speech method become:

 private void speech() {
  engine.setPitch((float) pitch);
  engine.setSpeechRate((float) speed);
  engine.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null, null);


At the end of this article, you learned how to develop an Android app that uses Android Text to Speech.

More posts...

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.