Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool SapiRecognizerImpl::Text(std::wstring & rText)
- {
- HRESULT hr;
- SPSTATEHANDLE dictHandle = 0;
- // that's what I tried to do, didn't help though
- // {
- ISpVoice *pVoice;
- if (SUCCEEDED(m_pIncomingRecoCtx->GetVoice(&pVoice)))
- {
- pVoice->Skip(L"SENTENCE", 100, 0);
- pVoice->Release();
- }
- // }
- hr = m_pDictGrammar->SetDictationState(SPRS_ACTIVE);
- if (FAILED(hr))
- {
- return false;
- }
- while (true)
- {
- CSpEvent event;
- hr = m_pIncomingRecoCtx->WaitForNotifyEvent(8000);
- if (SUCCEEDED(hr))
- {
- hr = event.GetFrom(m_pIncomingRecoCtx);
- }
- if (hr == S_OK && event.eEventId == SPEI_PHRASE_START)
- {
- hr = m_pIncomingRecoCtx->WaitForNotifyEvent(INFINITE);
- if (hr == S_OK)
- {
- hr = event.GetFrom(m_pIncomingRecoCtx);
- assert(event.eEventId == SPEI_RECOGNITION || event.eEventId == SPEI_FALSE_RECOGNITION);
- }
- }
- else
- {
- continue;
- }
- WCHAR *pText = NULL;
- ISpRecoResult *pResult = NULL;
- if (SUCCEEDED(hr) && event.eEventId == SPEI_RECOGNITION)
- {
- pResult = event.RecoResult();
- BYTE bDisplayAttr;
- hr = pResult->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, FALSE, &pText, &bDisplayAttr);
- }
- if (SUCCEEDED(hr) && pResult)
- {
- rText = pText;
- }
- if (pText)
- {
- ::CoTaskMemFree(pText);
- }
- if (!rText.empty())
- {
- break;
- }
- }
- if (SUCCEEDED(hr))
- {
- hr = m_pDictGrammar->SetDictationState(SPRS_INACTIVE);
- }
- return SUCCEEDED(hr);
- }
Add Comment
Please, Sign In to add comment