Search code examples
c++visual-studiospeech-recognitionsapihresult

Error when testing Windows Speech Recognition API (SAPI)


I am trying to test the following example: Test of Speech Recognition using Windows SAPI

The code compiles well But It crashes in execution.

The returned pointer to ISpRecognizer Object takes the values NULL as shown in the following code :

// This function exits when the word passed as parameter is said by the user
int start_listening(const std::string& word)
{
.....

HRESULT hr;

ISpRecognizer* recognizer;
hr = CoCreateInstance(CLSID_SpSharedRecognizer,
    nullptr, CLSCTX_ALL, IID_ISpRecognizer,
    reinterpret_cast<void**>(&recognizer)); <<<<<ERROR: recognizer =NULL


<<< hr = REGDB_E_CLASSNOTREG<< MEAN "class not registered"

check_result(hr); 

ISpRecoContext* recoContext;
hr = recognizer->CreateRecoContext(&recoContext);<<<<CRASH: TRY TO ACCESS TO 
                                                 <<<<  A NULL  POINTER
...
...
...

I am using visual studio 2015 on windows 8.1 and targeting x64 platform.

Do you know why the pointer to ISPRecognizer is NULL and why I am getting HRESULT=REGDB_E_CLASSNOTREG ?


Solution

  • I'm thinking that you're not calling ::CoInitialize() beforehand, and not properly initializing your ISpReognizer. I've got a fully working example as an answer to another question over here.