使用实时流进行语音识别

问题描述 投票:9回答:1

首先,为了澄清我的目标:我使用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);
    }

结果是我没有得到例外,但我也没有得到SpeechRecognizedSpeechDetected事件的解雇。我怀疑这是因为System.Speech.Recognition程序集不支持实时流。我在网上搜索,有人报告实施自定义Stream类型作为解决方法,但我无法按照帖子上的说明不明确(see Dexter Morgan's reply here)。

我知道这个问题最好通过使用不同的库或替代方法来解决,但我想知道如何专门做这个临时实现,主要是出于知识目的。

谢谢!

c# windows audio speech-recognition cscore
1个回答
5
投票

@Justcarty感谢您的澄清,这里是我的解释为什么OP的代码不能工作以及需要做什么才能使其工作。

在C#中用于语音识别和合成,你可能会对我们有两个Speech DLL的文档感到困惑 1. Microsoft Speech DLL(Microsoft.speech.dll)2。系统语音DLL(System.Speech.Dll)

System.speech dll是Windows操作系统的一部分。这两个库在API几乎相同但不完全相同的意义上是相似的。所以,如果你在网上搜索语音示例,你会得到的代码片段可能无法告诉他们是否向System.SpeechMicrosoft.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      |
| ------------------------|--------------------|

有关更多信息,请阅读Following Article,它解释了正确的实施方式

© www.soinside.com 2019 - 2024. All rights reserved.