项目上需要使用语音播报服务,内网使用只需要几行代码
<!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>Document</title>
</head>
<body>
<button onclick="init()">转</button>
</body>
<script>
function init() {
var utterThis = new window.SpeechSynthesisUtterance();
utterThis.lang = 'zh-CN';
utterThis.volume = 1;
utterThis.rate = 1;
utterThis.pitch = 1;
utterThis.text = '矿工,请赶紧撤离该区域';
// SpeechSynthesisUtterance.lang 获取并设置话语的语言
// SpeechSynthesisUtterance.pitch 获取并设置话语的音调(值越大越尖锐, 越低越低沉)
// SpeechSynthesisUtterance.rate 获取并设置说话的速度(值越大语速越快, 越小语速越慢)
// SpeechSynthesisUtterance.text 获取并设置说话时的文本
// SpeechSynthesisUtterance.voice 获取并设置说话的声音 目前
// SpeechSynthesisUtterance.volume 获取并设置说话的音量
window.speechSynthesis.speak(utterThis); //这样就会有个美女姐姐语音朗读 张三,扫码成功!
}
</script>
</html>