 |
|
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
Here is a nice example given by android itself: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html
Its good example
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.