91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#調用百度語音識別小Demo

發布時間:2020-07-02 23:25:26 來源:網絡 閱讀:6326 作者:bigpomelo 欄目:編程語言
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 = "";//隨便寫
        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

附件:http://down.51cto.com/data/2368300
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

曲阜市| 双桥区| 宜春市| 汤阴县| 乐山市| 沾益县| 清水县| 儋州市| 娄底市| 安吉县| 松原市| 奈曼旗| 德江县| 张家港市| 鄂尔多斯市| 资阳市| 和林格尔县| 繁峙县| 合山市| 罗城| 南安市| 福贡县| 南开区| 砀山县| 资溪县| 厦门市| 弋阳县| 龙南县| 休宁县| 滦平县| 化隆| 左权县| 额尔古纳市| 铅山县| 广丰县| 交城县| 日土县| 宿松县| 石阡县| 盐山县| 都安|