Speech Recognition Engine does not shut down - invalid operation exception

牧云@^-^@ 提交于 2019-12-24 03:58:15

问题


Decided to wire up a simple speech writing application as a test bed for learning Speech Recognition + F#. To allow the speech recognition to be started or stopped I wired up the following methods:

 let Activate () = 
     sp.RecognizeAsync(RecognizeMode.Multiple)

 let Deactivate () = 
     sp.RecognizeAsyncCancel()
     sp.RecognizeAsyncStop()

I can start the engine fine with the default grammar dictionary. The problem comes whens I call the deactivate method. I often get the following exception:

 An unhandled exception of type 'System.InvalidOperationException' occurred in System.Speech.dll

 Additional information: Cannot perform this operation while the recognizer is doing recognition.

回答1:


See here.

There appear to be two issues with your code:

  1. You should either call RecognizeAsyncCancel or RecognizeAsyncStop, but not both. They do the same thing except that RecognizeAysncCancel truncates the input while RecognizeAsyncStop doesn't. I'm guessing that calling both of them in a row is causing the error you're seeing.

  2. Both RecognizeAsyncCancel and RecognizeAsyncStop have callbacks for when they are complete. You shouldn't do anything else with the engine until the final operation is complete. See the link for an example of how to do this.



来源:https://stackoverflow.com/questions/17937305/speech-recognition-engine-does-not-shut-down-invalid-operation-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!