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.

Giao diện SpeechSynthesisErrorEvent của Web Speech API chứa thông tin về bất kỳ lỗi nào xảy ra trong khi xử lý các đối tượng SpeechSynthesisUtterance trong dịch vụ giọng nói.

Event SpeechSynthesisEvent SpeechSynthesisErrorEvent

Hàm khởi tạo

SpeechSynthesisErrorEvent()

Tạo một SpeechSynthesisErrorEvent mới.

Thuộc tính phiên bản

SpeechSynthesisErrorEvent mở rộng giao diện SpeechSynthesisEvent, kế thừa các thuộc tính từ giao diện cha của nó, Event.

SpeechSynthesisErrorEvent.error Read only

Trả về mã lỗi cho biết điều gì đã xảy ra không ổn với một lần thử tổng hợp giọng nói.

Phương thức phiên bản

SpeechSynthesisErrorEvent mở rộng giao diện SpeechSynthesisEvent, kế thừa các phương thức từ giao diện cha của nó, Event.

Ví dụ

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(`Đã xảy ra lỗi với tổng hợp giọng nói: ${event.error}`);
  };

  inputTxt.blur();
};

Thông số kỹ thuật

Specification
Web Speech API
# speechsynthesiserrorevent

Tương thích trình duyệt

Xem thêm