using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.IO; using System.Threading; using Newtonsoft.Json.Linq; namespace voice { public partial class Form1 : Form { string testtoken = ""; string cuid = "";//隨便寫(xiě) string serverURL = "http://vop.baidu.com/server_api"; public Form1() { InitializeComponent(); cuid = Guid.NewGuid().ToString(); } private string Post(string audioFilePath) { serverURL += "?lan=zh&cuid=kwwwvagaa&token=" + testtoken; FileStream fs = new FileStream(audioFilePath, FileMode.Open); byte[] voice = new byte[fs.Length]; fs.Read(voice, 0, voice.Length); fs.Close(); fs.Dispose(); HttpWebRequest request = null; Uri uri = new Uri(serverURL); request = (HttpWebRequest)WebRequest.Create(uri); request.Timeout = 5000; request.Method = "POST"; request.ContentType = "audio/wav; rate=16000"; request.ContentLength = voice.Length; try { using (Stream writeStream = request.GetRequestStream()) { writeStream.Write(voice, 0, voice.Length); writeStream.Close(); writeStream.Dispose(); } } catch { return null; } string result = string.Empty; string result_final = string.Empty; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8)) { string line = string.Empty; StringBuilder sb = new StringBuilder(); while (!readStream.EndOfStream) { line = readStream.ReadLine(); sb.Append(line); sb.Append("\r"); } readStream.Close(); readStream.Dispose(); result = sb.ToString(); string[] indexs = result.Split(','); foreach (string index in indexs) { string[] _indexs = index.Split('"'); if (_indexs[2] == ":[") result_final = _indexs[3]; } } responseStream.Close(); responseStream.Dispose(); } response.Close(); } return result_final; } private void button1_Click(object sender, EventArgs e) { textBox1.Text = Post(Application.StartupPath + "\\2.wav"); } } }
附件中有源代碼,具體看里面的README
譙城網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,譙城網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為譙城近1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的譙城做網(wǎng)站的公司定做!
網(wǎng)站名稱:C#調(diào)用百度語(yǔ)音識(shí)別小Demo
網(wǎng)站路徑:http://www.muchs.cn/article40/jpjiho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、網(wǎng)站設(shè)計(jì)、Google、企業(yè)網(wǎng)站制作、靜態(tài)網(wǎng)站、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)