speech_recognition icon indicating copy to clipboard operation
speech_recognition copied to clipboard

Stop listening when voice end

Open antonmolchan opened this issue 6 years ago • 8 comments

Hi, on Android platform when listening started, user speak some voice and when user stop speaking, application stoped to listen him. On IOS that function dont worked, and application listening all time while user do not clicked on stop button. Is it possible to stop listening user if he finished talking?

antonmolchan avatar Jun 05 '19 19:06 antonmolchan

I solved that on iOS by using a timer. Every time a new word comes from the speech recognition stream, I call it:

if (forceDetectSpeechDetectionOff) {
      _lastWordTimer?.cancel();
      _lastWordTimer = Timer(Duration(milliseconds: 1000), () {
        recognition.stop();
      });
    } 

shinayser avatar Jun 06 '19 15:06 shinayser

@shinayser Hi, i write the same code, works good. Maybe you know how on android set listening only for eng language ? When i start application on phone with rus language, application try to listen rus or eng voice(when i say only one word, in most cases i seen rus text), but when i setup phone on eng language all works fine. This exception of library, in android path.

antonmolchan avatar Jun 07 '19 00:06 antonmolchan

@antonmolchan @shinayser Guys, sorry for noob question, but how to implement this code?

if (forceDetectSpeechDetectionOff) {
      _lastWordTimer?.cancel();
      _lastWordTimer = Timer(Duration(milliseconds: 1000), () {
        recognition.stop();
      });
    } 

There is no boolean forceDetectSpeechDetectionOff in this package, so as _lastWordTimer definition... Thanks

tsinis avatar Oct 08 '19 12:10 tsinis

@tsinis

declare a class Timer variable.. Line: 53

put it on your callback..

Line: 182 to 186

Screen Shot 2019-10-11 at 4 42 55 PM

monggos avatar Oct 11 '19 08:10 monggos

@tsinis declare a class Timer variable.. Line: 53 put it on your callback.. Line: 182 to 186

@monggos Awesome, now I get it, at first I didn’t understand where the Тimer class comes from etc. Now it's works like a charm. Thanks a million!

tsinis avatar Oct 11 '19 13:10 tsinis

I am having a problem with IOS, OnRecognitionResultHandler is never called after speaking. As @monggos showed, I did follow the same but not Working Any Suggestions.

ramsham2411 avatar Nov 08 '19 12:11 ramsham2411

@ramsham2411 first, check your callback registration if set correctly.. like this..

Screen Shot 2019-11-12 at 11 12 41 PM

monggos avatar Nov 12 '19 15:11 monggos

Wouldn't it be useful to have an optional timeout to configure (like SpeechTimeout)? It's unexpected that this behavior differs between iOS and Android.

beevelop avatar Jan 10 '20 12:01 beevelop