2011-03-26 39 views
0

我是新來的語音識別系統,並且開發了一個文本編輯器來編寫我所說的內容。我遇到了可以通過代碼啓用語音識別的問題,但無法禁用它。任何人都可以請建議如何禁用語音識別。我的語音識別代碼如下:.net問題中的語音識別

//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 
} 

回答

0

您是否嘗試過在要禁用語音識別時刪除識別處理程序?

有關如何刪除事件處理程序的示例,請參閱此question

+0

我無法刪除識別處理程序。你能告訴我,我能怎麼做? – impiyush 2011-03-26 15:08:28

+0

編輯我的回覆以包含刪除處理程序的示例。 – Jason 2011-03-27 01:29:29

1

如果我沒有弄錯,SpeechLib是一個圍繞SAPI API的COM互操作包裝。在System.Speech中使用本機.NET Managed Speech類可能會更好。在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桌面或多個應用程序的應用程序。

0

您是否嘗試過更改規則狀態或識別器狀態?例如,試試

grammar.DictationSetState(SpeechRuleState.SGDSInactive); 

我也同意邁克爾,你可能想要一個inproc識別引擎,而不是共享引擎。