LiJun
2018-10-29 42acb64952c98e07a0b10bbc9bee4fefb8a72a79
发声对象添加
1个文件已添加
1个文件已修改
88 ■■■■ 已修改文件
gx_tieta/WebRoot/Test.jsp 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gx_tieta/WebRoot/js/VoiceUtil.js 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gx_tieta/WebRoot/Test.jsp
@@ -20,10 +20,8 @@
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
     <link rel="stylesheet" type="text/css" href="css/basic.css" />
    <script type="text/javascript" src="js/frame.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="js/base.js"></script>
    <script type="text/javascript" src="js/buildNav.js"></script>
     </head>    
     <body>
    <!-- <form action="MyFileAction!UploadTestFile" method="post" enctype="multipart/form-data" id="up-form1">
@@ -38,7 +36,7 @@
        <img alt="" id="im" src="">
    </form>
 </body>
    <script type="text/javascript" src="js/VoiceUtil.js"></script>
    <script type="text/javascript">    
    var permits;
    <%    Object obj=session.getAttribute("permits");
@@ -49,43 +47,9 @@
    <%    }    %>
    
    
    var param = {
        dev_id:910000001,
        record_datetime:'2018-01-01 00:00:00',
        record_datetime_end:'2018-03-30 23:59:59',
        station_event_type:0,                                //1:基站停电        2:基站续航    3:基站发电        4:基站开门    5:基站掉站    6:基站温度上限   7:基站温度下限    8:基站湿度上限    9:基站湿度下限
        page:{
            pageSize:10,             //每页的行数
            pageCurr:1                //当前页码数
        }
    };
    searchStationHistRecord(param);
    //查询基站详情
    function searchStationHistRecord(param){
        // 请求获取当前省下的市
        $.ajax({
            type: "post",
            url: "Bts_station_eventAction!serchByInfo",
            async:true,
            dataType:'json',
            data:"json = "+JSON.stringify(param),
            success: function(data){
                var rs = JSON.parse(data.result);
                console.info(rs);
                if(rs.code == 1) {
                }else {
                }
            }
        });
    }
    setTimeout(function() {
        voice.play("这是我第一次做语音播报在  2018-01-01 01:56:23");
    },2000);
    
    //上传logo
    $('#up-file1').click(function(){
gx_tieta/WebRoot/js/VoiceUtil.js
New file
@@ -0,0 +1,44 @@
// 设置语音播报对象
var Voice = function() {
    this.speak = window.speechSynthesis;
    this.voice = '';
    this.zh_CN = false;
    this._setLang();    // 获取并检测是否有中文的环境
};
// 播报语音        (调用发声的方法时请使用延时发声)
Voice.prototype.play = function(txt) {
    if(!this.zh_CN) {
        console.info('你的电脑不支持中文播报!');
    }
    console.info(this.zh_CN);
    this.cancel();
    var to_speak = new SpeechSynthesisUtterance(txt);
    to_speak.voice = this.voice;    // 设定中文播报
    this.speak.speak(to_speak);
};
// 退出当前播报
Voice.prototype.cancel = function() {
    this.speak.cancel();
};
// 检查当前语言环境
Voice.prototype._setLang = function() {
    var _this = this;
    setTimeout(function(){
        var voices = _this.speak.getVoices();
        for(var i=0; i<voices.length; i++) {
            var _voices = voices[0];
            //console.info(_voices);
            if(_voices.lang === 'zh-CN') {
                _this.zh_CN = true;
                _this.voice = _voices;
            }
        }
    }, 0);
};
var voice = new Voice();