SpeechSynthesisVoice: thuộc tính lang

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 lang của giao diện SpeechSynthesisVoice trả về một BCP 47 language tag cho biết ngôn ngữ của giọng nói.

Giá trị

Một chuỗi đại diện cho ngôn ngữ của thiết bị.

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-lang

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

Xem thêm