首页 > 技术文章 > 使用代码让浏览器说话

suntongxue 2020-06-23 17:44 原文

speak(sentence) {

   const utterance = 

new SpeechSynthesisUtterance(sentence)

      window.speechSynthesis.speak(utterance)

        }

speak(“hello”)

 

 

* @param sentence:要说的句子

* @param pitch: 音调,取值范围(0 - 2) 默认值:1

* @param rate: 语速,取值范围(0.1 - 10) 默认值:1

* @param volume: 音量,取值范围(0 - 1) 默认值:0.5 

 

function speak(sentence, pitch, ratevolume) {

const utterance = new SpeechSynthesisUtterance(sentence) utterance.rate = rate

utterance.pitch = pitch

utterance.volume = volume

window.speechSynthesis.speak(utterance)

}

推荐阅读