在网页端实现将指定的文字进行语音合成并进行播报。
使用HTML5的Speech Synthesis API就能实现简单的语音合成效果。
<input id="btn1" type="button" value="点我" onclick="test();" />
<script>
function test() {
const sos = `阿尤!不错哦`;
const synth = window.speechSynthesis;
let msg = new SpeechSynthesisUtterance(sos);
synth.speak(msg)
}
</script>
然后点击按钮,就会触发test方法的执行实现语音合成
这里推荐使用Chrome浏览器,因为HTML5的支持度不同