files/en-us/web/api/speechsynthesiserrorevent/error/index.md
{{APIRef("Web Speech API")}}
The error property of the
{{domxref("SpeechSynthesisErrorEvent")}} interface returns an error code indicating what has gone wrong with a speech synthesis attempt.
A string containing the error reason. Possible values are:
canceled
interrupted
audio-busy
audio-hardware
network
synthesis-unavailable
synthesis-failed
language-unavailable
window.speechSynthesis.getVoices() method to determine which voices and languages are supported in the user's browser.voice-unavailable
text-too-long
invalid-argument
not-allowed
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 (const voice of voices) {
if (voice.name === selectedOption) {
utterThis.voice = voice;
}
}
synth.speak(utterThis);
utterThis.onerror = (event) => {
console.error(
`An error has occurred with the speech synthesis: ${event.error}`,
);
};
inputTxt.blur();
};
{{Specifications}}
{{Compat}}