<style>
.ceshi{}
.ceshi ul{
width: 60%;
margin: 0 auto;
}
.ceshi ul li{
width: 20%;
display: inline-block;
}
</style>
<div class="ceshi">
<ul> <li>按时吃空</li><li>的SV放</li><li>分隔符</li><li>投入和</li><li>跟你讲</li></ul>
</div>
<script>
var musiText = '';
// $(document).mouseenter(function(e){
// musiText = e.target.innerText
// console.log(musiText)
// handleSpeak(musiText)
// });
$('.ceshi ul li').mouseenter(function(e){
musiText = e.target.innerText
console.log(musiText)
handleSpeak(musiText)
});
const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();
// 语音播报的函数
function handleSpeak(text) {
msg.text = text;
msg.lang = "zh-CN"; // 使用的语言:中文
msg.volume = 1; // 音量:1
msg.rate = 2; // 语速:1
msg.pitch = 0; // 音高:1
synth.speak(msg); // 播放
}
// 语音停止
function handleStop(e) {
msg.text = e;
msg.lang = "zh-CN";
synth.cancel(msg);
}
</script>
js浏览器 文本语音播报
于 2022-05-10 15:08:51 首次发布