http://yuyin.baidu.com/申请创建一个语音合成应用,“查看Key”获得ID、KEY、SECRRET_KEY
public string API_id = "88888888"; //你的ID
public string API_record = null;
public string API_record_format = null;
public string API_record_HZ = null;
public string API_key = "1IoiaAoOb8XS5s6d5ssXXXX"; //你的KEY
public string API_secret_key = "e735b416161d08ad216ss9d6s6df6546s6s"; //你的SECRRET_KEY
public string API_language = null;
public string API_access_token = null;
public string strJSON = "";
private const string tex = "家乐福10月30号全场8.5折。";
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
///
/// </summary>
/// <param name="para_API_key">你的KEY</param>
/// <param name="para_API_secret_key">你的SECRRET_KEY</param>
/// <returns></returns>
public string getStrAccess(string para_API_key, string para_API_secret_key)
{
//方法参数说明:
//para_API_key:API_key(你的KEY)
//para_API_secret_key(你的SECRRET_KEY)
//方法返回值说明:
//百度认证口令码,access_token
string access_html = null;
string access_token = null;
string getAccessUrl = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials" + "&client_id=" + para_API_key + "&client_secret=" + para_API_secret_key;
try
{
HttpWebRequest getAccessRequest = WebRequest.Create(getAccessUrl) as HttpWebRequest;
//getAccessRequest.Proxy = null;
getAccessRequest.ContentType = "multipart/form-data";
getAccessRequest.Accept = "*/*";
getAccessRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
getAccessRequest.Timeout = 30000;//30秒连接不成功就中断
getAccessRequest.Method = "post";
HttpWebResponse response = getAccessRequest.GetResponse() as HttpWebResponse;
using (StreamReader strHttpComback = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
access_html = strHttpComback.ReadToEnd();
}
}
catch (WebException ex)
{
Response.Write(ex.ToString());
}
JObject jo = JObject.Parse(access_html);
access_token = jo["access_token"].ToString();//得到返回的toke
return access_token;
}
protected void Button1_Click(object sender, EventArgs e) //通过点击按钮获得解析的语音信息
{
API_access_token = getStrAccess(API_key, API_secret_key);
Guid cid = new Guid();
Response.Redirect("http://tsn.baidu.com/text2audio?tex=" + tex + "&lan=zh&cuid=" + cid.ToString() + "&ctp=1&tok=" + API_access_token);
}
生成后得到一个地址
http://tsn.baidu.com/text2audio?tex=家乐福10月30号全场8.5折。&lan=zh&cuid=00000000-0000-0000-0000-000000000000&ctp=1&tok=24.958f5392dcae747174b0b8ccc76d273a.2592000.1479864652.282335-8692649
自动播放语音!
评论列表: