wxWidgets and microsoft SAPI for speech recognition
-
- Knows some wx things
- Posts: 27
- Joined: Fri Jun 28, 2013 2:14 pm
- Location: tehran, iran
- Contact:
wxWidgets and microsoft SAPI for speech recognition
hello everyone
i'm coding a software that requires the speech recognition events (i need to use ISpNotifySource and other stuff) with speech recognition in order to get speech recognition
but i dont know how can i assign windows events (things that are passed to window proc function of the window in order for it to be processed)
if it is possible to use custom events, please tell me how to use that, or what can i do in order to make it work?
i'm coding a software that requires the speech recognition events (i need to use ISpNotifySource and other stuff) with speech recognition in order to get speech recognition
but i dont know how can i assign windows events (things that are passed to window proc function of the window in order for it to be processed)
if it is possible to use custom events, please tell me how to use that, or what can i do in order to make it work?
Re: wxWidgets and microsoft SAPI for speech recognition
Override
Code: Select all
WXLRESULT wxWindow::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
Use the source, Luke!
-
- Knows some wx things
- Posts: 27
- Joined: Fri Jun 28, 2013 2:14 pm
- Location: tehran, iran
- Contact:
Re: wxWidgets and microsoft SAPI for speech recognition
hello,doublemax wrote:OverrideCode: Select all
WXLRESULT wxWindow::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
i've overrided this and an access vialation occured
this is the function that i've implemented
Code: Select all
//our window proc
WXLRESULT window::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
switch(nMsg)
{
case event_sr:
sr_event();
}
return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
}
Code: Select all
//speech recognition callback
void sr_event()
{
//speech recognizer event:
CSpEvent e;
while(e.GetFrom(context)==S_OK)
{
switch(e.eEventId)
{
case SPEI_HYPOTHESIS:
{
wxMessageBox(get_stt_text(e), "info", wxOK|wxICON_INFORMATION, nullptr, wxDefaultCoord, wxDefaultCoord);
}
}
}
}
maybe MSWWindowProc() is called before app::OnInit()? because i initialize my speech recognition there
and, this is the sr_event macro:
Code: Select all
#define sr_event WM_USER+1
Re: wxWidgets and microsoft SAPI for speech recognition
It's probably not the reason for the crash, but you shouldn't call wxMessageBox from there. Use wxLogDebug for non-intrusive debug logging.
What is your code based on? I only know code for TTS using SAPI and the event handling looks different there:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
What is your code based on? I only know code for TTS using SAPI and the event handling looks different there:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
Use the source, Luke!
-
- Knows some wx things
- Posts: 27
- Joined: Fri Jun 28, 2013 2:14 pm
- Location: tehran, iran
- Contact:
Re: wxWidgets and microsoft SAPI for speech recognition
ok, let me explain it:doublemax wrote:It's probably not the reason for the crash, but you shouldn't call wxMessageBox from there. Use wxLogDebug for non-intrusive debug logging.
What is your code based on? I only know code for TTS using SAPI and the event handling looks different there:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
in app::OnInit(), beside creation of the window, it initializes com then creates the interfaces for speech recognition
after showing the window, it sets the window handle with w->GetHandle() as speech recognition's notify window with the event of event_sr which is processed in the MSWWindowProc() function
this is the OnInit code:
Code: Select all
bool app::OnInit()
{
//initialize com
if(CoInitializeEx(nullptr, COINIT_MULTITHREADED)==S_FALSE)
{
return false;
}
//set application name and vendor names:
SetAppDisplayName("myCrew");
SetAppName("myCrew");
SetClassName("myCrew");
SetVendorDisplayName("amir ramezani");
SetVendorName("amir ramezani");
//create our window:
w=new window();
//set it as top-level window (if closed, the app will be quit)
SetTopWindow(w);
//show it
w->Show();
//center the window
w->Center();
//initialize speech recognition
hr=CoCreateInstance(CLSID_SpSharedRecognizer, nullptr, CLSCTX_ALL, IID_ISpRecognizer, reinterpret_cast<void**>(&recognizer));
if(FAILED(hr))
{
return false;
}
//create speech recognition context manager
hr=recognizer->CreateRecoContext(&context);
if(FAILED(hr))
{
return false;
}
//set intrest for our event
const ULONGLONG interest = SPFEI(SPEI_SOUND_START) | SPFEI(SPEI_SOUND_END) |
SPFEI(SPEI_PHRASE_START) | SPFEI(SPEI_RECOGNITION) |
SPFEI(SPEI_FALSE_RECOGNITION) | SPFEI(SPEI_HYPOTHESIS) |
SPFEI(SPEI_INTERFERENCE) | SPFEI(SPEI_RECO_OTHER_CONTEXT) |
SPFEI(SPEI_REQUEST_UI) | SPFEI(SPEI_RECO_STATE_CHANGE) |
SPFEI(SPEI_PROPERTY_NUM_CHANGE) | SPFEI(SPEI_PROPERTY_STRING_CHANGE);
hr=context->SetInterest(interest, interest);
if(FAILED(hr))
{
return false;
}
//create the grammar
hr=context->CreateGrammar(maingramid, &main_grammar);
if(FAILED(hr))
{
return false;
}
//load dictation into our grammar
hr=main_grammar->LoadDictation(0, SPLO_STATIC);
if(FAILED(hr))
{
return false;
}
//make our dictation active
hr=main_grammar->SetDictationState(SPRS_ACTIVE);
if(FAILED(hr))
{
return false;
}
//set our event thing
hr=context->SetNotifyWindowMessage(w->GetHandle(), event_sr, 0, 0);
if(FAILED(hr))
{
return false;
}
//return true to continue execution
return true;
}
in the event loop of the speech recognition that i've called, it shows that context which is of type ISpRecoContext is null and CspEvent gives error
this is the code of my event:
Code: Select all
//speech recognition callback
void sr_event()
{
//speech recognizer event:
CSpEvent e;
while(e.GetFrom(context)==S_OK)
{
switch(e.eEventId)
{
case SPEI_HYPOTHESIS:
{
wxMessageBox(get_stt_text(e), "info", wxOK|wxICON_INFORMATION, nullptr, wxDefaultCoord, wxDefaultCoord);
}
}
}
}
maybe the window proc is called before app::OnInit()?
-
- Knows some wx things
- Posts: 27
- Joined: Fri Jun 28, 2013 2:14 pm
- Location: tehran, iran
- Contact:
Re: wxWidgets and microsoft SAPI for speech recognition
hi again,
another thing that comes to my mind is using custom events although i have no clew how to do that (with windows events as they have wParam and lParam)
another thing that comes to my mind is using custom events although i have no clew how to do that (with windows events as they have wParam and lParam)
Re: wxWidgets and microsoft SAPI for speech recognition
Can you provide a complete, compilable sample?
Just for a test, don't initialize the speech api immediately. Do it only after clicking a button/selecting a menu entry.
Just for a test, don't initialize the speech api immediately. Do it only after clicking a button/selecting a menu entry.
Use the source, Luke!
Re: wxWidgets and microsoft SAPI for speech recognition
I do not have any experience with SAPI, but this sample using Windows message queue looks that pretty simple and easy to "translate" to wxWidgets code:
https://github.com/pauldotknopf/Windows ... edictation. It only gets the text, the more complex one is the dictation pad example.
https://github.com/pauldotknopf/Windows ... edictation. It only gets the text, the more complex one is the dictation pad example.