SpeechRecognitionEvent

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

SpeechRecognitionEventウェブ音声 API のインターフェイスで、 result および nomatch イベントのイベントオブジェクトを表し、中間または最終の音声認識結果に関連するすべてのデータを保持します。

Event SpeechRecognitionEvent

インスタンスプロパティ

SpeechRecognitionEvent は親インターフェイスである Event からプロパティを継承しています。

SpeechRecognitionEvent.emma 読取専用 非推奨 Non-standard

結果の EMMA (Extensible MultiModal Annotation markup language) - XML - 表現を返します。

SpeechRecognitionEvent.interpretation 読取専用 非推奨 Non-standard

ユーザーが言ったことの意味づけを返します。

SpeechRecognitionEvent.resultIndex 読取専用

実際に変更された SpeechRecognitionResultList (en-US) 「配列」の中で最もインデックス値の小さい結果を返します。

SpeechRecognitionEvent.results 読取専用

現在のセッションのすべての音声認識結果を表す SpeechRecognitionResultList (en-US) オブジェクトを返します。

このコードは Speech color changer の例から取得したものです。

js
recognition.onresult = (event) => {
  // The SpeechRecognitionEvent results property returns a SpeechRecognitionResultList object
  // The SpeechRecognitionResultList object contains SpeechRecognitionResult objects.
  // It has a getter so it can be accessed like an array
  // The first [0] returns the SpeechRecognitionResult at position 0.
  // Each SpeechRecognitionResult object contains SpeechRecognitionAlternative objects that contain
  // individual results.
  // These also have getters so they can be accessed like arrays.
  // The second [0] returns the SpeechRecognitionAlternative at position 0.
  // We then return the transcript property of the SpeechRecognitionAlternative object
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `Result received: ${color}.`;
  bg.style.backgroundColor = color;
};

仕様書

Specification
Web Speech API
# speechreco-event

ブラウザーの互換性

BCD tables only load in the browser

関連情報