Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CallBacks for event and functions for startListening,stopListening,abort etc..? #12

Closed
hvardhan617 opened this issue Mar 15, 2019 · 1 comment

Comments

@hvardhan617
Copy link

Will we get any callbacks while invoking async functions such as startListening,stopListening,abortListening ?
If so, how can we handle the callbacks?

@JamesBrill
Copy link
Owner

There are two ways you can do this:

  • Use the built-in event handlers in the Speech Recognition object, which is given to you as a property called recognition. You can set these to your callback function when constructing or mounting your component:
    const { recognition } = this.props
    recognition.onend = () => console.log("Listening has stopped");
    recognition.onstart = () => console.log("Listening has started");
  • Detect changes to the listening property, which is another property injected by react-speech-recognition. If you're using a class-based React component, you can pick up these changes in the componentWillReceiveProps lifecycle hook. For example:
  componentWillReceiveProps(nextProps) {
    if (this.props.listening !== nextProps.listening) {
      console.log(nextProps.listening);
    }
  }

Hope that helps!

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

No branches or pull requests

2 participants