SpeechSynthesisVoice:voiceURI 属性

Baseline 已广泛支持

此功能已成熟,并可在多种设备和浏览器版本上使用。自 2018 年 9 月以来,它已在各种浏览器中推出。

SpeechSynthesisVoice 接口的 voiceURI 只读属性返回此语音的语音合成服务的 URI 类型和位置。

一个表示语音 URI 的字符串。这是一个通用 URI,可以指向本地或远程服务,例如,它可能是专有系统 URN 或远程服务的 URL。

示例

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

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

  console.log(voice.voiceURI);
  // On Mac, this returns URNs, for example 'urn:moz-tts:osx:com.apple.speech.synthesis.voice.daniel'

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

规范

规范
Web Speech API
# dom-speechsynthesisvoice-voiceuri

浏览器兼容性

另见