To Use Text To Speech Follow These Steps
1. Use this code in onCreate event at last
}android.speech.tts.TextToSpeech t1;{
2. In button1 onClick event, set the string variable text to the contents of edittext1, and after that put following code in add source directly block.
t1=new android.speech.tts.TextToSpeech(getApplicationContext(), new android.speech.tts.TextToSpeech.OnInitListener() {
@Override public void onInit(int status) {
if(status != android.speech.tts.TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
t1.speak(text, android.speech.tts.TextToSpeech.QUEUE_FLUSH, null);
} } });
3. in onPause event put this code
if(t1 !=null){
t1.stop();
t1.shutdown(); }
t1.stop();
t1.shutdown(); }
4. Save the project and run the app
Note : Text To Speech take some time to initialize.
Bro... video hay kya iska???
ReplyDelete