语音识别挂起在ApiController上

时间:2012-11-16 18:56:55

标签: c# model-view-controller speech-recognition

我有一个使用mvc的服务,在这种情况下我有一个控制器正在实现apicontroler我正在从另一个项目调用一个帖子并传递一个流。然后我得到字符串并继续工作。 这个方法运行并返回正确的值但是我没有得到任何我调用它的地方。看起来它有效但没有任何反应。

这是代码。

result = new List<string>(); 
Stream stream = new MemoryStream(); 
Task loadingStream = (Request.Content as StreamContent).CopyToAsync(stream);

loadingStream.Wait();

stream.Position = 0;

SpeechRecognitionEngine _appRecognizer = new SpeechRecognitionEngine(new CultureInfo("en-US"));

_appRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognized);

_appRecognizer.SetInputToWaveStream(stream);

_appRecognizer.LoadGrammar(new Grammar(@"C:\Users\Thomas\Desktop\grammar1.srgs")); 
RecognitionResult recognitionResult = _appRecognizer.Recognize();

_appRecognizer.SpeechRecognized -= SpeechRecognized;

return recognitionResult != null ? recognitionResult.Text : null;

1 个答案:

答案 0 :(得分:0)

您是否致电_appRecognizer.RecognizerAsync()?查看文档here