首页 > 学院 > 开发设计 > 正文

csharp:百度语音合成

2019-11-14 14:26:19
字体:
来源:转载
供稿:网友
        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;        }

  程序还未完善。

注:有效符号多或特殊符号的,无法读文章,百度有字数限制。可能要特珠服务需要购买。

网址DEMO:http://www.dusystem.com/news/show-184.html

API请求方式基本说明

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

 

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表