SpeechSynthesisVoice:lang 屬性

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上使用。自 2018 年 9 月以來,它已在各種瀏覽器中推出。

langSpeechSynthesisVoice 介面的一個只讀屬性,它返回一個 BCP 47 語言標籤,表示語音的語言。

一個字串,表示裝置的語言。

示例

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);
}

規範

規範
Web Speech API
# dom-speechsynthesisvoice-lang

瀏覽器相容性

另見