javascript - web speech api语音合成-获取语音列表

标签 javascript google-chrome webkit speech-recognition text-to-speech

我在使用网络语音 API 时遇到了一个奇怪的问题。我已经设置了一些代码来说出一串文本——很少,它会用正常的声音说出来(Mac OS X 中听写和语音设置中的“Alex”)。但通常情况下,它会用“Albert”的声音说话。

我正在查看此处列出的 w3c 网络语音 API:

https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html#dfn-ttsgetvoices

还有一个接口(interface)叫做

SpeechSynthesisVoiceList{}

我正在尝试访问此功能,但我不能。

我如何访问此语音列表?我正在使用 chrome canary,我已经尝试了很多方法来做到这一点。我期望的工作是:

var u = new SpeechSynthesisUtterance();
  console.log(u.getVoices());

var u = new SpeechSynthesisVoiceList();
  console.log(u);

我也跑过:

console.log(window)

我看到很多关于网络语音 API 和语音合成的东西,但没有看到关于语音的东西。

最佳答案

您应该使用 speechSynthesis.getVoices() 来获取所有声音的列表。这是 Google Chrome 33 的输出:

[{
    "default": true,
    "localService": false,
    "lang": "en-US",
    "name": "Google US English",
    "voiceURI": "Google US English"
}, {
    "default": false,
    "localService": false,
    "lang": "en-GB",
    "name": "Google UK English Male",
    "voiceURI": "Google UK English Male"
}, {
    "default": false,
    "localService": false,
    "lang": "en-GB",
    "name": "Google UK English Female",
    "voiceURI": "Google UK English Female"
}, {
    "default": false,
    "localService": false,
    "lang": "es-ES",
    "name": "Google Español",
    "voiceURI": "Google Español"
}, {
    "default": false,
    "localService": false,
    "lang": "fr-FR",
    "name": "Google Français",
    "voiceURI": "Google Français"
}, {
    "default": false,
    "localService": false,
    "lang": "it-IT",
    "name": "Google Italiano",
    "voiceURI": "Google Italiano"
}, {
    "default": false,
    "localService": false,
    "lang": "de-DE",
    "name": "Google Deutsch",
    "voiceURI": "Google Deutsch"
}, {
    "default": false,
    "localService": false,
    "lang": "ja-JP",
    "name": "Google 日本人",
    "voiceURI": "Google 日本人"
}, {
    "default": false,
    "localService": false,
    "lang": "ko-KR",
    "name": "Google 한국의",
    "voiceURI": "Google 한국의"
}, {
    "default": false,
    "localService": false,
    "lang": "zh-CN",
    "name": "Google 中国的",
    "voiceURI": "Google 中国的"
}, {
    "default": false,
    "localService": true,
    "lang": "",
    "name": "native",
    "voiceURI": "native"
}]

关于javascript - web speech api语音合成-获取语音列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17224540/

相关文章:

iphone - 使用 WebKit 重现 Springboard 的图标闪耀

javascript - 如何在javascript中将字符串转换为对象的字段名称

javascript - 仅在 Chrome 中未捕获的类型错误

html - 在后代元素上设置 margin-top 时 'body' 元素顶部的 Webkit 额外空间

swift - 单元测试 WKNavigationDelegate 函数 swift

css - 在 Safari 8 和 Chrome 43 上跳跃、起伏的变换转换

javascript - 输入键在 froala 编辑器上不起作用

php - 将 php 值解析为 javascript Uncaught ReferenceError

javascript - Socket.IO初始数据包

java - 防止 GWT Tree 关闭选定节点的分支