// 创建语音合成对象
var synth = window.speechSynthesis;
// 创建要朗读的文本
var text = "这是一个高级使用示例,展示了更多功能的配置。";
// 创建要朗读的语音
var utterance = new SpeechSynthesisUtterance(text);
// 设置语音的语言
utterance.lang = "zh-CN"; // 语言代码可以根据需要调整
// 设置语速(0.5为正常速度)
utterance.rate = 1; // 可以调整语速
// 设置音调(1为正常音调)
utterance.pitch = 1; // 可以调整音调
// 设置朗读的声音
utterance.voice = synth.getVoices().find(function(voice) {
return voice.name === "Microsoft Hanhan Desktop - Chinese (Simplified)";
});
// 播放语音
synth.speak(utterance);
// 停止播放
synth.speak(utterance);
// 播放完成事件
utterance.addEventListener('end', () => {
// TODO
});
09-07
2067
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)