码迷,mamicode.com
首页 > 其他好文 > 详细

csharp: 百度语音合成

时间:2015-11-25 19:16:17      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

        public string API_id = "3333"; //你的ID
        public string API_record = null; 
        public string API_record_format = null; 
        public string API_record_HZ = null;
        public string API_key = "geovindu"; //你的KEY
        public string API_secret_key = "geovindu"; //你的SECRRET_KEY
        public string API_language = null; 
        public string API_access_token = null; 
        public string strJSON = ""; 
        private const string tex = "远去的山河沉寂,恋过的风景如昔." +  
                           "苍何斩落了情迷,生死轻付了别离." +  
                           "捣一脉相思成泥,沐四海悲风无迹." +  
                           "往生海烟波又起,妙华镜风雪共历.";



   
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {


        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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);

        }
        /// <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;
        }

  程序还未完善。

API请求方式基本说明

http://yuyin.baidu.com/docs/tts/136

 

语音合成接口支持 POST 和 GET两种方式
正式地址:http://tsn.baidu.com/text2audio

csharp: 百度语音合成

标签:

原文地址:http://www.cnblogs.com/geovindu/p/4995463.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!