语音合成API支持铬吗?我需要安装声音吗?如果是这样的话,我怎么能做到呢?我在用费多拉。像视频这样的声音,我需要安装额外的软件包才能工作吗?
我试过这段代码:
var msg = new SpeechSynthesisUtterance('I see dead people!');
msg.voice = speechSynthesis.getVoices().filter(function(voice) {
return voice.name == 'Whisper';
})[0];
speechSynthesis.speak(msg);
来自聊天的Web应用程序-语音合成API简介的文章
但是函数speechSynthesis.getVoices()返回空数组。
我也试过:
window.speechSynthesis.onvoiceschanged = function() {
console.log(window.speechSynthesis.getVoices())
};
函数被执行,但是数组也是空的。
在https://fedoraproject.org/wiki/Chromium上有使用--enable-speech-dispatcher
标志的信息,但是当我使用它时,我得到了不支持标记的警告。
发布于 2018-01-10 05:04:31
语音合成API支持铬吗?
是的,Web语音API在Chromium上有基本的支持,尽管该规范的Chromium和Firefox实现都存在一些问题,参见Blink>Speech、Internals>SpeechSynthesis、网络语音。
我需要安装声音吗?如果是这样的话,我怎么能做到呢?我在用费多拉。像视频这样的声音,我需要安装额外的软件包才能工作吗?
是的,需要安装声音。默认情况下,SpeechSynthesisUtterance
voice
属性中没有设置声音,参见如何在铬上使用Web语音API?;如何从window.speechSynthesis.speak()调用中捕获生成的音频?。
您可以将speech-dispatcher
安装为系统语音合成服务器的服务器,将espeak
安装为语音合成器。
$ yum install speech-dispatcher espeak
您还可以在用户主文件夹中为speech-dispatcher
设置一个配置文件,以便为您使用的speech-dispatcher
和输出模块(例如espeak
)设置特定选项。
$ spd-conf -u
使用--enable-speech-dispatcher
标志启动铬会自动生成到speech-dispatcher
的连接,在该连接中,可以在0
和5
之间设置LogLevel
,以检查Chromium与speech-dispatcher
之间的SSIP通信。
.getVoices()
异步返回结果,需要调用两次
请参阅electron
在GitHub 语音合成:无声音#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);
})();
https://stackoverflow.com/questions/46863170
复制相似问题