百度语音合成的使用(get方案)

一、index.html

<html>
<head>
<meta name="viewport" content="width=device-width">
<style type="text/css">
#vedioDiv {
     visibility: hidden;
}
</style>
<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
</head>
<body style="margin: 0px;">
<lable>请输入文字:</lable>
<input  id="voiceText" type="text" />
<button id="voiceTextBtn">转化为语音</button>
<div id="vedioDiv">
</div>
<script type="text/javascript" src="js/test_view.js"></script>
<script type="text/javascript" src="js/test_model.js"></script>
<script type="text/javascript" src="js/test_controller.js"></script>
</body>

</html>

二、test_model.js(核心)

参数选择描述
tex必填必合成的文本,使用UTF-8编码。小于512个中文字或者英文数字。(文本在百度服务器内转换为GBK后,长度必须小于1024字节)
tok必填开放平台获取到的开发者access_token(见上面的“鉴权认证机制”段落)
cuid必填用户唯一标识,用来区分用户,计算UV值。建议填写能区分用户的机器 MAC 地址或 IMEI 码,长度为60字符以内
ctp必填客户端类型选择,web端填写固定值1
lan必填固定值zh。语言选择,目前只有中英文混合模式,填写固定值zh
spd选填语速,取值0-9,默认为5中语速
pit选填音调,取值0-9,默认为5中语调
vol选填音量,取值0-15,默认为5中音量
per选填发音人选择, 0为普通女声,1为普通男生,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女声
var Model = {};

Model.getVoiceByText= function getVoiceByText(vedioJqueryObj , voiceText){


    var source = "<source src=http://tsn.baidu.com/text2audio?tex="+voiceText+"&amp;lan=zh&amp;cuid=8d:89:a5:ba:65:0d&amp;"+
                        "ctp=1&amp;tok=24.2695392b5384125f296447e16fd1f16d.2592000.1517986880.282335-10222819        "+
                        "type='audio/mp3'>";

    var vedio="<video controls='controls' autoplay='autoplay' name='media'>"+source+"</video>"

    View.vedioDiv.empty();
    View.vedioDiv.html(vedio);
}

三、test_controller.js

$(document).ready(function( ) {

    $("#voiceTextBtn").click(function(){
        var voiceText = $("#voiceText").val();             
        Model.getVoiceByText(View.vedioObj,voiceText);
    })


})

四、test_view.js

var View = {};

var vedioDiv = $("#vedioDiv");

View.vedioDiv=vedioDiv;


效果图:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值