SpeechRecognition: result イベント

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

resultウェブ音声 API のイベントで、音声認識サービスが結果を返したとき、つまり単語やフレーズが正の値で認識され、それがアプリに伝達されたときに発行されます。

構文

このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

js
addEventListener("result", (event) => {});

onresult = (event) => {};

イベント型

イベントプロパティ

以下に列挙したプロパティに加えて、親インターフェイスである Event から継承したプロパティも利用できます。

SpeechRecognitionEvent.emma 読取専用

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

SpeechRecognitionEvent.interpretation 読取専用

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

SpeechRecognitionEvent.resultIndex 読取専用

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

SpeechRecognitionEvent.results 読取専用

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

下記のソースコードは Speech color changer の例を参考しています

result イベントは、 addEventListener メソッドで使用することができます。

js
const recognition = new SpeechRecognition();

recognition.addEventListener("result", (event) => {
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `結果を受信しました: ${color}.`;
  bg.style.backgroundColor = color;
});

または onresult イベントハンドラープロパティを使用してください。

js
recognition.onresult = (event) => {
  const color = event.results[0][0].transcript;
  diagnostic.textContent = `結果を受信しました: ${color}.`;
  bg.style.backgroundColor = color;
};

仕様書

Specification
Web Speech API
# eventdef-speechrecognition-result
Web Speech API
# dom-speechrecognition-onresult

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
result event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

関連情報