Logo

bool sapi_lipsync::initializeObjects  ) 
 

this method performs common initialization of SAPI objects

This method initializes SAPI and creates the objects used by subclasses, it does not start the lipsync process.

Definition at line 132 of file sapi_lipsync.cpp.

00133 {
00134     HRESULT hr = S_OK;
00135     m_err = L"";
00136     try
00137     {
00138         // create the recognizer (inproc)
00139         hr = this->m_recog.CoCreateInstance(CLSID_SpInprocRecognizer);
00140         if (hr != S_OK) 
00141         {
00142             m_err = L"Error: Can't create SAPI Speech Recognizer (ISpRecognizer)";
00143             throw (hr);
00144         }
00145 
00146         // create the recognition context from the recognizer
00147         hr = this->m_recog->CreateRecoContext(&this->m_recogCntxt);
00148         if (hr != S_OK)
00149         {
00150             m_err = L"Error: Cannot create SAPI Recognition Context (ISpRecoContext)";
00151             throw (hr);
00152         }            
00153 
00154         hr = m_recogCntxt->SetNotifyCallbackFunction(&this->sapi_callback, 0, LPARAM(this));
00155         if (hr != S_OK)
00156         {
00157             m_err = L"Error: Cannot set notify callback function. (SetNofifyCallbackFunction)";
00158             throw (hr);
00159         }
00160         // initialize and disable the grammar
00161         hr = m_recogCntxt->CreateGrammar(GID_LIPSYNC, &m_grammar);
00162         if (hr != S_OK)
00163         {
00164             m_err = L"Error: Failed to create grammar for lipsync";
00165             throw (hr);
00166         }
00167         // not totally sure here!
00168         //hr = m_grammar->SetGrammarState(SPGS_DISABLED); Let subclasses handle the grammer state
00169         if (hr != S_OK)
00170         {
00171             m_err = L"Error: Failed to disable the grammar.";
00172             throw (hr);
00173         }
00174 
00175         // need a phoneme converter to map SPHONEID into phoneme strings
00176         hr = SpCreatePhoneConverter(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 
00177             NULL, NULL, &this->m_phnCvt);
00178         if (hr != S_OK)
00179         {
00180             m_err = L"Error: Failed create phoneme converter";
00181             throw (hr);
00182         }
00183 
00184         // Set interest level for events, we want all events, just in case.                
00185         hr = m_recogCntxt->SetInterest(ullInterest, ullInterest);
00186         if (hr != S_OK)
00187         {
00188             m_err = L"Error: Cannot correctly set notifications for the Speech Recognizer";
00189             throw(hr);
00190         }
00191         // turn off recognizer while we initialize things. HMMM
00192         //m_recog->SetRecoState(SPRST_INACTIVE);
00193     } 
00194     catch (HRESULT& _hr)
00195     {
00196         hr = _hr;
00197     }
00198     return (hr == S_OK);
00199 }


Copyright (C) 2002-2005 Annosoft LLC. All Rights Reserved.
Visit us at www.annosoft.com