前端工程师 开发工具_语音识别/语音合成

2017web 前端开发工具|html css前端开发工具|app前端使用php开发工具

识别可能反应个几秒钟吧,10秒钟没反应就别傻等了,js库访问不到的问题。
输入你要说的话,点击合成就ok,你要说脏话,建议带耳机
html 代码

<!DOCTYPE html>
<head>
    <meta charset=”UTF-8″>
    <title>面试题前端开发工具:语音合成</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
            list-style-type: none;
        }
        html,
        body {
            width: 100%;
            height: 100%;
            background: black;
            overflow: hidden;
        }
        .container {
            width: 70%;
            height: 50%;
            margin: 200px auto;
            background: #fff;
            text-align: center;
        }
        .container input {
            font-size: 2rem;
            width: 50%;
            height: 20%;
            margin: 30px 0;
        }
    </style>
</head>
<body>
    <div class=”container”>
        <input id=”text-in” type=”text” placeholder=”输入你想合成的话”>
        <input type=”button” value=”合成语音” onclick=”temp()”>
    </div>
    <script src=”http://blog.faultylabs.com/files/md5.js”></script>
    <script src=”http://webapi.openspeech.cn/socket.io/socket.io.js”></script>
    <script src=’http://webapi.openspeech.cn/fingerprint.js’></script>
    <script src=”http://webapi.openspeech.cn/tts.min.js”></script>
    <script type=”text/javascript”>
        /**
         * 初始化对象
         */
        var session = new IFlyTtsSession({
            ‘url’: ‘http://webapi.openspeech.cn/’,
            ‘interval’: ‘30000’,
            ‘disconnect_hint’: ‘disconnect’,
            ‘sub’: ‘tts’
        });
        var audio = null;
        /**
         * @content 待合成文本(不超过4096字节)
         */
        function play(content) {
            /***********************************************************以下签名过程需根据实际应用信息填入***************************************************/
            var appid = “54c88b8d”;
            var timestamp = new Date().toLocaleTimeString(); //当前时间戳,例new Date().toLocaleTimeString()
            var expires = 60000; //签名失效时间,单位:ms,例60000
            var signature = faultylabs.MD5(appid + ‘&’ + timestamp + ‘&’ + expires + ‘&’ + “6a97bfd7fa4531f7”);
            var params = {
                “params”: “aue = speex-wb;7, ent = intp65, spd = 50, vol = 50, tte = utf8, caller.appid=” + appid + “,timestamp=” +
                    timestamp + “,expires=” + expires,
                “signature”: signature,
                “gat”: “mp3”
            };
            session.start(params, content, function (err, obj) {
                if (err) {
                    alert(“语音合成发生错误,错误代码 :” + err);
                } else {
                    if (audio != null) {
                        audio.pause();
                    }
                    audio = new Audio();
                    audio.src = ”;
                    audio.play();
                    audio.src = “http://webapi.openspeech.cn/” + obj.audio_url;
                    audio.play();
                }
            });
        };
        function temp() {
            var content = document.getElementById(“text-in”).value;
            play(content);
        }
    </script>
</body>
</html>

苹果电脑前端开发工具|前端开发工具ltp|web前端开发工具怎么用

» 本文来自:前端开发者 » 《前端工程师 开发工具_语音识别/语音合成》
» 本文链接地址:https://www.rokub.com/3938.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!