Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- code/sound/phrases.xml | 66 +++++------
- code/sound/voicerec.cpp | 299 ++++++++++++++++++++++++------------------------
- 2 files changed, 184 insertions(+), 181 deletions(-)
- diff --git a/code/sound/phrases.xml b/code/sound/phrases.xml
- index 0e93614..45207a2 100644
- --- a/code/sound/phrases.xml
- +++ b/code/sound/phrases.xml
- @@ -1,6 +1,6 @@
- <GRAMMAR>
- <DEFINE>
- - <ID NAME="VID_Counter" VAL="80"/>
- + <ID NAME="VID_Counter" VAL="80"/>
- <ID NAME="VID_DestroyTarget" VAL="10"/>
- <ID NAME="VID_DisableTarget" VAL="11"/>
- <ID NAME="VID_DisarmTarget" VAL="12"/>
- @@ -35,30 +35,30 @@
- <RULE ID="VID_WingName" TOPLEVEL="ACTIVE">
- <L PROPID="VID_WingName">
- - <P VAL="0">Alpha</P>
- - <P VAL="1">Beta</P>
- - <P VAL="2">Gamma</P>
- - <P VAL="3">Delta</P>
- - <P VAL="4">Epsilon</P>
- - <P VAL="5">Zeta</P>
- - <P VAL="6">Eta</P>
- - <P VAL="7">Theta</P>
- - <P VAL="8">Iota</P>
- - <P VAL="9">Kappa</P>
- - <P VAL="10">Lambda</P>
- - <P VAL="11">Mu</P>
- - <P VAL="12">Nu</P>
- - <P VAL="13">Xi</P>
- - <P VAL="14">Omicron</P>
- - <P VAL="15">Pi</P>
- - <P VAL="16">Rho</P>
- - <P VAL="17">Sigma</P>
- - <P VAL="18">Tau</P>
- - <P VAL="19">Upsilon</P>
- - <P VAL="20">Phi</P>
- - <P VAL="21">Chi</P>
- - <P VAL="22">Psi</P>
- - <P VAL="23">Omega</P>
- + <P VALSTR="Alpha">Alpha</P>
- + <P VALSTR="Beta">Beta</P>
- + <P VALSTR="Gamma">Gamma</P>
- + <P VALSTR="Delta">Delta</P>
- + <P VALSTR="Epsilon">Epsilon</P>
- + <P VALSTR="Zeta">Zeta</P>
- + <P VALSTR="Eta">Eta</P>
- + <P VALSTR="Theta">Theta</P>
- + <P VALSTR="Iota">Iota</P>
- + <P VALSTR="Kappa">Kappa</P>
- + <P VALSTR="Lambda">Lambda</P>
- + <P VALSTR="Mu">Mu</P>
- + <P VALSTR="Nu">Nu</P>
- + <P VALSTR="Xi">Xi</P>
- + <P VALSTR="Omicron">Omicron</P>
- + <P VALSTR="Pi">Pi</P>
- + <P VALSTR="Rho">Rho</P>
- + <P VALSTR="Sigma">Sigma</P>
- + <P VALSTR="Tau">Tau</P>
- + <P VALSTR="Upsilon">Upsilon</P>
- + <P VALSTR="Phi">Phi</P>
- + <P VALSTR="Chi">Chi</P>
- + <P VALSTR="Psi">Psi</P>
- + <P VALSTR="Omega">Omega</P>
- </L>
- <L PROPID="VID_ShipName">
- <P VAl="0">Wing</P>
- @@ -87,26 +87,26 @@
- <P VAL="VID_IgnoreTarget">Ignore my target</P>
- <P VAL="VID_FormWing">Form on my wing</P>
- <P VAL="VID_CoverMe">Cover me</P>
- - <P VAL="VID_EngageEnemy">Engage Enemy</P>
- + <P VAL="VID_EngageEnemy">Engage the Enemy</P>
- <P VAL="VID_EngageEnemy">Attack</P>
- <P VAL="VID_Depart">Depart</P>
- </L>
- </RULE>
- <RULE ID="VID_TopMenu" TOPLEVEL="ACTIVE">
- - <L PROPID="VID_TopMenu">
- + <L PROPID="VID_TopMenu">
- <P VAL="VID_Ships">Ships</P>
- <P VAL="VID_Wings">Wings</P>
- <P VAL="VID_AllFighters">All Fighters<O><RULEREF REFID="VID_Action"/></O></P>
- <P VAL="VID_AllWings">All Wings<O><RULEREF REFID="VID_Action"/></O></P>
- <P VAL="VID_Reinforcements">Reinforcements</P>
- <P VAL="VID_SupportShip">Support ship</P>
- - <P VAL="VID_SupportShip">Rearm</P>
- - <P VAL="VID_SupportShip">Repair</P>
- - <P VAL="VID_AbortSupport">Abort</P>
- + <P VAL="VID_SupportShip">Rearm <O>and repair</O></P>
- + <P VAL="VID_SupportShip">Repair <O>and rearm</O></P>
- + <P VAL="VID_AbortSupport">Abort <L><P>support <O>ship</O></P><P>rearm <O>and repair</O></P><P>repair <O>and rearm</O></P></L></P>
- <P VAL="VID_Cancel">Cancel</P>
- <P VAL="VID_Command">Command</P>
- - <P VAL="VID_More">More</P>
- + <P VAL="VID_More">More</P>
- </L>
- </RULE>
- @@ -144,9 +144,9 @@
- <P VAL="91">Target previous uninspected</P>
- <P VAL="92">Target newest</P>
- <P VAL="93">Target next turret</P>
- - <P VAL="94">Target previous turrent</P>
- + <P VAL="94">Target previous turret</P>
- <P VAL="95">Target next bomb</P>
- - <P VAL="96">Target previous bomb</P>
- + <P VAL="96">Target previous bomb</P>
- </L>
- </RULE>
- diff --git a/code/sound/voicerec.cpp b/code/sound/voicerec.cpp
- index 70e847d..80a5230 100644
- --- a/code/sound/voicerec.cpp
- +++ b/code/sound/voicerec.cpp
- @@ -112,104 +112,118 @@ void doVid_Action(int action)
- bool VOICEREC_init(HWND hWnd, int event_id, int grammar_id, int command_resource)
- {
- - HRESULT hr = S_OK;
- - CComPtr<ISpAudio> cpAudio;
- -
- - while (true)
- - {
- - // create a recognition engine
- - hr = p_recogEngine.CoCreateInstance(CLSID_SpSharedRecognizer);
- - if (FAILED(hr))
- - {
- + HRESULT hr = S_OK;
- + CComPtr<ISpAudio> cpAudio;
- +
- + while (true)
- + {
- + // create a recognition engine
- + hr = p_recogEngine.CoCreateInstance(CLSID_SpInprocRecognizer);
- + if (FAILED(hr))
- + {
- MessageBox(hWnd,"Failed to create a recognition engine\n","Error",MB_OK);
- printf("Failed to create a recognition engine\n");
- - break;
- - }
- -
- - // create the command recognition context
- - hr = p_recogEngine->CreateRecoContext( &p_recogContext );
- - if (FAILED(hr))
- - {
- + break;
- + }
- +
- + // create the command recognition context
- + hr = p_recogEngine->CreateRecoContext( &p_recogContext );
- + if (FAILED(hr))
- + {
- MessageBox(hWnd,"Failed to create the command recognition context\n","Error",MB_OK);
- printf("Failed to create the command recognition context\n");
- - break;
- - }
- -
- - // Let SR know that window we want it to send event information to, and using
- - // what message
- - hr = p_recogContext->SetNotifyWindowMessage( hWnd, event_id, 0, 0 );
- - if (FAILED(hr))
- - {
- + break;
- + }
- +
- + // Let SR know that window we want it to send event information to, and using
- + // what message
- + hr = p_recogContext->SetNotifyWindowMessage( hWnd, event_id, 0, 0 );
- + if (FAILED(hr))
- + {
- MessageBox(hWnd,"Failed to SetNotifyWindowMessage\n","Error",MB_OK);
- - break;
- - }
- -
- - // Tell SR what types of events interest us. Here we only care about command
- - // recognition.
- - hr = p_recogContext->SetInterest( SPFEI(SPEI_RECOGNITION), SPFEI(SPEI_RECOGNITION) );
- - if (FAILED(hr))
- - {
- + break;
- + }
- +
- + // Tell SR what types of events interest us. Here we only care about command
- + // recognition.
- + hr = p_recogContext->SetInterest( SPFEI(SPEI_RECOGNITION), SPFEI(SPEI_RECOGNITION) );
- + if (FAILED(hr))
- + {
- MessageBox(hWnd,"Failed to set events\n","Error",MB_OK);
- - break;
- - }
- + break;
- + }
- // Create a grammar
- - hr = p_recogContext->CreateGrammar(grammar_id, &p_grammarObject);
- - if (FAILED(hr))
- - {
- + hr = p_recogContext->CreateGrammar(grammar_id, &p_grammarObject);
- + if (FAILED(hr))
- + {
- MessageBox(hWnd,"Failed to create grammar\n","Error",MB_OK);
- - break;
- - }
- + break;
- + }
- - // Load our grammar from data\phrases.xml, or if that doesn't exist, from the compiled in
- - // user defined ("SRGRAMMAR") resource type.
- + // Load our grammar from data\phrases.xml, or if that doesn't exist, from the compiled in
- + // user defined ("SRGRAMMAR") resource type.
- hr = p_grammarObject->LoadCmdFromFile(L"data\\phrases.xml", SPLO_STATIC);
- - if (FAILED(hr))
- - {
- + if (FAILED(hr))
- + {
- hr = p_grammarObject->LoadCmdFromResource(NULL, MAKEINTRESOURCEW(command_resource),
- - L"SRGRAMMAR", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
- - SPLO_DYNAMIC);
- + L"SRGRAMMAR", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
- + SPLO_STATIC);
- if (FAILED(hr))
- {
- MessageBox(hWnd,"Failed to load resource\n","Error",MB_OK);
- - break;
- + break;
- }
- - }
- + }
- +
- + hr = SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &cpAudio);
- + if (FAILED(hr))
- + {
- + MessageBox(hWnd,"Failed to get default audio input\n", "Error", MB_OK);
- + break;
- + }
- - // Set rules to active, we are now listening for commands
- - hr = p_grammarObject->SetRuleState(NULL, NULL, SPRS_ACTIVE );
- - if (FAILED(hr))
- - {
- + // Set the audio input to our token.
- + hr = p_recogEngine->SetInput(cpAudio, TRUE);
- + if (FAILED(hr))
- + {
- + MessageBox(hWnd,"Failed to set audio input\n", "Error", MB_OK);
- + }
- +
- + // Set rules to active, we are now listening for commands
- + hr = p_grammarObject->SetRuleState(NULL, NULL, SPRS_ACTIVE );
- + if (FAILED(hr))
- + {
- MessageBox(hWnd,"Failed to set listening for commands\n","Error",MB_OK);
- - break;
- - }
- + break;
- + }
- - break;
- - }
- + break;
- + }
- - // if we failed and have a partially setup SAPI, close it all down
- - if (FAILED(hr))
- - {
- - VOICEREC_deinit();
- - }
- + // if we failed and have a partially setup SAPI, close it all down
- + if (FAILED(hr))
- + {
- + VOICEREC_deinit();
- + }
- - return ( hr == S_OK);
- + return ( hr == S_OK);
- }
- void VOICEREC_deinit()
- {
- - // Release grammar, if loaded
- - if ( p_grammarObject )
- - {
- - p_grammarObject.Release();
- - }
- - // Release recognition context, if created
- - if ( p_recogContext )
- - {
- - p_recogContext->SetNotifySink(NULL);
- - p_recogContext.Release();
- - }
- - // Release recognition engine instance, if created
- + // Release grammar, if loaded
- + if ( p_grammarObject )
- + {
- + p_grammarObject.Release();
- + }
- + // Release recognition context, if created
- + if ( p_recogContext )
- + {
- + p_recogContext->SetNotifySink(NULL);
- + p_recogContext.Release();
- + }
- + // Release recognition engine instance, if created
- if ( p_recogEngine )
- {
- p_recogEngine.Release();
- @@ -219,50 +233,21 @@ void VOICEREC_deinit()
- void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd);
- void VOICEREC_process_event(HWND hWnd)
- {
- - CSpEvent event; // Event helper class
- -
- - // Loop processing events while there are any in the queue
- - while (event.GetFrom(p_recogContext) == S_OK)
- - {
- - // Look at recognition event only
- - switch (event.eEventId)
- - {
- - case SPEI_RECOGNITION:
- - VOICEREC_execute_command(event.RecoResult(), hWnd);
- - break;
- -
- - }
- - }
- -}
- + CSpEvent event; // Event helper class
- -// Its not enough to update this, phrases.xml must have this info as well
- -char *wing_names[] =
- -{
- - "Alpha",
- - "Beta",
- - "Gamma",
- - "Delta",
- - "Epsilon",
- - "Zeta",
- - "Eta",
- - "Theta",
- - "Iota",
- - "Kappa",
- - "Lambda",
- - "Mu",
- - "Nu",
- - "Xi",
- - "Omicron",
- - "Pi",
- - "Rho",
- - "Sigma",
- - "Tau",
- - "Upsilon",
- - "Phi",
- - "Chi",
- - "Psi",
- - "Omega",
- -};
- + // Loop processing events while there are any in the queue
- + while (event.GetFrom(p_recogContext) == S_OK)
- + {
- + // Look at recognition event only
- + switch (event.eEventId)
- + {
- + case SPEI_RECOGNITION:
- + VOICEREC_execute_command(event.RecoResult(), hWnd);
- + break;
- +
- + }
- + }
- +}
- /******************************************************************************
- * ExecuteCommand *
- @@ -276,12 +261,12 @@ char VOICEREC_lastCommand[30];
- void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- {
- - SPPHRASE *pElements;
- + SPPHRASE *pElements;
- - // Get the phrase elements, one of which is the rule id we specified in
- - // the grammar. Switch on it to figure out which command was recognized.
- - if (SUCCEEDED(pPhrase->GetPhrase(&pElements)))
- - {
- + // Get the phrase elements, one of which is the rule id we specified in
- + // the grammar. Switch on it to figure out which command was recognized.
- + if (SUCCEEDED(pPhrase->GetPhrase(&pElements)))
- + {
- #ifndef NDEBUG
- if(DEBUG_ON)
- {
- @@ -304,13 +289,15 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- mprintf(( "recognized speech : %s \n", szText ));
- mprintf(( "speech Rule.ulId : %d \n", pElements->Rule.ulId ));
- - //MessageBoxW(NULL,pwszText,NULL,MB_OK);
- + //MessageBoxW(NULL,pwszText,NULL,MB_OK);
- +
- + ::CoTaskMemFree(pwszText);
- }
- -#endif
- +#endif
- int part1, part2, part3;
- part1 = part2 = part3 = -1;
- - switch ( pElements->Rule.ulId )
- - {
- + switch ( pElements->Rule.ulId )
- + {
- case VID_WingName:
- {
- @@ -327,9 +314,24 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- if (part2 == -1)
- break; // no ship number or wing
- + const wchar_t* valstr = pElements->pProperties->pszValue;
- + char* wing_name = new char[wcslen(valstr)+1];
- +
- + size_t j = 0;
- +
- + for (size_t i = 0; i < wcslen(valstr); i++) {
- + int c = wctob(valstr[i]);
- + if (c != EOF) {
- + wing_name[j++] = static_cast<char>(c);
- + }
- + }
- + wing_name[j] = '\0';
- +
- if (part2 == 0)
- {
- - Msg_instance = wing_lookup(wing_names[part1]);
- + Msg_instance = wing_lookup(wing_name);
- + delete[] wing_name;
- +
- if (Msg_instance < 0)
- break;
- @@ -338,13 +340,14 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- hud_squadmsg_toggle();
- }
- - hud_squadmsg_do_mode(SM_MODE_WING_COMMAND);
- + hud_squadmsg_do_mode(SM_MODE_WING_COMMAND);
- }
- - else
- + else
- {
- char shipName[NAME_LENGTH];
- - wing_bash_ship_name(shipName, wing_names[part1], part2);
- -
- + wing_bash_ship_name(shipName, wing_name, part2);
- + delete[] wing_name;
- +
- Msg_instance = ship_name_lookup(shipName);
- // Can't issue commands to yourself or to nobody
- @@ -358,20 +361,20 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- hud_squadmsg_toggle();
- }
- - hud_squadmsg_do_mode(SM_MODE_SHIP_COMMAND);
- + hud_squadmsg_do_mode(SM_MODE_SHIP_COMMAND);
- }
- - if (part3 == -1)
- + if (part3 == -1)
- break;
- }
- case VID_Action:
- {
- int action;
- - if (part3 == -1)
- + if (part3 == -1)
- {
- - action = pElements->pProperties->vValue.ulVal;
- + action = pElements->pProperties->vValue.ulVal;
- }
- else
- {
- @@ -401,7 +404,7 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- switch(action)
- {
- - case VID_Ships:
- + case VID_Ships:
- hud_squadmsg_do_mode( SM_MODE_SHIP_SELECT );
- break;
- @@ -409,22 +412,22 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- hud_squadmsg_do_mode( SM_MODE_WING_SELECT );
- break;
- - case VID_AllFighters:
- + case VID_AllFighters:
- case VID_AllWings:
- // Msg_instance = MESSAGE_ALL_FIGHTERS;
- // Squad_msg_mode == SM_MODE_ALL_FIGHTERS
- hud_squadmsg_msg_all_fighters();
- - if (pElements->pProperties->pNextSibling) {
- - doVid_Action(pElements->pProperties->pNextSibling->vValue.ulVal);
- + if (pElements->pProperties->pFirstChild) {
- + doVid_Action(pElements->pProperties->pFirstChild->vValue.ulVal);
- }
- // if(Msg_shortcut_command == -1)
- // {
- - // hud_squadmsg_do_mode( SM_MODE_ALL_FIGHTERS );
- + // hud_squadmsg_do_mode( SM_MODE_ALL_FIGHTERS );
- // }
- break;
- - case VID_Reinforcements:
- + case VID_Reinforcements:
- hud_squadmsg_do_mode( SM_MODE_REINFORCEMENTS );
- break;
- @@ -466,7 +469,7 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- int action = pElements->pProperties->vValue.ulVal;
- mprintf(("Targeting/speed %d \n", action));
- - if (action > -1)
- + if (action > -1)
- {
- button_function( action );
- }
- @@ -500,19 +503,19 @@ void VOICEREC_execute_command(ISpPhrase *pPhrase, HWND hWnd)
- }
- - /*
- -
- -
- + /*
- +
- +
- hud_squadmsg_do_mode( SM_MODE_SHIP_COMMAND ); // and move to a new mode
- hud_squadmsg_do_mode( SM_MODE_WING_COMMAND ); // and move to a new mode
- hud_squadmsg_do_mode( SM_MODE_SHIP_COMMAND );
- */
- - }
- - // Free the pElements memory which was allocated for us
- - ::CoTaskMemFree(pElements);
- - }
- + }
- + // Free the pElements memory which was allocated for us
- + ::CoTaskMemFree(pElements);
- + }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement