JamesBrill / react-speech-recognition

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

bestMatchOnly option for fuzzy matching #78

Closed JamesBrill closed 3 years ago

JamesBrill commented 3 years ago

When an array of command phrases is provided for a fuzzy command, there is the possibility that the callback will be triggered multiple times. For example, take the following command:

      {
        command: ['eat', 'sleep', 'leave'],
        callback: (command) => console.log(command),
        isFuzzyMatch: true,
        fuzzyMatchingThreshold: 0.2
      }

If the user says "leap", the callback will be triggered three times as it matches all three command phrases.

This release introduces a new command option bestMatchOnly. This is false by default but when set will ensure the callback is only called once by the command phrase with the best match. If we modify the example above to

      {
        command: ['eat', 'sleep', 'leave'],
        callback: (command) => console.log(command),
        isFuzzyMatch: true,
        fuzzyMatchingThreshold: 0.2,
        bestMatchOnly: true
      }

then it will only be called once for the "leave" command, which has a slightly better match than the others.