JamesBrill / react-speech-recognition

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

bug found with bestMatchOnly #82

Closed Nitzahon closed 3 years ago

Nitzahon commented 3 years ago

So if you may recall I was the one who requested the feature of bestMatchOnly, I found a bug though, when working with an array that included the nfollowing:

{
command: ['item two','item four','item five','item six'],
      callback: (command) => videoCommandCallback(command),
      isFuzzyMatch: true,
      fuzzyMatchingThreshold: 0.6,
      bestMatchOnly: true
}

when ever either "item four" or "item five" was spoken, the command that triggered the callback (aka the bestMatch) was in fact "item two"

JamesBrill commented 3 years ago

This is unfortunately the expected behaviour of the Web Speech API. When you say "item six", Web Speech API will actually transcribe this as "item 6", which matches all of your four command phrases equally badly so ends up just matching the first one by default. The matching algorithm just operates on the raw strings and does not understand the meaning of any words.

To make things more complex, some numbers will be transcribed as words. e.g. "item four" is transcribed as "item for" - the API doesn't have enough context to know that you intended to say the number.

There are a couple of ways around this: