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

浏览器兼容性

另见