csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
348 stars 217 forks source link

'error_no_match' does not get fired when user stops listening #509

Open vongrad opened 2 weeks ago

vongrad commented 2 weeks ago

I have noticed that error_no_match does not get fired after user stops listening because the flags isNotListening and _userEnded are set before calling the platform specific stop.

This happens in:

 Future<void> _onNotifyError(String errorJson) async {
    if (isNotListening && _userEnded) {
      return;
    }
    ...

The reason why this is an issue is that there is no consistent way to react to results - no matter if there is a match or not. For example, if the STT matches some text, the output looks like this:

/SpeechToTextPlugin( 7989): Notify status:notListening
D/SpeechToTextPlugin( 7989): Notify status:doneNoResult
D/SpeechToTextPlugin( 7989): rmsDB -2.0 / 10.0
D/SpeechToTextPlugin( 7989): rmsDB -2.0 / 10.0
D/SpeechToTextPlugin( 7989): Calling results callback

Note that Calling results callback is called after doneNoResult (perhaps the doneNoResult should be changed to done or similarly as this is a bit misleading when there are results, but its not an issue now).

Now consider the following output without any results:

D/SpeechToTextPlugin( 7989): Notify status:notListening
D/SpeechToTextPlugin( 7989): Notify status:doneNoResult

As you can see, its the same, but the Calling results callback is not called as there are no results.

Now to the issue, if you want, lets say show some popup to the user once the STT result is ready, independently if the STT matched something or not, there is no easy way to do it, as in case with the actual result, you would have to wait some amount of time to see if Calling results callback gets fired, because it could as well be the case where there is no result.

I would propose that the error_no_match get triggered even after the user stops listening as this way, we know the STT results are ready once Calling results callback gets fired OR error_no_match gets fired.

sowens-csd commented 2 weeks ago

Interesting idea and a good explanation. Thanks for taking the time to write it up. Giving consistent feedback on results/no results seems like a very good thing to do.

I won’t be able to look at this for a few weeks but I’ll put it on the list.