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

瀏覽器相容性

另見