<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<body>
<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">
/**
* 初始化Session对象
*/
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"; //应用APPID,在open.voicecloud.cn上申请即可获得
var timestamp = new Date().toLocaleTimeString(); //当前时间戳,例new Date().toLocaleTimeString()
var expires = 60000; //签名失效时间,单位:ms,例60000
//!!!为避免secretkey泄露,签名函数调用代码建议在服务器上完成
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();
}
});
};
</script>
<input type="text" id="audiotext"/>
<input type="button" onclick="play(document.getElementById('audiotext').value)" value="点击我读出" />
</body>
</html>
MYX