TEXT TO SPEECH ANDROID APPLICATION....
Here Write any word in edit text for ex. "Hello" after click button so, listen "Hello"....
Demo Text To Speech |
public class TtsActivity extends Activity implements OnInitListener,
OnClickListener { // here implement two listener....
TextToSpeech t; /Create Text to speech object for ex. t
EditText e;
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = new TextToSpeech(this, this); // Text to Speech create method
e = (EditText) findViewById(R.id.editText1);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(this);
}
public void onClick(View v) { // Button Click Activity
speakOut();
}
public void Destroy() {
if (t != null) {
t.stop();
t.shutdown();
}
super.onDestroy();
}
public void onInit(int arg0) { // Text to Speech method
if (arg0 == TextToSpeech.SUCCESS) {
int result = t.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_NOT_SUPPORTED
|| result == TextToSpeech.LANG_MISSING_DATA)
{
Toast.makeText(this, "lagnguage is not supprted", 2000).show();
} else {
b.setEnabled(true);
speakOut();
}
} else {
Toast.makeText(this, "lagnguage is initiliased", 2000).show();
}
}
public void speakOut() {
String st = e.getText().toString(); // enter ur edittext word and click button so, listen word....
t.speak(st,TextToSpeech.QUEUE_FLUSH, null);
}
VIEW MY TUTORIAL
ReplyDelete