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 |
瀏覽器相容性
載入中…