js实现语音朗读 发表于 2018-06-18 | 更新于 2023-01-11 js实现语音朗读 文章原文 1234567891011121314151617181920212223242526272829303132<!doctype html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title>测试语音合成</title></head><body><button id='play'>播放</button><button id='stop'>停止</button><script> const speaker = new window.SpeechSynthesisUtterance() // 播放语音 function speak(text) { speaker.text = text window.speechSynthesis.speak(speaker) } // 停止语音 function stop() { window.speechSynthesis.cancel() } document.querySelector('#play').onclick = () => speak('编号是:1234567890123415413512341') document.querySelector('#stop').onclick = stop</script></body></html>