SpeechRecognition: error イベント
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
error はウェブ音声 API の
SpeechRecognition オブジェクトのイベントで、音声認識のエラーが発生した時に発生します。
構文
このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("error", (event) => {});
onerror = (event) => {};
イベント型
SpeechRecognitionErrorEvent です。 Event を継承しています。
イベントプロパティ
以下に列挙したプロパティに加えて、親インターフェイスである Event から継承したプロパティも利用できます。
SpeechRecognitionErrorEvent.error読取専用-
発生したエラーの種類を示します。
SpeechRecognitionErrorEvent.message読取専用-
エラーの詳細を説明するメッセージを返します。
例
error イベントは、 addEventListener メソッドで使用することができます。
js
const recognition = new webkitSpeechRecognition() || new SpeechRecognition();
recognition.addEventListener("error", (event) => {
console.error(`音声認識エラーが発生しました: ${event.error}`);
});
または onerror イベントハンドラープロパティを使用してください。
js
recognition.onerror = (event) => {
console.error(`音声認識エラーが発生しました: ${event.error}`);
};
仕様書
| Specification |
|---|
| Web Speech API> # eventdef-speechrecognition-error> |
| Web Speech API> # dom-speechrecognition-onerror> |
ブラウザーの互換性
Loading…