9

我对网络语音 api 有一个奇怪的问题。我已经设置了一些代码来说出一串文本 - 很少会以正常的声音说出它(Mac OS X 中听写和语音设置中的“Alex”)。但通常,它以“Albert”的声音说话。

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

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

并且有一个接口叫做

SpeechSynthesisVoiceList {}

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

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

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

或者

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

我也跑过:

console.log(window)

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

4

1 回答 1

7

您应该使用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"
}]
于 2014-01-08T02:39:52.247 回答