Android – Text to speech simple example

android   In this article I will show the most simple way to add text to speech abilities to your Android application.


public class Text2SpeechTest extends Activity implements OnInitListener {

	TextToSpeech talker;

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

    public void say(String text2say){
    	talker.speak(text2say, TextToSpeech.QUEUE_FLUSH, null);
    }

	@Override
	public void onInit(int status) {
		say("Hello World");

	}

	@Override
	public void onDestroy() {
		if (talker != null) {
			talker.stop();
			talker.shutdown();
		}

		super.onDestroy();
	}
}




Download code example

7 thoughts on “Android – Text to speech simple example

  1. Muy bueno. Funciona en el emulador y en mi tableta.
    Muchas gracias.

    Very good. It works in the emulator and on my tablet.
    Thank you very much.

  2. anyone knows how to add a language?, such as Spanish

    ——————-

    Alguien sabe como añadir un idioma que no esta soportado de serie, como por ejemplo Español.

    Gracias. un saludo.

  3. Can anyone tell that how to use google to speech tts and espeak app both in my application. i want to use both, randomly.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>