前端开发JS朗读文本

网游游戏开发前端
web前端开发 小游戏
前端和游戏开发哪个好学

html 代码

<!DOCTYPE html>
    <head>
        <meta charset=”UTF-8″ />
        <title></title>
        <style type=”text/css”>
            div {
                border: 1px solid #ddd;
                margin-bottom: 20px;
            }
            button {
                margin: 20px;
                width: 120px;
                height: 34px;
            }
            p {
                margin: 20px;
            }
        </style>
    </head>
    <body>
        <div>
            <button>朗读</button>
            <p>
                百度百科是百度公司推出的一部内容开放、自由的网络百科全书平台。
            </p>
        </div>
        <script src=”js/speech.js”></script>
        <script>
            document.getElementsByTagName(‘button’)[0].onclick = function() {
                var txt = this.parentNode.getElementsByTagName(‘p’)[0].innerHTML
                speech(txt)
            }
        </script>
    </body>
</html>

speech代码
javascript 代码

;(function(w) {
    var DEFIND_SRC = ‘http://tts.baidu.com/text2audio?’
    var speech = function(options) {
        return new speech.fn.init(options)
    }
    speech.fn = speech.prototype = {
        init: function(options) {
            if (options) {
                if (typeof options == ‘string’) this.txt = options
                this.speek(true)
            }
            return this
        },
        resrc: function(objs) {
            objs = objs || {}
            var options = {
                lan: objs.lan || ‘zh’,
                ie: objs.ie || ‘UTF-8’,
                spd: objs.spd || ‘4’,
                text: encodeURI(this.txt),
            }
            var src = DEFIND_SRC
            for (var name in options) src += name + ‘=’ + options[name] + ‘&’
            return src.substr(0, src.length – 1)
        },
        speek: function(isspeek) {
            if (!this.txt) return this
            var aud = (this.audioer =
                this.audioer || document.createElement(‘audio’))
            aud.duration
            aud.src = this[‘resrc’]()
            isspeek && aud.play()
            return this
        },
    }
    speech.fn.init.prototype = speech.fn
    window.speech = speech
})(window)
网络游戏开发 前端多还是后端多
如何学好游戏前端开发
前端游戏开发dome
» 本文来自:前端开发者 » 《前端开发JS朗读文本》
» 本文链接地址:https://www.rokub.com/7044.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!