赞
踩
使用HTML5的Speech Synthesis API能简单实现语音合成,并进行播报,实现代码如下:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>网页实现文字转语音朗读功能</title>
- </head>
- <body>
- <button onclick="play()">朗读</button>
- <script>
- var utterThis = new SpeechSynthesisUtterance();
- utterThis.text = "hello word";
- utterThis.volume = 1; // 声音的音量 范围是0到1
- utterThis.rate = 0.7; //语速,数值,默认值是1,范围是0.1到10
- mutterThisg.pitch = 0; // 音高,数值,范围从0(最小)到2(最大)。默认值为1
- function play() {
- speechSynthesis.speak(utterThis);
- }
- </script>
- </body>
- </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。