网络语音api语音合成 - 获取语音列表

mhe*_*ers 7 javascript speech-recognition webkit google-chrome text-to-speech

网络语音api我有一个奇怪的问题.我已经设置了一些代码来说出一串文字 - 很少,它用正常的声音说话("Alex"来自Mac OS X中的听写和语音设置).但通常情况下,它的声音是"阿尔伯特".

我正在看这里列出的w3c网络语音api:

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

并且有一个名为的界面

SpeechSynthesisVoiceList {}

我试图访问此功能,但我不能.

我该如何访问此语音列表?我正在使用铬金丝雀,我已经尝试了很多这样做的方法.我期望的工作是:

var u = new SpeechSynthesisUtterance();
  console.log(u.getVoices());
Run Code Online (Sandbox Code Playgroud)

要么

var u = new SpeechSynthesisVoiceList();
  console.log(u);
Run Code Online (Sandbox Code Playgroud)

我也跑:

console.log(window)
Run Code Online (Sandbox Code Playgroud)

我看到很多关于网络语音api和语音合成的事情,但没有关于声音的事情.

niu*_*ech 6

您应该使用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"
}]
Run Code Online (Sandbox Code Playgroud)

  • 根据https://code.google.com/p/chromium/issues/detail?id=340160,这可能无法在页面加载时使用.`setInterval(...,1);`的解决方法可以解决http://aurelio.audero.it/demo/speech-synthesis-api-demo.html中使用的问题. (3认同)