SpeechSynthesisUtterance: error イベント

errorウェブ音声 APISpeechSynthesisUtterance オブジェクトのイベントで、エラーが発生して正常に発話ができなかったときには発生します。

構文

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

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

onerror = (event) => {};

イベント型

イベントプロパティ

以下に挙げたプロパティに加え、親インターフェイスである Event のプロパティが利用可能です。

charIndex 読取専用

イベントが発生したときに発話されていた SpeechSynthesisUtterance.text 内の文字のインデックス位置を返します。

elapsedTime 読取専用

イベントが発生した時点の SpeechSynthesisUtterance.text が話し始めてからの経過時間(秒)を返します。

error 読取専用

音声合成に失敗した原因を示すエラーコードを返します。

name 読取専用

SpeechSynthesisUtterance.text が発話される際に発生する特定の種類のイベントに関連する名前を返します。 mark イベントの場合は到達した SSML マーカーの名前、 boundary イベントの場合は到達した境界の種類です。

utterance 読取専用

イベントが発生した SpeechSynthesisUtterance インスタンスを返します。

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

js
utterThis.addEventListener("error", (event) => {
  console.log(
    `An error has occurred with the speech synthesis: ${event.error}`,
  );
});

または onerror イベントハンドラープロパティで使用することができます。

js
utterThis.onerror = (event) => {
  console.log(
    `An error has occurred with the speech synthesis: ${event.error}`,
  );
};

仕様書

Specification
Web Speech API
# eventdef-speechsynthesisutterance-error
Web Speech API
# dom-speechsynthesisutterance-onerror

ブラウザーの互換性

BCD tables only load in the browser

関連情報