Guest User

Untitled

a guest
Jun 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. bool SapiRecognizerImpl::Text(std::wstring & rText)
  2. {
  3. HRESULT hr;
  4. SPSTATEHANDLE dictHandle = 0;
  5.  
  6. // that's what I tried to do, didn't help though
  7. // {
  8. ISpVoice *pVoice;
  9. if (SUCCEEDED(m_pIncomingRecoCtx->GetVoice(&pVoice)))
  10. {
  11. pVoice->Skip(L"SENTENCE", 100, 0);
  12. pVoice->Release();
  13. }
  14. // }
  15.  
  16. hr = m_pDictGrammar->SetDictationState(SPRS_ACTIVE);
  17. if (FAILED(hr))
  18. {
  19. return false;
  20. }
  21.  
  22. while (true)
  23. {
  24. CSpEvent event;
  25. hr = m_pIncomingRecoCtx->WaitForNotifyEvent(8000);
  26. if (SUCCEEDED(hr))
  27. {
  28. hr = event.GetFrom(m_pIncomingRecoCtx);
  29. }
  30.  
  31. if (hr == S_OK && event.eEventId == SPEI_PHRASE_START)
  32. {
  33. hr = m_pIncomingRecoCtx->WaitForNotifyEvent(INFINITE);
  34. if (hr == S_OK)
  35. {
  36. hr = event.GetFrom(m_pIncomingRecoCtx);
  37. assert(event.eEventId == SPEI_RECOGNITION || event.eEventId == SPEI_FALSE_RECOGNITION);
  38. }
  39. }
  40. else
  41. {
  42. continue;
  43. }
  44.  
  45. WCHAR *pText = NULL;
  46. ISpRecoResult *pResult = NULL;
  47. if (SUCCEEDED(hr) && event.eEventId == SPEI_RECOGNITION)
  48. {
  49. pResult = event.RecoResult();
  50. BYTE bDisplayAttr;
  51. hr = pResult->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, FALSE, &pText, &bDisplayAttr);
  52. }
  53. if (SUCCEEDED(hr) && pResult)
  54. {
  55. rText = pText;
  56. }
  57. if (pText)
  58. {
  59. ::CoTaskMemFree(pText);
  60. }
  61. if (!rText.empty())
  62. {
  63. break;
  64. }
  65. }
  66.  
  67. if (SUCCEEDED(hr))
  68. {
  69. hr = m_pDictGrammar->SetDictationState(SPRS_INACTIVE);
  70. }
  71.  
  72. return SUCCEEDED(hr);
  73. }
Add Comment
Please, Sign In to add comment