i dont find answer on google or dont right words it.
so speechrecognizer works fine. when hear beep (i use without google dialog) , nothing 3 seconds or more, recognizer nothing , fade away, no second beep hear, no onresult(), no endofspeech.
so happend when recognizer listening , nothing? method fired?
edit: after works, big opiatefuchs , realy comments , answers. edit simplified code way, guys can see how make it.
onpartialresult() called if nothing, when happen partialresult string empty, if empty know nothing spoken. (idea opiatefuchs)
thats simplified code important recognizer:
public constructor (){ speech = speechrecognizer.createspeechrecognizer(context); speech.setrecognitionlistener(this); recogintent = new intent(recognizerintent.action_recognize_speech); recogintent.putextra(recognizerintent.extra_language_preference, "de"); speech.startlistening(); } public void startlistening(){ speech.startlistening(recogintent); if(timerrunning==false){ setcdt(); mcountdowntimer.start(); timerrunning=true; } } @override public void onreadyforspeech(bundle params) { } @override public void onbeginningofspeech() { } @override public void onrmschanged(float rmsdb) { } @override public void onbufferreceived(byte[] buffer) { } @override public void onendofspeech() { toast.maketext(c, "work", toast.length_short); //too see if called } @override public void onerror(int error) { } @override public void onresults(bundle results) { arraylist<string> matches = results .getstringarraylist(speechrecognizer.results_recognition); toast.maketext(c, matches.get(0), toast.length_long).show(); speech.cancel(); analyse(matches.get(0)); m.next(); //calls recognizer again } @override public void onpartialresults(bundle partialresults) { arraylist<string> matches = partialresults .getstringarraylist(speechrecognizer.results_recognition); if(matches.get(0).length() == 0){ m.tv.append("nothing"); //show on textview } else{ m.tv.append("cancel timer "); //show on textview mcountdowntimer.cancel(); hasspoken = true; timerrunning = false; } } @override public void onevent(int eventtype, bundle params) { } //innerclass public class finishspeechrecognizertimer extends countdowntimer { public finishspeechrecognizertimer(long starttime, long interval){ super(starttime,interval); } @override public void onfinish(){ timerrunning = false; if (hasspoken==false){ m.tv.append("nospeak "); speech.cancel(); m.tv.append("listen again after no speak "); startlistening(); } } @override public void ontick(long millisuntilfinish){ } } public void setcdt(){ starttime = 5000; interval = 4000; //want no ontick - interval > starttime timerrunning = false; hasspoken = false; mcountdowntimer = new finishspeechrecognizertimer(starttime, interval); }
for discussion try provide example scratch should lead right direction. said in comments, seems speechrecognition
not stop if nothing said, implement
countdowntimer
example , finish speechrecognizer
after time:
make global speechrecognizer
(like have done), boolean
, countdowntimer
objects
:
private speechrecognizer speech; private boolean hasspoken=false; private countdowntimer mcountdowntimer; private long starttime = 30000l; private long interval = 1000l; private boolean timerrunning = false;
extend countdowntimer class
:
public class finishspeechrecognizertimer extends countdowntimer{ public finishspeechrecognizertimer(long starttime, long interval){ super(starttime,interval); } @override public void onfinish(){ if(hasspoken==false){ speech.cancel(); } timerrunning=false; } @override public void ontick(long millisuntilfinish){ //do whatever want } }
initialize
speech = speechrecognizer.createspeechrecognizer(yourcontext); mcountdowntimer = new finishspeechrecognizertimer(starttime, interval);
start , @ same time start countdowntimer
:
speech.startlistening(recogintent); if(timerrunning==false){ mcountdowntimer.start(); timerrunning=true; }
and spoken, set boolean value
hasspoken
true
, cancel
timer:
@override public void onbeginningofspeech() { hasspoken=true; mcountdowntimer.cancel(); timerrunning=false; }
as said, it´s scratch, can´t guarantee working. example starts countdowntimer
30 seconds , checks every second if spoken. how long want wait you.
edit
turns out in cases onbeginofspeech() method called multiple times without speaking. interested:
instead of doing stuff in onbeginofspeech()
, can use method onpartialresult():
@override public void onpartialresults(bundle partialresults) { arraylist<string> matches = results .getstringarraylist(speechrecognizer.result_recognition); if(matches.size()==0){ hasspoken=false; }else{ hasspoken=true; mcountdowntimer.cancel(); timerrunning=false; } }
Comments
Post a Comment