[英]Speech recognition with Microsoft Cognitive Speech API and non-microphone real-time audio stream
[英]Speech recognition using a real time stream
首先,为了阐明我的目标:我使用CSCore库并使用WasapiLoopbackCapture
类捕获背景音频,我打算将其用作System.Speech.Recognition
识别引擎的实时输入。 该类将数据输出到.WAV文件或Stream。 然后我尝试这样做:
private void startButton_Click(object sender, EventArgs e)
{
_recognitionEngine.UnloadAllGrammars();
_recognitionEngine.LoadGrammar(new DictationGrammar());
LoadTargetDevice();
StartStreamCapture(); // Here I am starting the capture to _stream (MemoryStream type)
_stream.Position = 0; // Without setting this, I get a stream format exception.
_recognitionEngine.SetInputToWaveStream(_stream);
_recognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
}
其结果是,我没有得到一个例外,但我还没有得到SpeechRecognized
或SpeechDetected
事件射击。 我怀疑这是因为System.Speech.Recognition
程序集不支持实时流。 我在网上搜索,有人报告实施自定义Stream
类型作为解决方法,但我无法按照帖子上的说明进行操作,这些说明不清楚( 请参阅Dexter Morgan的回复 )。
我知道这个问题最好通过使用不同的库或替代方法来解决,但我想知道如何专门做这个临时实现,主要是出于知识目的。
谢谢!
@Justcarty感谢您的澄清,这里是我的解释为什么OP的代码不能工作以及需要做什么才能使其工作。
在C#中用于语音识别和合成,你可能会对我们有两个Speech DLL的文档感到困惑
1. Microsoft Speech DLL(Microsoft.speech.dll)2。系统语音DLL(System.Speech.Dll)
System.speech dll是Windows操作系统的一部分。 这两个库在API几乎相同但不完全相同的意义上是相似的。 因此,如果您在线搜索语音示例,则从您获得的代码片段中可能无法判断他们是否向System.Speech
或Microsoft.Speech
解释。
因此,对于向C#应用程序添加语音,您需要使用Microsoft.Speech library
,而不是System.Speech library
。
下面总结了一些主要差异
|-------------------------|---------------------|
| Microsoft.Speech.dll | System.Speech.dll |
|-------------------------|---------------------|
|Must install separately | |
| | Part of the OS |
| | (Windows Vista+) |
|-------------------------|---------------------|
|Must construct Grammars | Uses Grammars or |
| free dictation |
| ------------------------|--------------------|
有关更多信息阅读以下文章 ,它解释了正确的实施方式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.