【问题标题】:Implementing SpeechSynthesisUtterance() TTS via javascript and android Chrome通过 javascript 和 android Chrome 实现 SpeechSynthesisUtterance() TTS
【发布时间】:2020-06-09 16:28:23
【问题描述】:

我正在尝试通过 javascript 调用 SpeechSynthesisUtterance() 以使其在 Android Chrome 下工作(因为我已阅读此特定功能与 Android Chrome 兼容)。所以,我写了一个简短的演示,但我不知道如何将它与 Android Chrome 链接。我调用了窗口函数,但它不起作用。如果这不是一个合适的问题,请通知我,以便将其删除。

<button id="ButtonPlay">TTS demo</button>

<script>
    function WhatToPlay(text) {    
        var msg = new SpeechSynthesisUtterance();    
        msg.text = text;
        window.speechSynthesis.speak(msg);
    }

    $("#ButtonPlay").click(function() {
        WhatToPlay("Hello world");
    });
</script>

【问题讨论】:

    标签: javascript android google-chrome text-to-speech


    【解决方案1】:

    我在 Android Chrome 上测试了这个基本代码,它可以工作,所以如果你的上没有,那么肯定有其他问题,例如设备本身。

    <!DOCTYPE html>
    <button type="button" id="speakBtn">Speak</button>
    
    <script>
      const speak = () => {
        const utter = new SpeechSynthesisUtterance();
        utter.text = "Hello";
        speechSynthesis.cancel();
        speechSynthesis.speak(utter);
      }
      speakBtn.addEventListener('click', speak);
      speechSynthesis.getVoices();
    </script>
    

    【讨论】:

    • 谢谢。非常感谢您的努力和建议。
    猜你喜欢
    • 1970-01-01
    • 2016-03-11
    • 2014-02-04
    • 2014-04-30
    • 2016-12-19
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多