speechSynthesis.getVoices()是Chromium Fedora中的空数组 [英] speechSynthesis.getVoices() is empty array in Chromium Fedora

查看:631
本文介绍了speechSynthesis.getVoices()是Chromium Fedora中的空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chromium是否支持语音合成API?我需要安装声音吗?如果可以,我该怎么做?我正在使用Fedora。像视频这样的声音是否需要安装额外的程序包才能正常工作?

Is Speech Synthesis API supported by Chromium? Do I need to install voices? If so how can I do that? I'm using Fedora. Is voices like video that I need to install extra package for it to work?

我尝试过以下代码:

var msg = new SpeechSynthesisUtterance('I see dead people!');
msg.voice = speechSynthesis.getVoices().filter(function(voice) {
    return voice.name == 'Whisper';
})[0];
speechSynthesis.speak(msg);

2014/01 / Web-apps-that-talk-Introduction-to-the-Speech-Synthesis-API rel = nofollow noreferrer>说话的Web应用程序-语音合成API简介

from article Web apps that talk - Introduction to the Speech Synthesis API

,但是函数SpeechSynthesis.getVoices()返回空数组。

but the function speechSynthesis.getVoices() return empty array.

我也尝试过:

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

函数已执行,但数组也为空。

the function get executed but the array is also empty.

https://fedoraproject.org/wiki/Chromium 上有要使用的信息-enable-speech-dispatcher 标志,但是当我使用它时,我已经警告不支持该标志。

On https://fedoraproject.org/wiki/Chromium there is info to use --enable-speech-dispatcher flag but when I've use it I've got warning that flag is not supported.

推荐答案


Chromium是否支持语音合成API?

Is Speech Synthesis API supported by Chromium?

是的,尽管 Web Speech API 在Chromium浏览器中具有基本支持Chromium和Firefox规范的实施都存在一些问题,请参见眨眼>语音内部人员> SpeechSynthesis 网络演讲

Yes, the Web Speech API has basic support at Chromium browser, though there are several issues with both Chromium and Firefox implementation of the specification, see see Blink>Speech, Internals>SpeechSynthesis, Web Speech.


我需要安装声音吗?如果可以,我该怎么做?我正在使用
Fedora。像视频这样的声音是否需要我为
安装额外的程序包才能正常工作?

Do I need to install voices? If so how can I do that? I'm using Fedora. Is voices like video that I need to install extra package for it to work?

是的,需要安装声音。默认情况下,Chromium的语音未设置为 SpeechSynthesisUtterance voice 属性,请参见如何在铬上使用Web Speech API?如何从window.speechSynthesis.speak( )致电?

Yes, voices need to be installed. Chromium is not shipped with voices to set at SpeechSynthesisUtterance voice attribute by default, see How to use Web Speech API at chromium?; How to capture generated audio from window.speechSynthesis.speak() call?.

您可以安装 语音发送器 作为系统语音合成服务器的服务器,而 espeak 作为语音合成器。

You can install speech-dispatcher as a server for the system speech synthesis server and espeak as the speech synthesizer.

$ yum install speech-dispatcher espeak

您还可以在用户主文件夹中为语音分派器设置配置文件,以为语音调度程序和您使用的输出模块,例如 espeak

You can also set a configuration file for speech-dispatcher in the user home folder to set specific options for both speech-dispatcher and the output module that your use, for example espeak

$ spd-conf -u

使用<$ c启动铬$ c>-enable-speech-dispatcher 标志会自动生成与 speech-dispatcher 的连接,您可以在其中设置 LogLevel 0 5 之间,以查看Chromium代码和<$ c之间的SSIP通信$ c>语音分派器。

Launching Chromium with --enable-speech-dispatcher flag automatically spawns a connection to speech-dispatcher, where you can set the LogLevel between 0 and 5 to review SSIP communication between Chromium code and speech-dispatcher.

.getVoices()异步返回结果,需要被调用两次

.getVoices() returns results asynchronously and needs to be called twice

请参见GitHub electron 问题。 com / electron / electron / issues / 586 rel = nofollow noreferrer>语音合成:无声音#5 86 。

see this electron issue at GitHub Speech Synthesis: No Voices #586.

window.speechSynthesis.onvoiceschanged = e => {
  const voices = window.speechSynthesis.getVoices();
  // do speech synthesis stuff
  console.log(voices);
}
window.speechSynthesis.getVoices();

或由异步函数组成,该函数返回 Promise 值是语音数组

or composed as an asynchronous function which returns a Promise with value being array of voices

(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);

})();

这篇关于speechSynthesis.getVoices()是Chromium Fedora中的空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆