1

我有点失落,我真的希望你能帮助我。我正在尝试使用 Google Speech API。我的目标是获取一个音频文件,将其发送到 Speech API 并让它返回文本。这是我到目前为止所做的: • 在 Google 上创建了一个项目 • 创建了一个服务帐户 • 注册了一个指向我从 Google 下载的 json 文件的环境变量。• 将 NuGet GoogleSpeechAPI 安装到 Visual Studio 2015

我真的不知道从这里去哪里。到目前为止,这是我尝试实现的:(从 codeproject 上的借用代码修改)

var service = new CloudSpeechAPIService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Ayaz",
});

//FileStream fileStream = File.OpenRead(@"C:\OA\VS_Projects\Speech\good-morning-google.flac");
//MemoryStream memoryStream = new MemoryStream();
//memoryStream.SetLength(fileStream.Length);
//fileStream.Read(memoryStream.GetBuffer(), 0, (int)fileStream.Length);
//byte[] BA_AudioFile = memoryStream.GetBuffer();

string path = @"C:\OA\VS_Projects\Speech\good-morning-google.flac";
byte[] BA_AudioFile = System.IO.File.ReadAllBytes(path);

SyncRecognizeRequest mySyncReq = new SyncRecognizeRequest();

AsyncRecognizeRequest myRequest = new AsyncRecognizeRequest();
RecognitionAudio audio = new RecognitionAudio();
RecognitionConfig rConfig = new RecognitionConfig();
audio.Content = System.Convert.ToBase64String(BA_AudioFile);
rConfig.Encoding = "FLAC";  // LINEAR16   FLAC   MULAW   AMR   AMR_WB 
rConfig.LanguageCode = "us-EN";
rConfig.SampleRate = 44100;
myRequest.Audio = audio;
myRequest.Config = rConfig;

mySyncReq.Audio = audio;
mySyncReq.Config = rConfig;
//service.Speech.Asyncrecognize(myRequest); 
Operation iOp;
//Operation status;
//Syncrecognize   Asyncrecognize
iOp = service.Speech.Asyncrecognize(myRequest).Execute();

while(true)
{
    if (iOp.Done == true)
    {
        break;
    }

}
4

0 回答 0