文字转语音

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>文字转语音</title>
</head>
<body>
<button id="play">播放</button>
<script type="text/javascript">
var text = '从删库到跑路';

if (window.speechSynthesis) {
    play.onclick = function () {
        var ssu = new SpeechSynthesisUtterance();
        ssu.text = text; // 文本内容
        ssu.volume = 1;  // 音量,范围:0-1
        ssu.rate = 1;    // 播放语速,范围:0.1-10
        speechSynthesis.speak(ssu);
    };
} else {
    alert('当前浏览器不支持文字转语音');
}
</script>
</body>
</html>

Copyright © 2024 码农人生. All Rights Reserved