简体   繁体   English

如何在 SpeechRecognition Web Speech API 中禁用句子级自动更正

[英]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当我说出一句话“在我附近放映宗旨电影”时,语音识别 API 自动将我的句子更改为“在我附近放映今晚的电影”问题是宗旨一词更改为今晚

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.您可以将 maxAlternatives 设置为 20 之类的高值,然后使用 function 来检查其中一个是否包含您要查找的短语。

Pass your phrases as an array and the results received from SpeechRecognition.将您的短语作为数组传递,并从 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.这也依赖于 API 词汇表中的“信条”一词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM