语音识别引擎不关机 - 无效操作异常 [英] Speech Recognition Engine does not shut down - invalid operation exception
问题描述
决定要连接一个简单的演讲书面申请作为测试床学习语音识别+ F#。以允许语音识别来开始或停止我有线了下列方法:
让激活()=
sp.RecognizeAsync(RecognizeMode.Multiple) 让停用()=
sp.RecognizeAsyncCancel()
sp.RecognizeAsyncStop()
我就可以开始使用默认语法词典发动机罚款。问题来了whens我称之为停用方法。我经常收到以下异常:
'System.InvalidOperationException'类型的未处理的异常出现在System.Speech.dll 其他信息:当识别器识别做无法执行此操作。
请参阅这里。
有似乎与你的code两个问题:
-
您应该调用
RecognizeAsyncCancel
或RecognizeAsyncStop
,但不能同时使用。他们这样做只是同样的事情RecognizeAysncCancel
截断输入,而RecognizeAsyncStop
没有。我猜,叫他们两人一排是导致你所看到的错误。 -
两者
RecognizeAsyncCancel
和RecognizeAsyncStop
有当他们完成回调。直到最后的操作完成你不应该做任何事情的引擎。见链接,如何做到这一点的例子。
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.
See here.
There appear to be two issues with your code:
You should either call
RecognizeAsyncCancel
orRecognizeAsyncStop
, but not both. They do the same thing except thatRecognizeAysncCancel
truncates the input whileRecognizeAsyncStop
doesn't. I'm guessing that calling both of them in a row is causing the error you're seeing.Both
RecognizeAsyncCancel
andRecognizeAsyncStop
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.
这篇关于语音识别引擎不关机 - 无效操作异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!