JamesBrill / react-speech-recognition

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

cannot abort speech recogntion #1

Closed justinhessdev closed 7 years ago

justinhessdev commented 7 years ago

If I wrap SpeechRecognitionContainer in a top level component the app is always listening even when I don't want it to -- if I talk the transcript prop gets updated to what I am saying. I want it to start recognizing speech when I click the recording button, not all the time. (The red recording icon always shows in the tab bar. I only want it to show whenI click the recording button).

I tried using this.props.recognition.abort() and this.props.recognition.stop() to try and stop the recognition but nothing works.

Is it possible to choose when I want to start and stop speech recognition?

In addition - the speech recognition does not work when the SpeechRecognitionContainer and the component it wraps gets unmounted and then remounted.

Any suggestions?

JamesBrill commented 7 years ago

I've made some changes in #2 that should alleviate these issues. Of most relevance to you will be the new startListening and abortListening callbacks. The Web Speech API wrapper should be more resilient against re-renders now too.

Let me know if upgrading to 1.0.3 improves things for you!

justinhessdev commented 7 years ago

@JamesBrill

So far this is working beautifully. Thanks so much for taking the time to improve the package. I will let you know if I notice any other issues.

justinhessdev commented 7 years ago

Everything looks great but I'll point out two minor issues I've seen.

  1. The SpeechRecognition still listens when rendered. In my top-level component I call abortListening() and the Web Speech API stops listening. However, it still runs for a half second until componentWillMount gets called. Maybe if by default listening is set to false this will solve that issue. And then on the client side we simply call startListening(). Currently, it seems that the user is always being recorded

The Web Speech API wrapper is more resilient against re-renders now

. However if I am "listening" and I unmount the component I get this warning:

Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the SpeechRecognition component.

JamesBrill commented 7 years ago
  1. Ah, I was hoping it wouldn't get a chance to record anything in that short space of time. My reason for having it on by default was because I figured most people would want a "plug and play" component that didn't require any initialisation. However, I see the need for your use case to be supported. I'm going to look into making the default state configurable.

  2. This shouldn't be hard to fix - I'll try to deal with this as well.

justinhessdev commented 7 years ago
  1. Thanks so much. Making default state configurable is really helpful. I owe you one.

  2. Thanks again

Looking forward to the next release

JamesBrill commented 7 years ago
  1. See #3 for how to set the API to off by default in 1.0.4.

  2. Should also be resolved by those changes.

justinhessdev commented 7 years ago

THANKS!

Working great