我使用的是这里给出的C++代码。但这里使用的共享语音识别运行自己的命令,如移动、最小化、删除。我需要在不调用MS语音识别程序的情况下创建它。
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