资源简介

C# 语音识别 示例源码

资源截图

代码片段和文件信息

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 cuid = “666“;//可以随便写
        string serverURL = “http://vop.baidu.com/server_api“;
        public Form1()
        {
            InitializeComponent();
            cuid = Guid.NewGuid().ToString();
        }

        private string Post(string audioFilePath)
        {
            string token = “24.cd839bae72bde020346a1534258d8173.2592000.1479976284.282335-8792499“;
            serverURL += “?lan=zh&cuid=kwwwvagaa&token=“ + token;
            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[

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-10-18 18:30  voice\
     目录           0  2019-10-18 18:30  voice\.vs\
     目录           0  2019-10-18 18:34  voice\.vs\voice\
     目录           0  2019-10-18 18:30  voice\.vs\voice\v14\
     文件       43520  2016-10-26 10:55  voice\.vs\voice\v14\.suo
     目录           0  2019-10-18 18:34  voice\.vs\voice\v15\
     文件       51200  2019-10-18 19:18  voice\.vs\voice\v15\.suo
     目录           0  2019-10-18 18:34  voice\.vs\voice\v15\Server\
     目录           0  2019-10-18 18:34  voice\.vs\voice\v15\Server\sqlite3\
     文件           0  2019-10-18 18:34  voice\.vs\voice\v15\Server\sqlite3\db.lock
     文件        4096  2019-10-18 18:34  voice\.vs\voice\v15\Server\sqlite3\storage.ide
     文件       32768  2019-10-18 18:34  voice\.vs\voice\v15\Server\sqlite3\storage.ide-shm
     文件      803432  2019-10-18 18:50  voice\.vs\voice\v15\Server\sqlite3\storage.ide-wal
     文件         240  2016-10-26 10:44  voice\README.txt
     目录           0  2019-10-18 18:40  voice\voice\
     文件         189  2016-10-25 12:21  voice\voice\App.config
     文件        2585  2016-10-25 18:37  voice\voice\Form1.Designer.cs
     文件        3453  2019-10-18 18:40  voice\voice\Form1.cs
     文件        5817  2016-10-25 18:37  voice\voice\Form1.resx
     文件         517  2016-10-25 12:21  voice\voice\Program.cs
     目录           0  2019-10-18 18:30  voice\voice\Properties\
     文件        1336  2016-10-25 12:21  voice\voice\Properties\AssemblyInfo.cs
     文件        2823  2016-10-25 12:21  voice\voice\Properties\Resources.Designer.cs
     文件        5612  2016-10-25 12:21  voice\voice\Properties\Resources.resx
     文件        1092  2016-10-25 12:21  voice\voice\Properties\Settings.Designer.cs
     文件         249  2016-10-25 12:21  voice\voice\Properties\Settings.settings
     目录           0  2019-10-18 18:30  voice\voice\bin\
     目录           0  2019-10-18 18:42  voice\voice\bin\Debug\
     文件      156204  2016-10-25 15:42  voice\voice\bin\Debug\0.wav
     文件       97324  2016-10-25 15:41  voice\voice\bin\Debug\1.wav
     文件      135724  2016-10-25 15:41  voice\voice\bin\Debug\2.wav
............此处省略38个文件信息

评论

共有 条评论