资源简介
1. 首先去百度语音开发平台申请两种key(APIkey, secretkey)
2. 根据key申请token,token申请一个好像可以使用一个月左右
3. 我把读取录音文件的目录写死了,就是bin/debug目录,可以自行修改,后面开发
4. 大致酱紫,很简单一个demo,可以在此基础上扩展
5. 将录音文件放入路径,可以直接识别
代码片段和文件信息
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 2016-10-26 10:41 voice\
目录 0 2016-10-25 12:21 voice\.vs\
目录 0 2016-10-25 12:21 voice\.vs\voice\
目录 0 2016-10-25 12:21 voice\.vs\voice\v14\
文件 43520 2016-10-26 10:55 voice\.vs\voice\v14\.suo
文件 240 2016-10-26 10:44 voice\README.txt
目录 0 2016-10-26 10:55 voice\voice\
文件 189 2016-10-25 12:21 voice\voice\App.config
文件 2585 2016-10-25 18:37 voice\voice\Form1.Designer.cs
文件 3442 2016-10-26 10:55 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 2016-10-25 12:21 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 2016-10-25 12:21 voice\voice\bin\
目录 0 2016-10-25 18:40 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
文件 6947 1998-09-07 02:31 voice\voice\bin\Debug\3.wav
文件 430592 2013-06-06 13:33 voice\voice\bin\Debug\Newtonsoft.Json.dll
文件 1152512 2013-06-06 13:33 voice\voice\bin\Debug\Newtonsoft.Json.pdb
文件 464518 2013-06-06 13:33 voice\voice\bin\Debug\Newtonsoft.Json.xm
文件 130604 2016-10-25 15:41 voice\voice\bin\Debug\hi3.wav
文件 10240 2016-10-26 10:55 voice\voice\bin\Debug\voice.exe
文件 189 2016-10-25 12:21 voice\voice\bin\Debug\voice.exe.config
文件 22016 2016-10-26 10:55 voice\voice\bin\Debug\voice.pdb
............此处省略25个文件信息
- 上一篇:简易的学生管理系统ASP.NET
- 下一篇:ASP.NET 图书管理系统(毕业设计)
评论
共有 条评论