【问题标题】:Speech recognition in .net problem.net 中的语音识别问题
【发布时间】:2011-03-29 00:42:30
【问题描述】:

我是语音识别的新手,我开发了一个文本编辑器,可以写下我对它说的话。我遇到了一个问题,我可以通过代码启用语音识别,但不能禁用它。谁能建议如何禁用语音识别。我的语音识别代码如下:

//function to start/stop speech recognition

private void enableSpeechRecognitionToolStripMenuItem_Click(object sender, EventArgs e)
{
   listener = new SpeechLib.SpSharedRecoContext();
   //crating a share recognition object
   listener.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(listener_Reco);
   //creating a recgnition event handler object
   grammar = listener.CreateGrammar(0);
   //create grammar interface with ID = 0
   grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
   //setting grammar load type to static
   grammar.DictationSetState(SpeechRuleState.SGDSActive);
   //activating speech dictation
   enableSpeechRecognitionToolStripMenuItem.Checked = true;
   //checked
   toolStripStatusLabel1.Text = "[Speech Recognition Enabled]"; 
}

//function to append the listened text to the text box's text
public void listener_Reco(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
   string heard = Result.PhraseInfo.GetText(0, -1, true);
   //setting heard text to a variable
   richTextBox1.Text += " " + heard;
   //appending heard text
}

【问题讨论】:

    标签: c#-4.0 speech-recognition


    【解决方案1】:

    如果我没记错的话,SpeechLib 是 SAPI API 周围的 COM 互操作包装器。在System.Speech 中使用本机 .NET 托管语音类可能会更好。 https://stackoverflow.com/questions/5101119/looking-for-a-book-on-net-speech-recognition/5118157#5118157 中提到的 MSDN article 是一个很好的起点。我在What is the best option for transcribing speech-to-text in a asp.net web app? 中发布了一个很好的简单示例来帮助入门。

    我认为您也在使用共享识别器。如果您使用自己的 inproc SpeechRecognitionEngine 实例,您将对识别有更多控制权。共享识别器用于可以控制 windows 桌面或多个应用程序的应用程序。

    【讨论】:

      【解决方案2】:

      您是否尝试在要禁用语音识别时删除识别处理程序?

      请参阅此question,了解如何删除事件处理程序的示例。

      【讨论】:

      • 我无法删除识别处理程序。你能告诉我我该怎么做吗?
      • 编辑了我的回复以包含删除处理程序的示例。
      【解决方案3】:

      您是否尝试过更改规则状态或识别器状态?例如,尝试

      grammar.DictationSetState(SpeechRuleState.SGDSInactive);
      

      我也同意 Michael 的观点,您可能想要一个 inproc 识别引擎,而不是共享引擎。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多