【问题标题】:Firefox and Speech Synthesis APIFirefox 和语音合成 API
【发布时间】:2014-03-06 17:32:14
【问题描述】:

我正在创建 HTML5 语音合成应用程序,如下链接所示。

http://updates.html5rocks.com/2014/01/Web-apps-that-talk---Introduction-to-the-Speech-Synthesis-API

Windows7 和 Android Chrome33beta 或 Mac 的 safari 运行良好。

但 Windows7-Firefox 27 似乎支持 Speech-Synthesis-API,但由于返回空语音列表而无法正常工作。

有什么解决办法吗?

【问题讨论】:

  • 有一个名为media.webspeech.synth.enabledabout:config 标志可以在Firefox 中启用speechSynthesis。问题依然存在,speechSynthesis.getVoices().length===0

标签: html firefox text-to-speech


【解决方案1】:

检查您的浏览器是否支持语音合成 API
http://caniuse.com/#feat=speech-synthesis

你可以用modernizr检查一下
http://v3.modernizr.com/download/#-speechsynthesis

如果浏览器不支持,可以使用meSpek.js
http://www.masswerk.at/mespeak/

【讨论】:

  • 我的 Firefox 50 for Linux 说我有 0 个声音 (Fedora 23)。我们是否需要手动下载每个声音?有没有一个标准的存储库? Chrome 55 已经带有 19。
【解决方案2】:

如果您只想在网页上添加一个按钮以大声朗读该页面,请将此代码添加到您的网站:

<script src='https://code.responsivevoice.org/responsivevoice.js'></script>
<script type="text/javascript">
    <!-- //
    var speechpause=0;
    function toggleSpeech(){
      if(speechpause!=1){
        responsiveVoice.pause();
        speechpause=1;
      }else{
        responsiveVoice.resume();
        speechpause=0;
      }
    }
    //-->
</script>
<div style="float:right">
      <input onclick="responsiveVoice.speak($('#some_div_with_content').text(), 'Deutsch Female', {pitch: .7});" type="button" value="? Play" />
      <input onclick="toggleSpeech()" type="button" value="||" />
</div>

这使用 jquery 来获取内容的文本,但这很容易改变。

【讨论】:

    【解决方案3】:

    从第 44 版开始,API 的语音合成部分可在 Firefox 桌面上使用。

    但奇怪的是仍然需要设置标志。 "Browser Compatibility"下:

    可以通过 about:config 中的 media.webspeech.synth.enabled 和 media.webspeech.recognition.enable 标志启用。请注意,目前 Firefox 桌面版中只有语音合成部分可用——语音识别部分将在整理所需的内部权限后很快可用。

    我想知道为什么。 MDN 连some nice working examples 都搞砸了,为什么不默认启用这个功能呢?

    【讨论】:

      【解决方案4】:

      不幸的是,它看起来只有 Firefox OS(也许还有 Firefox for Android,我没有检查过)捆绑并支持语音合成库。

      有一个关于桌面支持的公开bug

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-14
        • 1970-01-01
        • 2014-10-03
        • 1970-01-01
        • 1970-01-01
        • 2021-12-14
        • 1970-01-01
        • 2014-02-26
        相关资源
        最近更新 更多