简体   繁体   English

Javascript/Html 语音合成不起作用

[英]Javascript/Html speechSynthesis doesn't work

I tried this in Chrome,Edge and Firefox but it doesn't work.我在 Chrome、Edge 和 Firefox 中试过这个,但它不起作用。

const text = document.getElementById("text");
const speed = document.getElementById("speed");
function play() {
var utterance = new SpeechSynthesisUtterance();
utterance.text = text.value;
utterance.rate = speed.value || 1;
utterance.pitch = 1;
utterance.volume = 1;
speechSynthesis.speak(utterance);
}

I don't know what you're trying to assign speed, but it works like this.我不知道您要分配什么速度,但它的工作原理是这样的。

 const text = document.getElementById("text"); document.getElementById("button").addEventListener("click", play) function play() { var utterance = new SpeechSynthesisUtterance(); utterance.text = text.value; utterance.pitch = 1; utterance.volume = 1; speechSynthesis.speak(utterance); }
 <input type="text" id="text" value= "hello"> <button id="button">click me</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM