speech-recognition icon indicating copy to clipboard operation
speech-recognition copied to clipboard

add allowForSilence during recording

Open tobika opened this issue 7 months ago • 3 comments

Responding to this issue: https://github.com/capacitor-community/speech-recognition/issues/102

We don't want the recording to stop immediately after the user stops to talk for a few milliseconds.

Since API 33 we need to use EXTRA_SEGMENTED_SESSION together with EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS to achieve this goal.

https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SEGMENTED_SESSION

Segmented session uses different callbacks on the RecognitionListener: onSegmentResults which wors a bit like onPartialResults and onEndOfSegmentedSession.

If you want to use allowForSilence in the config you have to listen to this events in order to get the results.

This is a first proposal and I'm still questioning if there's not a simpler interface for the plugin users. Reusing the onPartialResults even though it works a bit different. Collecting all results on the java side and pushing them back in the classic promise resolve of the start function?

I'm not at all a java developer but it works. On the iOS side I haven't tested yet if there is a similar problem.

tobika avatar Jul 05 '24 14:07 tobika