SpeechSynthesisUtterance可以实现:
if ('speechSynthesis' in window) {
// 创建语音合成对象
var utterThis = new SpeechSynthesisUtterance('你好,世界!');
utterThis.pitch = 1;
utterThis.rate = 1;
utterThis.volume = 1;
// 开始朗读
speechSynthesis.speak(utterThis);
// 监听事件
utterThis.addEventListener('start', function(event) {
console.log('开始朗读');
});
utterThis.addEventListener('end', function(event) {
console.log('朗读结束');
});
utterThis.addEventListener('error', function(event) {
console.error('朗读出错');
});
} else {
console.error('浏览器不支持speechSynthesis');
} 网友回复


