SpeechRecognitionEvent

SpeechRecognitionEventWeb 语音 API 的一个接口,它表示 resultnomatch 事件的事件对象,并包含与临时或最终语音识别结果相关的所有数据。

Event SpeechRecognitionEvent

实例属性

SpeechRecognitionEvent 还继承了其父接口 Event 的属性。

SpeechRecognitionEvent.emma 只读 已弃用 非标准

返回结果的可扩展多模态注释标记语言 (EMMA)(XML)表示形式。

SpeechRecognitionEvent.interpretation 只读 已弃用 非标准

返回用户所说内容的语义含义。

SpeechRecognitionEvent.resultIndex 只读

返回 SpeechRecognitionResultList “数组”中实际发生更改的最低索引值结果。

SpeechRecognitionEvent.results 只读

返回一个 SpeechRecognitionResultList 对象,该对象表示当前会话的所有语音识别结果。

示例

此代码摘录自我们的 语音颜色更改器 示例。

js
recognition.onresult = (event) => {
  // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
  // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
  // It has a getter so it can be accessed like an array
  // The first [0] returns the SpeechRecognitionResult at position 0.
  // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain
  // individual results.
  // These also have getters so they can be accessed like arrays.
  // The second [0] returns the SpeechRecognitionAlternative at position 0.
  // We then return the transcript property of the SpeechRecognitionAlternative object
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;
};

规范

规范
Web 语音 API
# speechreco-event

浏览器兼容性

BCD 表格仅在浏览器中加载

另请参阅