使用代码让浏览器说话
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, rate,volume) {
const utterance = new SpeechSynthesisUtterance(sentence) utterance.rate = rate
utterance.pitch = pitch
utterance.volume = volume
window.speechSynthesis.speak(utterance)
}