JS调用google DEMO朗读

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <script src="js/jquery-1.8.3.js"></script>
    <title>中文测试</title>
</head>
<body>
<button id="a">开始</button>
<button id="b">暂停</button>
<button id="c">继续</button>
<button id="d">停止</button>
</body>
</html>
<script>
    var synth = window.speechSynthesis
    var u = new SpeechSynthesisUtterance();
    //汉语
    u.lang = 'zh-CN';
    u.rate = 1;
    function speak(textToSpeak) {
        u.text = textToSpeak;
        synth.speak(u)
    }
    var str = "众所周知,古诗中有好多字音与我们现代的音有所不同,如果是细心研究过过学习过还好,但有时遇到模棱两可的字音,真的不知道读什么好,读起来也没有底气"
    speak(str)
    $("#a").click(function() {
        speak(str)
    })
    $("#b").click(function() {
        synth.pause()
    })
    $("#c").click(function() {
        synth.resume()
    })
    $("#d").click(function() {
        synth.cancel();
    })
    // var synth = window.speechSynthesis;
    // var utterance1 = new SpeechSynthesisUtterance('How about we say this now? This is quite a long sentence to say.');
    // var utterance2 = new SpeechSynthesisUtterance('We should say another sentence too, just to be on the safe side.');
    // synth.speak(utterance1);
    // synth.speak(utterance2);
    // synth.pause(); // pauses utterances being spoken
    //https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis/cancel
</script>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值