How to create Android text to speech application that says "hello world" without using text field to write the text? -
i making simple application when user clicks on button, background voice says "hello world". have gone through tutorials problem use text field write text user , executed button. want user click on button , voice should "hello world".
your mainactivity:-
package com.example.tts; import android.app.activity; import android.os.bundle; import android.speech.tts.texttospeech; import android.view.view; import android.widget.button; import android.widget.edittext; import java.util.locale; import android.widget.toast; public class mainactivity extends activity { texttospeech t1; button b1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); b1=(button)findviewbyid(r.id.button); t1=new texttospeech(getapplicationcontext(), new texttospeech.oninitlistener() { @override public void oninit(int status) { if(status != texttospeech.error) { t1.setlanguage(locale.uk); } } }); b1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string tospeak = "hello world"; toast.maketext(getapplicationcontext(), tospeak,toast.length_short).show(); t1.speak(tospeak, texttospeech.queue_flush, null); } }); } public void onpause(){ if(t1 !=null){ t1.stop(); t1.shutdown(); } super.onpause(); } }
Comments
Post a Comment