【问题标题】:Speech recognition using a real time stream使用实时流进行语音识别
【发布时间】:2018-07-01 05:42:57
【问题描述】:

首先,为了明确我的目标:我正在使用 CSCore 库并使用 WasapiLoopbackCapture 类捕获背景音频,我打算将其用作 @ 的实时输入987654325@识别引擎。该类将数据输出到 .WAV 文件或流。然后我尝试这样做:

    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)。

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

谢谢!

【问题讨论】:

  • @justcarty ,你有没有尝试过?
  • @Webruster 从与 OP 的通信来看,他们使用的格式似乎不受支持。见this imagethis one
  • @JustCarty 那么你期待什么?你的问题是什么而不是 OP 问题
  • @Webruster OP 创建了一个程序,可以收听实时音频并转换为文本。该程序没有崩溃,但不会检索音频或触发后续事件。 OP 想知道为什么会这样。
  • @JustCarty 检查我的解决方案

标签: c# windows audio speech-recognition cscore


【解决方案1】:

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

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

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

更多阅读Following Article,它解释了正确的实现方式

【讨论】:

  • 不使用其他DLL就没有办法吗?
猜你喜欢
  • 1970-01-01
  • 2019-04-12
  • 2018-01-27
  • 2019-05-05
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多