このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

SpeechRecognitionEvent.resultIndex

利用可能性は限定的

この機能はベースラインではありません。最も広く使用されているブラウザーの一部で動作しません。

Want more support for this feature? Tell us why.

resultIndexSpeechRecognitionEvent のインターフェイスの読み取り専用プロパティで、 SpeechRecognitionResultList 「配列」の中で最も小さな添字を結果として返します。

SpeechRecognitionResultList オブジェクトは配列ではありませんが、配列構文でアクセスできるようにゲッターがあります。

数値です。

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

ブラウザーの互換性

関連情報