SpeechSynthesisUtterance: error event
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2018.
Sự kiện error của đối tượng SpeechSynthesisUtterance thuộc Web Speech API được kích hoạt khi xảy ra lỗi ngăn yêu cầu phát âm được nói thành công.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt thuộc tính trình xử lý sự kiện.
addEventListener("error", (event) => { })
onerror = (event) => { }
Kiểu sự kiện
Một SpeechSynthesisErrorEvent. Kế thừa từ SpeechSynthesisEvent và Event.
Thuộc tính sự kiện
Ngoài các thuộc tính được liệt kê bên dưới, các thuộc tính từ giao diện cha Event cũng có sẵn.
charIndexRead only-
Trả về vị trí chỉ mục của ký tự trong
SpeechSynthesisUtterance.textđang được nói khi sự kiện được kích hoạt. elapsedTimeRead only-
Trả về thời gian đã trôi qua tính bằng giây sau khi
SpeechSynthesisUtterance.textbắt đầu được nói tại thời điểm sự kiện được kích hoạt. errorRead only-
Trả về mã lỗi cho biết điều gì đã xảy ra với lần thử tổng hợp giọng nói.
nameRead only-
Trả về tên được liên kết với một số loại sự kiện xảy ra khi
SpeechSynthesisUtterance.textđang được nói: tên của marker SSML đạt đến trong trường hợp sự kiệnmark, hoặc loại ranh giới đạt đến trong trường hợp sự kiệnboundary. utteranceRead only-
Trả về đối tượng
SpeechSynthesisUtterancemà sự kiện được kích hoạt trên đó.
Ví dụ
Bạn có thể sử dụng sự kiện error trong phương thức addEventListener:
utterThis.addEventListener("error", (event) => {
console.log(
`An error has occurred with the speech synthesis: ${event.error}`,
);
});
Hoặc sử dụng thuộc tính trình xử lý sự kiện onerror:
utterThis.onerror = (event) => {
console.log(
`An error has occurred with the speech synthesis: ${event.error}`,
);
};
Thông số kỹ thuật
| Specification |
|---|
| Web Speech API> # eventdef-speechsynthesisutterance-error> |
| Web Speech API> # dom-speechsynthesisutterance-onerror> |