Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Android – Text to speech simple example

DZone's Guide to

Android – Text to speech simple example

· Mobile Zone ·
Free Resource
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

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}