<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<button οnclick='playRadio()' id="played">播报语音</button>
<button οnclick='pauseRadio()' id="pasued">暂停</button>
<button οnclick='resumeRadio()' id="resumed">重新播报</button>
<button οnclick='stopRadio()' id="stoped">停止</button>
<div>语言伯伯</div>
<script>
// 播报语音
function playRadio() {
let useVoiceText = '你有一个新的待处理订单'
let to_speak = new SpeechSynthesisUtterance(useVoiceText);
window.speechSynthesis.speak(to_speak)
}
// 暂停
function pauseRadio() {
window.speechSynthesis.pause();
}
// 重新播报
function resumeRadio() {
window.speechSynthesis.resume();
}
// 停止
function stopRadio() {
window.speechSynthesis.cancel();
}
</script>
</body>
</html>
前端文字转语言播报
最新推荐文章于 2024-05-30 15:07:12 发布