【问题标题】:Speech to text web api returns different result on desktop vs mobileSpeech to text web api 在桌面和移动设备上返回不同的结果
【发布时间】:2018-06-20 17:27:28
【问题描述】:

我正在使用Web Speech API 使用以下代码将语音转换为文本:

const SpeechRecognition = window.webkitSpeechRecognition;
recognition = new SpeechRecognition();
recognition.onresult = (ev) => {
  const text = [...ev.results].reduce(
      (a, e) =>
        a + [...e].reduce((word, { transcript: t }) => `${word}${t}`, ''),
      '',
    );
  }
  this.setState({ speechText: text });
};

这在桌面上完美运行,来自 api 的结果如下:

但在移动端的 api 结果如下:

请忽略以上截图中的内容(成绩单)。桌面上的行为应如此,但在移动设备上,这会导致大量内容重复,因为结果具有重复的 SpeechRecognitionResult 值。我不确定为什么会这样。任何帮助表示赞赏。

此外,一旦用户停止讲话,桌面上的isFinal 即为true,但在移动设备上始终为true

【问题讨论】:

  • 是吗?手机只是提供了多个它对它的信心为 0 的替代品。你想发生什么?
  • 我做错了。刚刚找到了不需要 reduce() 的正确解决方案。

标签: javascript reactjs google-chrome speech-recognition


【解决方案1】:

这是在移动设备和桌面设备上检索结果的正确方法:

recognition.onresult = (ev) => {
  let noteContent = '';
  const current = ev.resultIndex;

  // Get the transcript
  const { transcript } = ev.results[current][0];

  // Append the current transcript to previous Note
  noteContent += transcript;

  this.setState({ speechText: noteContent });
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    相关资源
    最近更新 更多