200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 网页实现文字转语音朗读功能

网页实现文字转语音朗读功能

时间:2024-07-24 03:21:37

相关推荐

网页实现文字转语音朗读功能

使用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到1utterThis.rate = 0.7; //语速,数值,默认值是1,范围是0.1到10mutterThisg.pitch = 0; // 音高,数值,范围从0(最小)到2(最大)。默认值为1function play() {speechSynthesis.speak(utterThis);}</script></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。