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. HTML 学习笔记 JavaScript(数据类型)

    字符串 数字 布尔 数组 对象 Null Undefined JavaScript 拥有动态类型 JavaScript拥有动态类型 这意味着相同的变量可用作不同的类型: 实例: var x // x ...

  2. memcached的图形界面监控

    前提是已经安装了php和memcached   图形界面的监控是通过memcache.php来实现的,   1.把该php程序拷贝到apache的web根目录   [root@cacti srv]# ...

  3. squid代理服务器根据代理IP路由

    import os ips = os.popen("""ifconfig |grep 'inet addr:'|awk '{print $2}'| sed '$d'| s ...

  4. usb驱动开发13之设备生命线

    上一节勉勉强强把struct urb这个中心给说完,接着看那三个基本点. 第一个基本点,usb_alloc_urb函数,创建urb的专用函数,为一个urb申请内存并做初始化,在drviers/usb/ ...

  5. dotnetGen 系列终于开源了

    https://github.com/2881099/dotnetGen .Net 3.0 + SqlServer 生成器 https://github.com/2881099/dotnetGen_s ...

  6. Exchange WebSerivce Usage

    //ExchangeService版本为2007SP1 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange20 ...

  7. 学习C++.Primer.Plus 5 循环和关系表达式

    C++将赋值表达式的值定义为左侧成员的值 赋值操作符是自右向左结合的 cout.setf(ios:: boolalpha);//调用设置标记,命令cout输出true或false,而非1或0. 任何表 ...

  8. Struts2、Spring MVC4 框架下的ajax统一异常处理

    本文算是struts2 异常处理3板斧.spring mvc4:异常处理 后续篇章,普通页面出错后可以跳到统一的错误处理页面,但是ajax就不行了,ajax的本意就是不让当前页面发生跳转,仅局部刷新, ...

  9. 韩国网页设计资料《网页设计大师2》JPG+PSD+TXT等 73.89G 百度云下载

    < 网页设计大师2 >超越第一代版本,提供更新更精美的网页素材模板.全部由国际顶级设计师精选打造,完全展示走在潮流 之前的设计风格.是网页设计师/UI交互界面设计师必备工具. < 网 ...

  10. 记一个全局变量"冒充"局部变量引起的bug

    看代码相当简单直观,觉得怎么都不会出错,可运行结果明明就是错了 - 对着vim摸着脑袋就是想不出哪里有问题,可去掉新加的代码,就又可以了. 没办法,只好祭出杀手锏:一行一行注释掉来观察... 反映问题 ...