android - RecognitionListener doesn't call onEndOfSpeech immediately after user stops talking? -
so using speechrecognizer
along recognitionlistener
recognize user speech. works fine problem when tested noticed doesn't call onendofspeech
after finishes talking. waits around 7 10 seconds , onendofspeech
, onresult
called. don' know reason delay.
here code:
public class mainactivity extends appcompatactivity { protected static final int request_ok = 1; speechrecognizer sr; textview mtext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mtext = (textview) findviewbyid(r.id.text1); recognitionlistener recognitionlistener=new recognitionlistener() { @override public void onreadyforspeech(bundle bundle) { toast.maketext(mainactivity.this,"start takling",toast.length_short).show(); } @override public void onbeginningofspeech() { } @override public void onrmschanged(float v) { } @override public void onbufferreceived(byte[] bytes) { } @override public void onendofspeech() { toast.maketext(mainactivity.this,"onendofspeech",toast.length_short).show(); } @override public void onerror(int i) { } @override public void onresults(bundle bundle) { toast.maketext(mainactivity.this,"onresults",toast.length_short).show(); arraylist<string> voiceresults = bundle.getstringarraylist(speechrecognizer.results_recognition); if (voiceresults != null) { string text = voiceresults.get(0); toast.maketext(mainactivity.this,text,toast.length_short).show(); } } @override public void onpartialresults(bundle bundle) { } @override public void onevent(int i, bundle bundle) { } }; sr = speechrecognizer.createspeechrecognizer(this); sr.setrecognitionlistener(recognitionlistener); findviewbyid(r.id.button1).setonclicklistener( new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent(recognizerintent.action_recognize_speech); intent.putextra(recognizerintent.extra_language_model, "en-us"); sr.startlistening(intent); } }); } @override protected void ondestroy() { super.ondestroy(); sr.destroy(); } }
activity_main.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" > <textview android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="132dp" android:text="..." ></textview> <imagebutton android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/text1" android:layout_centerhorizontal="true" android:layout_margin="10dp" android:layout_margintop="37dp" android:src="@android:drawable/ic_btn_speak_now" ></imagebutton> </relativelayout>
Comments
Post a Comment