国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

csharp:百度語音識別

2019-11-14 13:44:15
字體:
來源:轉載
供稿:網友
 public string API_id = "8888"; //你的ID        public string API_record = null;        public string API_record_format = "wav";        public string API_record_HZ = "16000";        public string API_key = "geovindu"; //你的KEY        public string API_secret_key = "55519"; //你的SECRRET_KEY        public string API_language = "zh";        public string API_access_token = null;        public string strJSON = "";        //錄音        [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]        public static extern int mciSendString(         string lpstrCommand,         string lpstrReturnString,         int uReturnLength,         int hwndCallback        );        /// <summary>        ///         /// </summary>        public Form1()        {            InitializeComponent();        }        /// <summary>        ///         /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        PRivate void Form1_Load(object sender, EventArgs e)        {            API_record=application.StartupPath + "http://上班.wav";            API_access_token = getStrAccess(API_key, API_secret_key);        }        /// <summary>        ///         /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button1_Click(object sender, EventArgs e)        {            this.textBox2.Text = getStrText(API_id, API_access_token, API_language, API_record, API_record_format, API_record_HZ);        }        /// <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 = "mult翻譯的文本,錯誤是錯誤號,可以去看百度語音文檔,查看對應錯誤                         string strText = null;             string error = null;             FileInfo fi = new FileInfo(para_API_record);             FileStream fs = new FileStream(para_API_record, FileMode.Open);             byte[] voice = new byte[fs.Length];             fs.Read(voice, 0, voice.Length);             fs.Close();               string getTextUrl = "http://vop.baidu.com/server_api?lan=" + para_API_language + "&cuid=" + para_API_id + "&token=" + para_API_access_token;             HttpWebRequest getTextRequst = WebRequest.Create(getTextUrl) as HttpWebRequest;              /* getTextRequst.Proxy = null;             getTextRequst.ServicePoint.Expect100Continue = false;             getTextRequst.ServicePoint.UseNagleAlgorithm = false;             getTextRequst.ServicePoint.ConnectionLimit = 65500;             getTextRequst.AllowWriteStreamBuffering = false;*/               getTextRequst.ContentType = "audio /"+para_format+";rate="+para_Hz;             getTextRequst.ContentLength = fi.Length;             getTextRequst.Method = "post";             getTextRequst.Accept = "*/*";             getTextRequst.KeepAlive = true;            getTextRequst.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";             getTextRequst.Timeout = 30000;//30秒連接不成功就中斷                          using (Stream writeStream = getTextRequst.GetRequestStream())             {                 writeStream.Write(voice, 0, voice.Length);             }               HttpWebResponse getTextResponse = getTextRequst.GetResponse() as HttpWebResponse;                    using (StreamReader strHttpText = new StreamReader(getTextResponse.GetResponseStream(), Encoding.UTF8))             {                 strJSON = strHttpText.ReadToEnd();             }                             JObject jsons = JObject.Parse(strJSON);//解析JSON                             if (jsons["err_msg"].Value<string>() == "success.")             {                                      strText = jsons["result"][0].ToString();                     return strText;             }             else            {                     error = jsons["err_no"].Value<string>() + jsons["err_msg"].Value<string>();                     return error;             }                       }

  參考: http://yuyin.baidu.com/docs/asr/57 

API請求方式基本說明

  • 語音識別接口支持 POST 方式
  • 目前 API 僅支持整段語音識別的模式,即需要上傳整段語音進行識別
  • 語音數據上傳方式有兩種:隱示發送和顯示發送
  • 原始語音的錄音格式目前只支持評測 8k/16k 采樣率 16bit 位深的單聲道語音
  • 壓縮格式支持:pcm(不壓縮)、wav、opus、speex、amr、x-flac
  • 系統支持語言種類:中文(zh)、粵語(ct)、英文(en)
  • 正式地址:http://vop.baidu.com/server_api

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尚志市| 安徽省| 黄平县| 稷山县| 吉木萨尔县| 普格县| 织金县| 伊春市| 柯坪县| 宁陕县| 石台县| 广丰县| 青海省| 万州区| 台东县| 会同县| 合作市| 仙居县| 开远市| 原平市| 鄂尔多斯市| 板桥市| 乌兰浩特市| 婺源县| 五河县| 闸北区| 盐城市| 大连市| 永胜县| 建平县| 哈巴河县| 泾源县| 桓台县| 景宁| 福州市| 洪江市| 沾化县| 尼木县| 盘山县| 磴口县| 新源县|