代码示例
支持自定义播放文字
// 语音播放
function btnRst_Click(text) {
let synth = window.speechSynthesis;
let utterThis = new SpeechSynthesisUtterance(text);
utterThis.lang = 'zh-CN'; // 设置语言为中文(中国)
utterThis.pitch = 1.2; // 设置声调,取值范围为0-2,默认为1
utterThis.rate = 1.3; // 设置语速,取值范围为0.1-10,默认为1
utterThis.volume = 1; // 设置音量大小为0-1
utterThis.voice = synth.getVoices()[0] // 获取可用语音
synth.speak(utterThis);
}