npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

voice-command-recognizer

v1.0.8

Published

React HOC for voice command recognition. Based on Web Speech API's Speech Recognizer, using Annyang

Downloads

12

Readme

voice-command-recognizer

React component to recognize voice commands based on the Web Speech API (SpeechRecognizer).

Dependencies

It relies on annyang (Speech Recognition library by TalAlter) for command matching.

It enhances the command recognition by adding a fuzzyMatchThreshold feature. This prop allows to specify a certain tolerance for what the user says to be considered as correct.

The string comparison is using fuzzyset.js by @Glench with its default config.

How the component works

It's an HOC and you are capable of just conditionally rendering things inside it, based on its state (as with any other HOC).

You can either set the component to be listening to everything or only enable listening once the user says a certain keyphrase that you can define through the component props. The keyphrase needs to be said before each command. The voice-command-recognizer stops listening after the first successfully understood command. So, the keyphrase if set, is expected to be said between the commands that are intended to be ran.

You can also define a percentage of accuracy for what the user says and either run a custom action when that threshold is reached or just consider that as correct. It's useful for those cases when the user might not be a native english speaker and you'd like to be a bit more forgiving on pronunciation. :)

voice-command-recognizer also provides a hook when the keyphrase has been detected and the component is ready to listen to the commands provided (onRecognizerEnabled).

Props:

  • commands: The commands to be accepted and the function to be run for each. Different formats are accepted, see the Commands section below.
  • keyCommand: The command that would enable the component to listen. When said again, it would make the component stop listening.
  • startVoiceRecognition: Flag that allows to start/pause the recognition.
  • fuzzyMatchThreshold: A number (from 0 to 1) that determines how exact what the user says need to be.
  • onPermissionBlocked: The function to be run if the browser denies access to the microphone.
  • onPermissionDenied: The function to be run if the user denies access to the microphone.
  • onStart: It's triggered when SpeechRecognizer triggers its onstart event. It's a way to update your application once the speech recognition is started (i.e.: the browser can hear you).
  • onRecognizerEnabled: For the case when a keyphrase is provided, this prop expects a function that'd be executed once voice-command-recognizer has detected the keyphrase being said and it's ready to listen for a command.
  • onRecognizerDisabled: For the case when a keyphrase is provided, this prop expects a function that'd be executed once the actual command that was intended to be executed has been detected and the recognizer goes back to waiting on the keyphrase to be said.
  • onFuzzyMatch: Action to be ran when what the user is at least fuzzyMatchThreshold. If there's not an action provided, the component will trigger the command that's closes to what the user said.
  • onNotMatch: Action to be run when there's not a full match neither a fuzzy match with any of the available commands.

commands prop

The format expected for the command would be as follows:

{
  phrases: ['search', 'look for', 'find'],
  callback: () => {
    const { counter } = this.state;

    this.setState({
      counter: counter + 1,
    });
  },
}

phrases are basically the commands that when said would trigger the function that's in callback attribute.

They don't need to be specific words, but you can make it more general and use either regexes or spats.

This is supported through Annyang. Have a look at their doc's for how the commands can be defined.

Next steps

  • [ ] Update the current implementation on Guess the Movie to use this component.