SpeechRecognitionResult: length 属性
length 是 SpeechRecognitionResult 接口的一个只读属性,它返回“数组”的长度,即结果中包含的 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 |
浏览器兼容性
加载中…