SpeechRecognitionResult: length 属性

可用性有限

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

lengthSpeechRecognitionResult 接口的一个只读属性,它返回“数组”的长度,即结果中包含的 SpeechRecognitionAlternative 对象的数量(也称为“n 佳备选方案”)。

结果中包含的备选方案数量取决于首次启动语音识别时 SpeechRecognition.maxAlternatives 属性的设置值。

一个数字。

示例

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

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

  console.log(event.results[0].length);
};

规范

规范
Web Speech API
# dom-speechrecognitionresult-length

浏览器兼容性

另见