• 百度语音合成播放


    var audio = document.getElementById("myAudio");
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(!(isIE||isEdge||isIE11)){//非ie浏览器
    audio.addEventListener('playing', function () {
    $(':button').attr("disabled",true);
    }, false);

    audio.addEventListener('ended', function () {
    $(':button').attr("disabled",false);
    }, false);
    }


    function broadCast(token, zhText) {
    //判断浏览器
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE||isEdge||isIE11) {
    //ie浏览器
    var voice=document.createElement("bgsound");
    document.body.appendChild(voice);
    var audioSrc = "http://tsn.baidu.com/text2audio?lan=zh&cuid=123&ctp=1&spd=3&tex=" + zhText + ""&tok=" + token;
    voice.src=audioSrc;
    } else{
    //不是ie浏览器
    if (audio.paused) { //已经播放完毕
    var audioSrc = "http://tsn.baidu.com/text2audio?lan=zh&cuid=123&ctp=1&spd=3&tex=" + zhText + ""&tok=" + token;
    console.log("--audio:"+audio);
    console.log("--audioSrc:"+audioSrc);
    console.log("--audioSrc type:"+ typeof audioSrc);
    // audio.type='audio/mpeg';
    // source.src="http://tsn.baidu.com/text2audio?lan=zh&cuid=123&ctp=1&spd=3&tex=hello&tok=24.70b121c60ff4553de615166eb3d8e737.2592000.1553950115.282335-9969555";
    audio.src = audioSrc;
    audio.play();
    } else {
    sleepBroadCast(token, zhText, 1000);
    }
    }
  • 相关阅读:
    生成函数学习笔记
    CF1437F Emotional Fishermen
    BZOJ 1443 [JSOI2009]游戏Game
    BZOJ 1018 [SHOI2008]堵塞的交通traffic
    访问量破1000之记录
    BZOJ 1022 [SHOI2008]小约翰的游戏John
    BZOJ1457 棋盘游戏
    BZOJ1874: [BeiJing2009 WinterCamp]取石子游戏
    BZOJ 1188 [HNOI2007]分裂游戏
    Codeforces Round #345 (Div. 2)
  • 原文地址:https://www.cnblogs.com/liangmm/p/11677526.html
Copyright © 2020-2023  润新知