Android Text to Speech Example

In this tutorial you will learn about android text to speech example.

Android provides a class TextToSpeech that helps in converting any text into speech or voice. What I am doing in this example is, I am writing any text in textbox and on button click I am taking the text from textbox and converting it into speech using TextToSpeech class.

Android Text to Speech Example

First we need to create the object of TextToSpeech class. Its constructor takes two arguments, first argument is the reference of current activity and in the second argument we have to specify the listener. The setLanguage() method is used to specify the language, it takes Locale object as argument. The Locale object can be US, UK, CHINA, etc. Finally the speech() method is used to convert the text to speech, it takes three parameters or arguments. The first argument is the text that we want to convert, second argument takes constant QUEUE_FLUSH and third argument takes null.

Below I have given the whole code for doing this. The package name is com.texttospeech.

activity_main.xml

 

MainActivity.java

 

AndroidManifest.xml

 

Android Text to Speech Example

 

So this was the simple tutorial for android text to speech example. You can comment below if you have any doubts regarding above tutorial.

2 thoughts on “Android Text to Speech Example”

Leave a Comment

Your email address will not be published. Required fields are marked *