谷歌浏览器语音播报方法(后续考虑兼容性问题)

213 阅读1分钟
Css:
 
      <button type="button" onClick={() => speak('你好')}>说话</button>
 
js:
 
 const speak = (s: any) => {
        // 生成需要语音朗读的内容
        const utterance = new SpeechSynthesisUtterance(s)
        // 由浏览器发起语音朗读的请求
        window.speechSynthesis.speak(utterance)
    }