【问题标题】:Creating a In proc speech recognition using sapi c#?使用 sapi c# 创建 In proc 语音识别?
【发布时间】:2014-06-24 07:31:07
【问题描述】:

我用于设置 in proc 识别引擎的 SAPI 代码如下所示:

ISpeechRecoContext cpRecoCtx;
// create the recognition context
cpRecoCtx = new SpeechLib.SpInProcRecoContext();

((SpInProcRecoContext)cpRecoCtx).Recognition +=
    new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
/****** END: set up recognition context *****/

那么如何在 C# 中将我的音频输入设置为默认音频输入?我在 C++ 中找到了解决方案,但需要一个用于 C# 的解决方案。

【问题讨论】:

  • 您提供的代码不完整。特别是,您需要指定识别器引擎以及输入源。

标签: c# speech-recognition sapi


【解决方案1】:

默认的音频输入对象是SpMMAudioIn

ISpeechRecoContext cpRecoCtx;
SpMMAudioIn audio = new SpMMAudioIn;
// set the audio input
cpRecoCtx.GetRecognizer.SetInput(audio);

【讨论】:

    【解决方案2】:

    Eric,您的代码不起作用。首先,没有“GetRecognizer”方法。我已经用应该工作的方式替换了那条线。您指的是哪个版本的 SAPI?我正在使用“Microsoft Speech Object libary 5.4”。接下来,您不会展示如何将音频输入设置为您提到的设备。下面的代码应该可以工作,但它不允许您设置设备 ID,这在 VB6 中一直有效。尝试将 .DeviceID 设置为任何内容都会引发异常:

    SpeechLib.ISpeechRecoContext cpRecoCtx;
    cpRecoCtx = new SpeechLib.SpInProcRecoContext();
    SpeechLib.SpMMAudioIn audio = new SpeechLib.SpMMAudioIn();
    // set the audio input
    // cpRecoCtx.GetRecognizer.SetInput(audio); <--- no such method
    audio.DeviceId = 1;
    cpRecoCtx.Recognizer.AudioInputStream = audio;
    

    当然,有一种方法可以将输入发送到有效的 MMSYS (WaveInOpen) 输入流。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      相关资源
      最近更新 更多