最近老板说要试下google的语音识别,于是上网找了一些代码,最多的一篇就是C# 调用Google语音识别。 下载过来运行,前面几天一直是服务器内部500错误。 以为代码问题,今天又试了一下,居然可以用了(不知道什么原因。。)。 由于需要在C++上用,偷懒的办法就是C++调用C#动态链接库,下面是过程:
1. 编译c#动态链接库
新建C#项目,选择“类库”。 代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace googleLib
{
public class SpeechRecognize
{
public bool GoogleSR(string inFileName,string format,int rate,ref string recResults)
{
recResults = "";
try
{
FileStream fs = new FileStream(inFileName, FileMode.Open);
byte[] voice = new byte[fs.Length];