Skip to content

Conversation

tobika
Copy link

@tobika tobika commented Jul 5, 2024

Responding to this issue: #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.

@maxcodefaster

This comment was marked as abuse.

@tobika
Copy link
Author

tobika commented Jul 29, 2024

I forgot to add that this approach doesn't work with popup: true maybe I should add a check in the plugin that returns an error if this config parameters are not compatible?

@vovanb
Copy link

vovanb commented Aug 4, 2024

@tobika can you share working example with EXTRA_SEGMENTED_SESSION ?

@msty
Copy link

msty commented Nov 17, 2024

On the iOS side I haven't tested yet if there is a similar problem.

I have not observed the same problem on iOS after testing my app on both devices.

@azicchetti
Copy link

Thank you, this PR is quite useful. Without the allowForSilence option, this plugin is basically useless on android for long speeches, where a lot of pauses are the norm

@tobika
Copy link
Author

tobika commented Sep 1, 2025

Hi again,
After 1 year I came back to the project for which I initially developed this fix. Is there an intention to merge this? Or should there be some more changes, better documentation? Still have to copy/paste my own version in the node_modules ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants