c# 百度api语音识别
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语音识别的更多相关文章
- 调用百度API进行文本纠错
毕设做的是文本纠错方面,然后今天进组见研究生导师 .老师对我做的东西蛮感兴趣.然后介绍自己现在做的一些项目,其中有个模块需要有用到文本纠错功能. 要求1:有多人同时在线编辑文档,然后文档功能有类似Wo ...
- 35.百度云语音识别接口使用及PyAudio语音识别模块安装
百度云语音识别接口使用: 百度云语音识别接口文档:https://cloud.baidu.com/doc/SPEECH/ASR-API.html#JSON.E6.96.B9.E5.BC.8F.E4.B ...
- 百度API ; 很多有用的接口及公用 数据
百度API : http://apistore.baidu.com/ . 比如手机号码:
- 去百度API的百度地图准确叠加和坐标转换的解决方案研究
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 目前项目上如果要使用百度地图,得加载百度的开发包,然后通过百 ...
- 利用百度API Store接口进行火车票查询
火车票查询 项目源码下载链接: Github:https://github.com/VincentWYJ/TrainTicketQuery 博客文件:http://files.cnblogs.com/ ...
- 百度api短信开发
公司原来有一个短信发送的功能,是调用第三方的,但是很不稳定,时不时就收不到短信,但是钱已经扣了.对于这样的事,谁都忍受不了的.于是想找一个稳定短信发送平台,第一想到的是阿里云,百度.在这两个平台上公司 ...
- html5获取经纬度,百度api获取街区名,并使用JS保存进cookie
引用js<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak= ...
- 百度API使用--javascript api进行多点定位
使用百度地图提供的javascript api,给定多点的经纬度坐标,在百度地图上 显示这些坐标点. 其中包括各个点自适应地图显示,自定义坐标点的图标,以及各个点之间添加折线. 实现的效果如下图: 具 ...
- PHP学习笔记:利用百度api实现手机归属地查询
从来没有用过api,都不知道怎么获得api的数据,跟着demo,然后修改,终于实现了手机号码查询的功能,代码和说明很全,大家试试. <?php /** * Created by jianqing ...
随机推荐
- 使用adb shell卸载程序
个人感觉在命令行中卸载程序要比在手机界面卸载程序要方便许多,配合命令行下的报名查看包名的命令就更加方便了. 1.查看应用准确包名 adb shell pm list package -f |grep ...
- 一个App需要的东西
1.短信申请平台 (发送验证码需要的短信) http://www.yuntongxun.com/api/sms?nl=sy_cp 容联云通讯
- 兼容IE678的placeholder
jquery-placeholder.js是基于jquery的插件,对不支持placeholder的浏览器有非常好的兼容性,只需引入这个js文件,然后给所有Input元素调用一下placeholder ...
- css3结构性伪类选择器
- Centos5.8 安装 ImageMagick 6.8.9-3
下载最新的ImageMagick源码包 ImageMagick-6.8.9-3.x86_64.rpm 直接prm -ivh 安装提示错误 error: Failed dependencies: lib ...
- PAT 1018. 锤子剪刀布 (20)
现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算最大. 输入格式: 输入第1行给出正整数N(<=105),即双方交锋的次数.随后N行,每行给出一次交锋的信息,即 ...
- httpserver
改了下 # -*- coding:utf-8 -*- from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler HOST = &quo ...
- GET请求参数为中文时乱码分析
问题描述 近期做任务时,跟后端联调时遇到一个问题,前端发送get请求,当参数值有中文时,请求失败,请求参数变为乱码.(ps:一般当参数有中文时,很少使用get请求,而是使用post请求来传输数据,请求 ...
- [MetaHook] Find a function signature
Find a non-public function signature, we need a tool "IDA Pro" ( You can open picture in a ...
- KMS10流氓软件
win10想激活,结果中了流氓软件的当... (关键是win10家庭单语言版居然还激活不了....白吃亏了) 把我的chrome 和 firefox 主页改成hao.qquu8.com,该网址重定向到 ...