Hello everyone……..

In this simple example I will show you how to use Text To Speech in ANDROID. This is one of the unique features in ANDROID.
Unlike iPhone , ANDROID has a built in TTS Library which supports many languages. But iPhone doesn’t have this feature. They have to depend on third-party software for implementing this.

Now go on create a fresh project and copy this following code to it.

package com.TTS;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;

public class TTS extends Activity implements TextToSpeech.OnInitListener {

	  TextToSpeech tts;
	  @Override
	  public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    tts = new TextToSpeech(this,this);
	  }

	  public void onInit(int status) {
	    Locale loc = new Locale("eng", "","");
	    if(tts.isLanguageAvailable(loc) >= TextToSpeech.LANG_AVAILABLE){
	      tts.setLanguage(loc);
	    }
	    tts.speak("Text to speech in ANDROID from coderzheaven, Hope you like it.", TextToSpeech.QUEUE_FLUSH, null);
	  }

	  @Override
	  protected void onDestroy() {
	    super.onDestroy();
	    tts.shutdown();
	  }
}

After running this application you will hear the sound that is given as text in this line.

tts.speak(“Text to speech in ANDROID from coderzheaven, Hope you like it.”, TextToSpeech.QUEUE_FLUSH, null);

Please leave your comments if this post was useful.

 

3 Comments

  1. tabletki na odchudzanie April 9, 2011 at 8:28 pm

    Great info dude thanks for useful article. I’m waiting for more

     
  2. Malik April 10, 2011 at 1:10 pm

    @tabletki na odchudzanie-> thank you so much… We are working more on Android, iPhone and other related stuffs… we will update with other useful resources from these… Keep in touch… and once again thank you for your support… 🙂

     
  3. varsha June 9, 2011 at 12:36 pm

    its nice.
    i need to display that text in emulator.can any1 help me

     

Leave a Reply

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

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.