1、JavaScript,js语音播报脚本
第一次打开浏览器不会自动播报,需要手动点击一下播报的页面,使当前页面获取到光标即可
/**
语音播报 * @param str {播报文本}
*/
function speckText(str){
let utterThis = new window.SpeechSynthesisUtterance();
utterThis.text= str; //播放内容
utterThis.pitch = 2;//表示说话的音高,数值,范围从0(最小)到2(最大)。默认值为1
utterThis.rate = 1; //语速,数值,默认值是1,范围是0.1到10
utterThis.volume = 100; // 声音的音量
window.speechSynthesis.speak(utterThis);
// console.log("播放内容:" + str);
}
speckText("有新的订单进来!");