SpeechSynthesisErrorEvent
SpeechSynthesisErrorEvent 介面是 Web Speech API 的一部分,它包含有關在語音服務中處理 SpeechSynthesisUtterance 物件時發生的任何錯誤的詳細資訊。
建構函式
SpeechSynthesisErrorEvent()-
建立一個新的
SpeechSynthesisErrorEvent。
例項屬性
SpeechSynthesisErrorEvent 繼承自 SpeechSynthesisEvent 介面,後者又繼承自其父介面 Event。
SpeechSynthesisErrorEvent.error只讀-
返回一個錯誤程式碼,指示語音合成嘗試中出現的錯誤。
例項方法
SpeechSynthesisErrorEvent 繼承自 SpeechSynthesisEvent 介面,後者繼承自其父介面 Event。
示例
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 (const voice of voices) {
if (voice.name === selectedOption) {
utterThis.voice = voice;
}
}
synth.speak(utterThis);
utterThis.onerror = (event) => {
console.log(
`An error has occurred with the speech synthesis: ${event.error}`,
);
};
inputTxt.blur();
};
規範
| 規範 |
|---|
| Web Speech API # speechsynthesiserrorevent |
瀏覽器相容性
載入中…