Abishek
Abishek

Reputation: 67

How to disable sentence-level auto correction in SpeechRecognition Web Speech API

when I speak a sentence 'show tenet movie near me' automatically the speech recognition API changing my sentence to 'show tonight movie near me' the problem was the word tenet is changed to tonight

Upvotes: 0

Views: 279

Answers (1)

jbflow
jbflow

Reputation: 642

Have you tried checking the alternatives? You can set maxAlternatives to something high like 20, then use a function such as this to check if one of them contains the phrase you're looking for.

Pass your phrases as an array and the results received from SpeechRecognition.

function ExtractTranscript(phrases, results) {
  // Loop through the alternatives to check if any of our phrases are contained in them.
  for (let result in results[0]) {
    if (new RegExp(phrases.join("|")).test(results[0][result].transcript)) {
      return results[0][result].transcript; // Return the alternative if they are
    }
  }
  return results[0][0].transcript; // Otherwise return the one with the highest confidence
}

This does also rely on the word "tenet" being in the vocabulary of the API.

Upvotes: 0

Related Questions