使用SAPI创建个人语音识别系统
问题描述:
我使用的是C++代码here。但这里使用的共享语音识别运行自己的命令,如移动,最小化,删除。我需要在不调用MS语音识别程序的情况下创建它。使用SAPI创建个人语音识别系统
hr = cpEngine.CoCreateInstance(CLSID_SpSharedRecognizer);
上面这一行创建共享实例。
我试着用CLSID_SpInprocRecognizer代替,但不能正确的。我对此很陌生。 有没有办法做到这一点?
答
我在这里遇到同样的问题,并花了很多时间试图找到答案。
- 不要使用过程中的识别器,如果你想摆脱MS语音识别程序
hr = cpRecognizer.CoCreateInstance(CLSID_SpInprocRecognizer);
的:幸运的是,我已经通过以下步骤得到了解决2.进程内识别器没有设置默认输入源或识别引擎,您需要将它们设置为让进程内识别器进行侦听。
CComPtr<ISpObjectToken> cpObjectToken;
CComPtr<ISpAudio> cpAudio;
// Get the default audio input token.
hr = SpGetDefaultTokenFromCategoryId(SPCAT_AUDIOIN, &cpObjectToken);
// Set the audio input to our token.
hr = cpRecognizer->SetInput(cpObjectToken, TRUE);
// Set up the inproc recognizer audio input with an audio input object.
// Create the default audio input object.
hr = SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &cpAudio);
// Set the audio input to our object.
hr = cpRecognizer->SetInput(cpAudio, TRUE);
3.指定要使用的特定语音识别引擎。如果没有指定,它将使用默认值。如果它没有被调用,它仍然使用默认的(我推荐这条线,仍然工作正常)。
hr = cpRecognizer->SetRecognizer(NULL);
就是这样!它打开了一个默认的美国英语识别引擎,并且很快就提取了我的命令。
参考:
http://stackoverflow.com/questions/18448394/inproc-speech-recognition-engine-in-python
http://msdn.microsoft.com/en-us/library/ms718864%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms718866%28v=vs.85%29.aspx
哇从过去的爆炸。我在没有进程中的识别器的情况下完成了我的项目。但是会尝试用这个来重写它。 – AlphaWolf 2013-12-11 04:34:44
这里的诀窍是让识别器开始聆听,第2步这样做。玩的开心! :p – sophia 2013-12-16 20:47:56