微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在 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 词汇表中的“信条”一词。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。