SpeechRecognitionEvent

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

SpeechRecognitionEvent 接口是 Web Speech API 的一部分,它代表了 resultnomatch 事件的事件对象,并包含了与临时或最终语音识别结果相关的所有数据。

Event SpeechRecognitionEvent

构造函数

SpeechRecognitionEvent()

创建一个新的 SpeechRecognitionEvent 对象。

实例属性

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

SpeechRecognitionEvent.resultIndex 只读

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

SpeechRecognitionEvent.results 只读

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

示例

此代码摘自我们的 语音变色器 示例。

js
recognition.onresult = (event) => {
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;
};

规范

规范
Web Speech API
# speechreco-event

浏览器兼容性

另见