js语音播报功能(1)
生活随笔
收集整理的這篇文章主要介紹了
js语音播报功能(1)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Document</title>
</head>
<body>
<button onclick="speak();">在線聽故事</button>
<button onclick="zhanting();">暫停</button>
<button onclick="stop();">停止</button>
<button onclick="comon();">繼續</button>
<div id="txt" style="visibility:hidden; "></div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script><script>// \//播放
// window.speechSynthesis.speak();
// //暫停
// window.speechSynthesis.pause();
// //繼續
// window.speechSynthesis.resume();
// //停止
// window.speechSynthesis.cancel();
// zhanting stop comon speak
// var mess = $("#txt").text()function zhanting(mess) {// body...window.speechSynthesis.pause(mess);
}
function stop(mess) {// body...window.speechSynthesis.cancel(mess);
}
function comon(mess) {// body...window.speechSynthesis.resume(mess);
}function speak(mess) {var mess = $("#txt").text()var msg = new SpeechSynthesisUtterance(mess)msg.volume = 100 // 聲音的音量msg.rate = 1 // 語速,數值,默認值是1,范圍是0.1到10msg.pitch = 1.5 // 表示說話的音高,數值,范圍從0(最小)到2(最大)。默認值為1speechSynthesis.speak(msg);}
</script></body>
</html>
總結
以上是生活随笔為你收集整理的js语音播报功能(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab调幅举例,基于MATLAB的
- 下一篇: TP6中db操作数据库的方式(方法)和O