js 离线的语音合成

请问一下离线版的文字转语音怎么搞,科大讯飞和百度的都要钱,想找免费的插件,我用下面这段代码在google里并没有起效果。。。。

    var utterThis = new window.SpeechSynthesisUtterance()
    utterThis.text = "测试测试测试测试";
    window.speechSynthesis.speak(utterThis)
阅读 5.7k
2 个回答
<!doctype html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport"
 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>Document</title>
</head>
<body>
<button onclick="speak();">Press to manually speak</button>
<script>
 function speak() {
    var utterThis = new window.SpeechSynthesisUtterance()
    utterThis.text = "测试测试测试测试";
 window.speechSynthesis.speak(utterThis)
  }
  speak();
</script>
</body>
</html>

你没设置语言,默认是英语的:

utterThis.lang = "zh-CN";
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题