Text to Speech in Android
Version of android executed in: 1.6rc2 in Windows
TOOLS we used:
Eclipse and Android library 1.6rc2
How it works:
1. In android 1.6rc2 the text to speech library is built in called android.speech.tts, here is link for the information http://developer.android.com/reference/android/speech/tts/TextToSpeech.html
2. Here is the code
package com.android;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
public class TtS extends Activity implements OnInitListener{
/** Called when the activity is first created. */
private TextToSpeech mTts;
int MY_DATA_CHECK_CODE = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
mTts = new TextToSpeech(this,this);
}
@Override
public void onInit(int arg0) {
// TODO Auto-generated method stub
String myText1 = “Did you sleep well?”;
String myText2 = “I hope so, because it’s time to wake up.”;
mTts.setLanguage(Locale.US);
mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null);
}
}
3. To make it even easier you can use you can download the code and open as an existing project. Click here to download.
References:
Popularity: 53% [?]





