Android Text to speech

Download Text to speech demo sample

Text to speech demo

Android introduced text to speech tools since its begining which we can use to speech the text in different language.

In this example, we are going to discuss below given things:

  1. How to initialize text to speech class
  2. How to change language
  3. How to control pitch rate
  4. How to control voice speed rate

How to initialize TextToSpeech

To intialize implement TextToSpeech.OnInitListener, and override onInit method of TextToSpeech.OnInitListener as follows:

How to call speack method of TextToSpeech?

Call the speak method TextToSpeech object as follows:

How to change language of TextToSpeech?

You can call setLanguage() method of TextToSpeech object to set the language of speak. A lot of languages like Canada, French, Chinese, Germany, Hindi etc. are supported in TextToSpeech.

How to change pitch rate of TextToSpeech?

You can set pitch rate of TextToSpeech by calling setPitch() method of TextToSpeech object. By default, the value is 1.0 which. To decrease pitch rate just lower the values from 1.0 while to increase the pitch rate use greater value of pitch rate than 1.

How to change speech rate of TextToSpeech?

The default value of speech rate is 1.0. To increase speach rate use greater value than 1 and to lower the speech rate decrease the value than 1.0

Android TextToSpeech demo

Step 1: Create a new project in Android Studio and name it Text to speech.

Step 2: Open res -> layout -> activity_main.xml and add following code


Step 3: Open your and replace it source with source of my as follows:

Step 4: Clean and run the project to see the result.

Share & Like

Tutorial topics

About is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.