public static 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 = "multipart/form-data";
getAccessRequest.Accept = "*/*";
getAccessRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
getAccessRequest.Timeout = ;//30秒连接不成功就中断
getAccessRequest.Method = "post"; HttpWebResponse response = getAccessRequest.GetResponse() as HttpWebResponse;
using (StreamReader strHttpComback = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
access_html = strHttpComback.ReadToEnd();
}
}
catch (WebException ex)
{
Console.Write(ex.Message);
Console.ReadLine();
}
JObject jo = JObject.Parse(access_html);
access_token = jo["access_token"].ToString();//得到返回的toke
return access_token;
}
public static string getStrText(string para_API_id, string para_API_access_token, string para_API_language, string para_API_record, string para_format, string para_Hz)
{
string strJSON = "";
//方法参数说明:
//该方法返回值:
//该方法执行正确返回值是语音翻译的文本,错误是错误号,可以去看百度语音文档,查看对应错误
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, , 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 = ;//30秒连接不成功就中断
using (Stream writeStream = getTextRequst.GetRequestStream())
{
writeStream.Write(voice, , 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"][].ToString();
return strText;
}
else
{
error = jsons["err_no"].Value<string>() + jsons["err_msg"].Value<string>();
return error;
}
} //百度公众号的两个唯一值
string access = getStrAccess(para_API_key, para_API_secret_key);
Console.Write(access);
Console.ReadLine();
string text = getStrText(GetMacByNetworkInterface()[0], access, "zh", "1.wav", "wav", "");

///<summary>
/// 通过NetworkInterface读取网卡Mac
///</summary>
///<returns></returns>
public static List<string> GetMacByNetworkInterface()
{
List<string> macs = new List<string>();
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
macs.Add(ni.GetPhysicalAddress().ToString());
}
return macs;
}

注意:视频采样率只支持8000,16000

c# 百度api语音识别的更多相关文章

  1. 调用百度API进行文本纠错

    毕设做的是文本纠错方面,然后今天进组见研究生导师 .老师对我做的东西蛮感兴趣.然后介绍自己现在做的一些项目,其中有个模块需要有用到文本纠错功能. 要求1:有多人同时在线编辑文档,然后文档功能有类似Wo ...

  2. 35.百度云语音识别接口使用及PyAudio语音识别模块安装

    百度云语音识别接口使用: 百度云语音识别接口文档:https://cloud.baidu.com/doc/SPEECH/ASR-API.html#JSON.E6.96.B9.E5.BC.8F.E4.B ...

  3. 百度API ; 很多有用的接口及公用 数据

    百度API : http://apistore.baidu.com/ . 比如手机号码:

  4. 去百度API的百度地图准确叠加和坐标转换的解决方案研究

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 目前项目上如果要使用百度地图,得加载百度的开发包,然后通过百 ...

  5. 利用百度API Store接口进行火车票查询

    火车票查询 项目源码下载链接: Github:https://github.com/VincentWYJ/TrainTicketQuery 博客文件:http://files.cnblogs.com/ ...

  6. 百度api短信开发

    公司原来有一个短信发送的功能,是调用第三方的,但是很不稳定,时不时就收不到短信,但是钱已经扣了.对于这样的事,谁都忍受不了的.于是想找一个稳定短信发送平台,第一想到的是阿里云,百度.在这两个平台上公司 ...

  7. html5获取经纬度,百度api获取街区名,并使用JS保存进cookie

    引用js<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak= ...

  8. 百度API使用--javascript api进行多点定位

    使用百度地图提供的javascript api,给定多点的经纬度坐标,在百度地图上 显示这些坐标点. 其中包括各个点自适应地图显示,自定义坐标点的图标,以及各个点之间添加折线. 实现的效果如下图: 具 ...

  9. PHP学习笔记:利用百度api实现手机归属地查询

    从来没有用过api,都不知道怎么获得api的数据,跟着demo,然后修改,终于实现了手机号码查询的功能,代码和说明很全,大家试试. <?php /** * Created by jianqing ...

随机推荐

  1. Debian 8(Jessie) 安装pptp-linux (PPTP客户端), 以及route命令说明

    命令, 这里定义这个pptp的连接名称为hcoffice #安装 sudo apt-get install pptp-linux #用户名和口令 sudo vim /etc/ppp/chap-secr ...

  2. Smoothing in fMRI analysis (FAQ)

    Source: http://mindhive.mit.edu/node/112 1. What is smoothing? "Smoothing" is generally us ...

  3. js 点击默认另存 ,不是打开 Blob 操作

    function savepic(obj) { if (memFileObj != undefined) { obj = memFileObj; } else { memFileObj = obj; ...

  4. Codevs 1910递归函数

    1910 递归函数  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 对于一个递归函数w(a, b, c). 如果a <= ...

  5. android源码framework下添加新资源的方法

    编译带有资源的jar包,需要更改frameworks层,方法如下: 一.增加png类型的图片资源 1.将appupdate模块所有用到的png格式图片拷贝到framework/base/core/re ...

  6. struts2使用Convention Plugin在weblogic上以war包部署时,找不到Action的解决办法

    环境: struts 2.3.16.3 + Convention Plugin 2.3.16.3 实现零配置 现象:以文件夹方式部署在weblogic(10.3.3)上时一切正常,换成war包部署,运 ...

  7. JavaScript中正则表达式test()、exec()、match() 方法区别

    1.test test 返回 Boolean,查找对应的字符串中是否存在模式.var str = "1a1b1c";var reg = new RegExp("1.&qu ...

  8. 与Python Falling In Love_Python跨台阶(面向对象)

    第二课会介绍Python中的一些变量的使用.列表.元组.字典等一些详细内容...篇幅会比较多...因此在整理中... 先跳过第二课...直接来第三课..Python中面向对象的学习以及与mysql数据 ...

  9. SqlServer导入数据到MySql

    1.下载MySql ODBC Driver并进行安装.例如我下载的这个安装包是mysql-connector-odbc-5.1.6-win32.msi. 2.装完后,添加odbc数据源: 3.在sql ...

  10. ServiceStack 概念参考文摘

    摘自:http://www.cnblogs.com/woxpp/p/5010881.html ServiceStack 用于服务开发,可以为各种形式的网站.软件.APP等提供数据服务,可以提供REST ...