SpeechSynthesisErrorEvent

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2018.

Die Schnittstelle SpeechSynthesisErrorEvent der Web Speech API enthält Informationen über Fehler, die bei der Verarbeitung von SpeechSynthesisUtterance-Objekten im Sprachdienst auftreten.

Event SpeechSynthesisEvent SpeechSynthesisErrorEvent

Konstruktor

SpeechSynthesisErrorEvent()

Erstellt ein neues SpeechSynthesisErrorEvent.

Instanz-Eigenschaften

SpeechSynthesisErrorEvent erweitert die Schnittstelle SpeechSynthesisEvent, welche Eigenschaften von ihrer übergeordneten Schnittstelle Event erbt.

SpeechSynthesisErrorEvent.error Schreibgeschützt

Gibt einen Fehlercode zurück, der angibt, was bei einem Sprachsyntheseversuch schiefgegangen ist.

Instanz-Methoden

SpeechSynthesisErrorEvent erweitert die Schnittstelle SpeechSynthesisEvent, welche Methoden von ihrer übergeordneten Schnittstelle Event erbt.

Beispiele

js
const synth = window.speechSynthesis;

const inputForm = document.querySelector("form");
const inputTxt = document.querySelector("input");
const voiceSelect = document.querySelector("select");

const voices = synth.getVoices();

// …

inputForm.onsubmit = (event) => {
  event.preventDefault();

  const utterThis = new SpeechSynthesisUtterance(inputTxt.value);
  const selectedOption =
    voiceSelect.selectedOptions[0].getAttribute("data-name");
  for (let i = 0; i < voices.length; i++) {
    if (voices[i].name === selectedOption) {
      utterThis.voice = voices[i];
    }
  }

  synth.speak(utterThis);

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

  inputTxt.blur();
};

Spezifikationen

Specification
Web Speech API
# speechsynthesiserrorevent

Browser-Kompatibilität

Siehe auch