SpeechRecognitionEvent: resultIndex 属性

可用性有限

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

SpeechRecognitionEvent 接口的 resultIndex 只读属性返回在 SpeechRecognitionResultList“数组”中实际发生变化的最低索引值结果。

SpeechRecognitionResultList 对象不是一个数组,但它有一个 getter,允许通过数组语法访问它。

一个数字。

示例

js
recognition.onresult = (event) => {
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;
  console.log(event.resultIndex); // returns 0 if there is only one result
};

规范

规范
Web Speech API
# dom-speechrecognitionevent-resultindex

浏览器兼容性

另见