Search code examples
windowsspeech-recognitionsapi

Is it possible to only load a dictation topic while using Shared Recogniser and not with Inproc reconizer in sapi?


When I am using a shared recognizer to a previously registered medical dictation topic , dictation grammar is loaded without error but when I change my recognizer to Inproc recognizer it is not able to load a dictation topic. Is there a way to load dictation topic while still using in proc recognizer?

My code for Loading grammar looks like

      CComPtr<ISpObjectToken>      cpObjectToken;
      CComPtr<ISpAudio>            cpAudio;
      CComPtr<ISpRecognizer> cpEngine;
      CComPtr<ISpRecoContext> cpRecoCtx;
      CComPtr<ISpRecoGrammar> cpGram;
      hr = cpEngine.CoCreateInstance(CLSID_SpInprocRecognizer);
      hr = SpGetDefaultTokenFromCategoryId(SPCAT_AUDIOIN, &cpObjectToken);
      hr = cpEngine->SetInput(cpObjectToken, TRUE);
      hr = SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &cpAudio);
      hr = cpEngine->SetInput(cpAudio, TRUE);
      hr = cpEngine->CreateRecoContext(&cpRecoCtx);
      hr = cpEngine->SetRecognizer(NULL);
      hr = cpRecoCtx->CreateGrammar(1, &cpGram);
      hr = cpGram->LoadDictation(L"Medical", SPLO_STATIC);

Solution

  • Inproc recognizers don't have a default SR engine, so calling

    hr = cpEngine->SetRecognizer(NULL);
    

    won't actually load an engine. I wrote a simple function to load the default recognizer; the code's longish, so I won't put it inline, but you can find it here.

    Also, in your other question, you had the topic named "Medical", and here you have it named "Medicine"; they do need to be the same.