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

问题描述

当我说出一个句子“show tenet movie near me”时,语音识别 API 会自动将我的句子更改为“show tonight movie near me”,问题是这个词宗旨改为今晚

解决方法

您是否尝试过检查替代方案?您可以将 maxAlternatives 设置为 20 之类的值,然后使用这样的函数来检查其中一个是否包含您要查找的短语。

将您的短语作为数组和从 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
}

这也依赖于 API 词汇表中的“信条”一词。