Chromium 支持语音合成 API 吗?
是的网络语音API https://w3c.github.io/speech-api/speechapi.html在 Chromium 浏览器上有基本支持,尽管 Chromium 和 Firefox 规范的实现都存在一些问题,请参阅眨眼>语音 https://bugs.chromium.org/p/chromium/issues/list?q=component:Blink%3ESpeech, 内部>语音合成 https://bugs.chromium.org/p/chromium/issues/list?q=component:Internals%3ESpeechSynthesis, 网络语音 https://bugzilla.mozilla.org/buglist.cgi?quicksearch=Web%20Speech.
我需要安装语音吗?如果是这样我该怎么做?我在用着
软呢帽。声音像视频一样需要安装额外的软件包吗
它能工作吗?
是的,需要安装语音。 Chromium 不附带可设置的声音SpeechSynthesisUtterance
voice
默认属性,参见如何在 chromium 上使用 Web Speech API? https://stackoverflow.com/questions/44013933/how-to-use-web-speech-api-at-chromium; 如何捕获 window.speechSynthesis.speak() 调用生成的音频? https://stackoverflow.com/questions/45003548/how-to-capture-generated-audio-from-window-speechsynthesis-speak-call.
您可以安装speech-dispatcher https://devel.freebsoft.org/doc/speechd/speech-dispatcher.html作为系统语音合成服务器的服务器和espeak http://espeak.sourceforge.net/作为语音合成器。
$ yum install speech-dispatcher espeak
您还可以设置一个配置文件speech-dispatcher
在用户主文件夹中为两者设置特定选项speech-dispatcher
以及您使用的输出模块,例如espeak
$ spd-conf -u
启动 Chromium--enable-speech-dispatcher
标志自动生成一个连接speech-dispatcher
,您可以在其中设置LogLevel
之间0
and 5
查看 Chromium 代码和之间的 SSIP 通信speech-dispatcher
.
.getVoices()
异步返回结果,需要调用两次
看到这个electron
GitHub 上的问题语音合成:无声音 #586 https://github.com/electron/electron/issues/586.
window.speechSynthesis.onvoiceschanged = e => {
const voices = window.speechSynthesis.getVoices();
// do speech synthesis stuff
console.log(voices);
}
window.speechSynthesis.getVoices();
或组成一个异步函数,返回一个Promise
值为声音数组
(async() => {
const getVoices = (voiceName = "") => {
return new Promise(resolve => {
window.speechSynthesis.onvoiceschanged = e => {
// optionally filter returned voice by `voiceName`
// resolve(
// window.speechSynthesis.getVoices()
// .filter(({name}) => /^en.+whisper/.test(name))
// );
resolve(window.speechSynthesis.getVoices());
}
window.speechSynthesis.getVoices();
})
}
const voices = await getVoices();
console.log(voices);
})();