首页 > 其他 > 详细

vue 页面文字转播放声音

时间:2021-04-06 12:17:55      阅读:21      评论:0      收藏:0      [点我收藏+]

vue 页面文字转播放声音

1、引入这句话

const synth = window.speechSynthesis;
const msg = new SpeechSynthesisUtterance();

2、引入声音的方法

/** 语音播报的函数/
handleSpeak(e){
msg.text = e;
msg.lang = ‘zh-CN‘;
msg.volume = ‘1‘;
msg.rate = 1;
msg.pitch = 1;
synth.speak(msg);
},
/
* 语音停止 */
handleStop(e){
msg.text = e;
msg.lang = ‘zh-CN‘;
synth.cancel(msg);
}

3、需要使用的地方调用

/* 语音播放 */
this.handleSpeak(‘你好,有新的告警信息产生啦‘);

vue 页面文字转播放声音

原文:https://www.cnblogs.com/zhukaixin/p/14620742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!