<!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到10
msg.pitch = 1.5 // 表示说话的音高,数值,范围从0(最小)到2(最大)。默认值为1
speechSynthesis.speak(msg);
}
</script>
</body>
</html>
js语音播报功能(1)
最新推荐文章于 2024-09-13 21:38:13 发布