百度和讯飞和其他厂都提供了语音识别的接口,这里使用讯飞的识别将本地手机录的音频文件转成文字
以下注意事项:
1.X_Param 参数开始的时候带了空格导致验证不过,原因是讯飞将字符串做了repelce处理
2.讯飞后台设置白名单IP
3.本地的文件请使用ffmpeg转码成pcm标准格式,
参考:http://ai.baidu.com/docs#/ASR-Tool-convert/top
//语音听写
public PostResult<string> Speech(IFormFileCollection fileCollection)
{
#region 上传音频
if (fileCollection.Count == 0) throw new InvalidDataException("没找到需要上传的文件。");
var folder = IO.Directory.GetCurrentDirectory() + "//wwwroot//upload";//先保存到本地,然后云上传
var file = fileCollection[0];
if (!IO.Directory.Exists(folder)) IO.Directory.CreateDirectory(folder);
var filename = file.FileName;
var extension = filename.Substring(filename.LastIndexOf(".")).ToLower(); // 扩展名
var key = filename.Replace(extension, "_") + DateTime.Now.ToString("yyyyMMddHHmmssfff") + extension;
using (IO.FileStream fs = new IO.FileStream(folder + "//" + key, IO.FileMode.Create, IO.FileAccess.ReadWrite))
{
file.CopyTo(fs);
fs.Flush();
} /**/
#endregion
#region 调用接口
//使用ffmpeg音频转码
var path =(folder