Android Text to Speech Tutorial

In this android tutorial we are going to learn creating Android Text to Speech. Android allows you convert your text into voice. Not only you can convert it but it also allows you to speak text in variety of different languages.

Android Text to Speech Tutorial

Download projct file of  Android Text  To Speech  Tutorial – Android Studio

I developed a simple interface with one input field and a button to trigger a event that will take text from input field and speaks out.


1. Create a new project by going to File ⇒ New Android Project. and fill required details.

2. Now add following code in src/

package com.andrious.texttospeech;

import android.speech.tts.TextToSpeech;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import java.util.Locale;

public class MainActivity extends AppCompatActivity {
    TextToSpeech t1;
    EditText write;
    ImageButton speakbtn;

    protected void onCreate(Bundle savedInstanceState) {

        write=(EditText) findViewById(;

        t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            public void onInit(int status) {
                if (status != TextToSpeech.ERROR) {
        speakbtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String toSpeak = write.getText().toString();
                Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);

    public void onDestroy() {
        // Don't forget to shutdown tts!
        if (t1 != null) {

3. Now add following xml in activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>
     android:hint="Write your text here :"/>

4. Now run your project and test your app by entering some text in input filed.

Changing Language

You can change language to speak by using setLanguage() function. Lot of languages are supported like Canada, French, Chinese, Germany etc.,

text to speech

t1.setLanguage(Locale.UK); // UK language

Changing Pitch Rate

You can set speed pitch level by using setPitch() function. By default the value is 1.0 You can set lower values than 1.0 to decrease pitch level or greater values for increase pitch level.


Changing Speed Rate

The speed rate can be set using setSpeechRate(). This also will take default of 1.0 value. You can double the speed rate by setting 2.0 or make half the speed level by setting 0.5




  1. Christiane Rutana

    July 11, 2018 at 11:22 pm

    Do you have a spam problem on this blog; I also am a blogger, and I was curious about your situation; we have developed some nice methods and we are looking to trade methods with other folks, please shoot me an e-mail if interested.

  2. Berry Fahrenkrug

    July 15, 2018 at 2:28 pm

    Appreciating the hard work you put into your site and detailed information you offer. It’s great to come across a blog every once in a while that isn’t the same old rehashed information. Wonderful read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

  3. Mitchell Rosero

    July 20, 2018 at 5:27 pm

    One thing is that while you are searching for a education loan you may find that you will need a cosigner. There are many circumstances where this is correct because you may find that you do not employ a past history of credit so the loan provider will require that you’ve someone cosign the financial loan for you. Good post.

  4. Sachiko Dubinsky

    July 21, 2018 at 2:54 pm

    It’s actually a nice and useful piece of information. I’m glad that you shared this useful info with us. Please keep us informed like this. Thanks for sharing.

  5. Yuki Cesari

    July 23, 2018 at 1:35 pm

    One thing I have actually noticed is that often there are plenty of misguided beliefs regarding the finance institutions intentions whenever talking about foreclosed. One fantasy in particular would be the fact the bank would like your house. Your banker wants your hard earned money, not the home. They want the funds they gave you with interest. Keeping away from the bank will simply draw the foreclosed conclusion. Thanks for your post.

  6. furtdsolinopv

    October 7, 2018 at 2:26 pm

    I was looking through some of your articles on this website and I think this website is rattling informative! Continue putting up.

  7. Leo Zaneski

    October 27, 2018 at 4:37 pm

    you got a very great website, Gladiola I found it through yahoo.

  8. loans no credit check

    December 8, 2018 at 10:16 am

    Do you need to justify that? Haha|

  9. ViolaBig

    December 25, 2018 at 1:30 am

    Hello. I have checked your and i see you’ve got some duplicate content so probably it is the reason that you
    don’t rank hi in google. But you can fix this issue fast. There is a tool
    that creates content like human, just search in google: miftolo’s tools

  10. Jarod Markie

    January 9, 2019 at 6:27 pm

    I was studying some of your content on this internet site and I believe this web site is really informative ! Retain putting up.

  11. smart defrag 6.0.1 key

    February 20, 2019 at 9:25 pm

    You could certainly see your skills in the work you write. The sector hopes for even more passionate writers such as you who aren’t afraid to mention how they believe. All the time go after your heart.

  12. Freebies

    April 26, 2019 at 5:18 am

    Get real free stuff and free samples by mail, coupons, deals and giveaways. Updated constantly with all the newest Free Stuff, Free Samples, Freebies, Coupons and Deals.

  13. Free Stuff

    April 26, 2019 at 9:30 pm

    The best free stuff, free samples, freebies, deals, and coupons. Updated daily, so there’s always something fresh.

  14. Free Stuff

    May 25, 2019 at 8:04 pm

    You made some good points there. I did a search on the theme and found a good number of people will have the same opinion with your blog.

Leave a Reply