直接上代码
这是html片段 <textarea id="textArea" name="" id="" cols="30" rows="10"></textarea> <div onclick="playVoice()">点击发声</div> 这是js片段 function isIe() { if (!!window.ActiveXObject || "ActiveXObject " in window) { return true } else { return false } } function playVoice() { console.log('点击成功') let msg = document.getElementById('textArea').value; console.log(isIe()) window.speechSynthesis.cancel() if (isIe()) { let voiceObj = new ActiveXObject("Sapi.SpVoice") voiceObj.Rate = -1 voiceObj.Volume = 60 voiceObj.Speak(msg, 1) } else { let speakMsg = new SpeechSynthesisUtterance(msg) speakMsg.rate = 1; speakMsg.pitch = 1.5; window.speechSynthesis.speak(speakMsg) } }没添加样式,点击按钮就能把文本域的内容读出来 |
|
最新喜欢:double... |
沙发#
发布于:2023-07-03 16:45
哇哦,好东西勒,感谢分享
|
|
|