SpeechRecognition: result イベント
result はウェブ音声 API のイベントで、音声認識サービスが結果を返したとき、つまり単語やフレーズが正の値で認識され、それがアプリに伝達されたときに発行されます。
構文
このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener('result', (event) => { })
onresult = (event) => { }
イベント型
SpeechRecognitionEvent です。 Event を継承しています。
イベントプロパティ
以下に列挙したプロパティに加えて、親インターフェイスである Event から継承したプロパティも利用できます。
SpeechRecognitionEvent.emma読取専用-
結果の EMMA (Extensible MultiModal Annotation markup language) - XML - 表現を返します。
SpeechRecognitionEvent.interpretation読取専用-
ユーザーが言ったことの意味づけを返します。
SpeechRecognitionEvent.resultIndex読取専用-
実際に変更された
SpeechRecognitionResultList(en-US) 「配列」の中で最もインデックス値の小さい結果を返します。 SpeechRecognitionEvent.results読取専用-
現在のセッションのすべての音声認識結果を表す
SpeechRecognitionResultList(en-US) オブジェクトを返します。
例
下記のソースコードは 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 |
ブラウザーの互換性
BCD tables only load in the browser