SpeechSynthesisVoice: thuộc tính default

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.

Thuộc tính chỉ đọc default của giao diện SpeechSynthesisVoice trả về một giá trị boolean cho biết liệu giọng nói có phải là giọng nói mặc định cho ứng dụng hiện tại (true) hay không (false).

Note: Đối với một số thiết bị, đây có thể là giọng nói mặc định cho ngôn ngữ của giọng nói. Thông số kỹ thuật không rõ ràng về điều đó nên một số triển khai có thể khác nhau.

Giá trị

Một giá trị boolean.

Ví dụ

js
for (const voice of voices) {
  const option = document.createElement("option");
  option.textContent = `${voice.name} (${voice.lang})`;

  if (voice.default) {
    option.textContent += " — DEFAULT";
  }

  option.setAttribute("data-lang", voice.lang);
  option.setAttribute("data-name", voice.name);
  voiceSelect.appendChild(option);
}

Thông số kỹ thuật

Specification
Web Speech API
# dom-speechsynthesisvoice-default

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

Xem thêm