window.speechSynthesis 使用

// 创建语音合成对象
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 
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值