JamesBrill / react-speech-recognition

💬Speech recognition for your React app
https://webspeechrecognition.com/
MIT License
657 stars 119 forks source link

Continuous mode doesn't clear transcript #58

Closed thiagoss closed 3 years ago

thiagoss commented 3 years ago

Not sure if this is a problem with this project or the underlying Web API. When using continuous mode it keeps listening as expected, but the transcript text is never cleared, even after issuing stopListening().

I also tried calling resetTranscript() after calling stopListening() but that seems to turn on listening again for some reason.

JamesBrill commented 3 years ago

Hi @thiagoss Can you please share the following:

Some initial comments:

thiagoss commented 3 years ago

I just got latest master as of today (v3.2.0) and turned the example into the issue by adding my code to it: https://github.com/thiagoss/react-speech-recognition/tree/example-issue-58

It makes sense that stopListening doesn't clear the transcript but I'm still unsure why resetTranscript seems to make it start listening again. I was hoping resetting the transcript wouldn't change current listening state.

Testing on Windows Chrome Version 84.0.4147.135 (Official Build) (64-bit)

JamesBrill commented 3 years ago

Indeed, the reset should not affect the listening state.

Thanks for clarifying that, though I think you may be missing SpeechRecognitionPanel, which your example references but did not commit. Could you include that as well?

thiagoss commented 3 years ago

Oh, sorry about that. Just added the file.

JamesBrill commented 3 years ago

I was able to reproduce the bug; thanks for the example. I see there is a race condition between resetTranscript and stopListening. I am taking a look at a solution.

I see you also used clearTranscriptOnListen - note that this only does anything when continuous listening is turned off. This clears the transcript when startListening is called to restart the microphone for discontinuous listening - this works well for the typical "push to talk" use case.

For clearing the transcript when the user stops speaking during continuous listening, you are actually taking the right approach by listening for new final transcripts and resetting then. I will update this issue as soon as I've published a version that enables this to work as expected.

JamesBrill commented 3 years ago

@thiagoss Give v3.2.1 a try.

thiagoss commented 3 years ago

It worked! Thanks for the quick fix!