在 Chromium Fedora 中,speechSynthesis.getVoices() 是空数组

2024-03-28

Chromium 支持语音合成 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 简介 https://developers.google.com/web/updates/2014/01/Web-apps-that-talk-Introduction-to-the-Speech-Synthesis-API

但函数speechSynthesis.getVoices()返回空数组。

我也尝试过:

window.speechSynthesis.onvoiceschanged = function() {
    console.log(window.speechSynthesis.getVoices())
};

函数被执行,但数组也是空的。

On https://fedoraproject.org/wiki/Chromium https://fedoraproject.org/wiki/Chromium有信息可以使用--enable-speech-dispatcher标志,但当我使用它时,我收到警告,表示不支持标志。


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()异步返回结果,需要调用两次

看到这个electronGitHub 上的问题语音合成:无声音 #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);

})();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Chromium Fedora 中,speechSynthesis.getVoices() 是空数组 的相关文章

随机推荐