How to Convert Text to Speech in Android Studio — Text to Speech Converter using Android

Hi Guys, welcome to GBAndroidBlogs we have created a Text to Speech converter app. In this app, we convert the text into speech. Here we convert the text into the English language.

Android allows us to convert the text into a voice or speech. Also, we can convert the text into different languages like the US, JAPAN, GERMANY, ITALY, etc.

For this purpose, Android provides us a class TextToSpeech class to converts the Text into Speech.

Text to Speech Convert:

here we first initialize the TextToSpeech class then apply the OnInitListener. In the listener, we specify the properties of the TextToSpeech object, such as its language, pitch, etc.

Language is set by calling setLanguage() method, in this method we can use different language just set the parameter Locale as your language requirement. Locale is the parameter of setlanguage method.

Once we can change the language, we can call the speck method of the TextToSpeech class.

There are many methods available in the TextToSpeech class. Like

  • addSpeech(String text, String filename): this method adds the mapping between the string of text and sound file.
  • getLanguage(): this method returns a Locale language that is set here.
  • isSpeaking(): this method checks the TextToSpeech engine is busy or not.
  • setPitch(float pitch): this method sets the pitch for the TextToSpeech engine.
  • setSpeedRate(float speechRate): this method sets the sound speed rate.
  • shutdown(): this method frees the resources used by the TextToSpeech.
  • stop(): this method stops the speak.

Here we also use the Seekbar for changing the pitch and speed rate of the speech. Then set the pitch and the speed rate.

File: main_activity.xml



Download the Full Code

Also, we can go and check the video from below link-

And there is your Text to Speech converter app.

Quick Recap:

  • Android provides a class TextToSpeech class to convert the Text into Speech.
  • TextToSpeech has different methods, like setSpeedRate(), addSpeech(), setPitch(), getLanguage(), isSpeaking() etc.
  • Here seek bar is used to change the pitch and speed rate.

You can also see:

If you have any query then comment below

Hi everyone, myself Golap an Android app developer with UI/UX designer.