13 #pragma message( "WARNING: You have not compiled voice recognition into this build (use FS2_VOICER)" )
16 #else // to end-of-file ...
37 CComPtr<ISpRecoGrammar> p_grammarObject;
38 CComPtr<ISpRecoContext> p_recogContext;
39 CComPtr<ISpRecognizer> p_recogEngine;
40 CComPtr<ISpAudio> cpAudio;
42 const bool DEBUG_ON =
false;
54 void doVid_Action(
int action)
123 hr = p_recogEngine.CoCreateInstance(CLSID_SpInprocRecognizer);
126 MessageBox(hWnd,
"Failed to create a recognition engine\n",
"Error",
MB_OK);
127 printf(
"Failed to create a recognition engine\n");
132 hr = p_recogEngine->CreateRecoContext( &p_recogContext );
135 MessageBox(hWnd,
"Failed to create the command recognition context\n",
"Error",
MB_OK);
136 printf(
"Failed to create the command recognition context\n");
142 hr = p_recogContext->SetNotifyWindowMessage( hWnd, event_id, 0, 0 );
151 hr = p_recogContext->SetInterest( SPFEI(SPEI_RECOGNITION), SPFEI(SPEI_RECOGNITION) );
159 hr = p_recogContext->CreateGrammar(grammar_id, &p_grammarObject);
168 hr = p_grammarObject->LoadCmdFromFile(L
"data\\phrases.xml", SPLO_STATIC);
171 hr = p_grammarObject->LoadCmdFromResource(NULL, MAKEINTRESOURCEW(command_resource),
172 L
"SRGRAMMAR", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
181 hr = SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &cpAudio);
184 MessageBox(hWnd,
"Failed to get default audio input\n",
"Error",
MB_OK);
189 hr = p_recogEngine->SetInput(cpAudio,
TRUE);
196 hr = p_grammarObject->SetRuleState(NULL, NULL, SPRS_ACTIVE );
199 MessageBox(hWnd,
"Failed to set listening for commands\n",
"Error",
MB_OK);
212 return ( hr == S_OK);
222 if ( p_grammarObject )
224 p_grammarObject.Release();
227 if ( p_recogContext )
229 p_recogContext->SetNotifySink(NULL);
230 p_recogContext.Release();
235 p_recogEngine.Release();
239 void VOICEREC_execute_command(ISpPhrase *pPhrase,
HWND hWnd);
245 while (event.GetFrom(p_recogContext) == S_OK)
248 switch (event.eEventId)
250 case SPEI_RECOGNITION:
251 VOICEREC_execute_command(event.RecoResult(),
hWnd);
266 char VOICEREC_lastCommand[30];
268 void VOICEREC_execute_command(ISpPhrase *pPhrase,
HWND hWnd)
274 if (SUCCEEDED(pPhrase->GetPhrase(&pElements)))
283 pPhrase->GetText(static_cast<ULONG>(SP_GETWHOLEPHRASE), static_cast<ULONG>(SP_GETWHOLEPHRASE),
TRUE, &pwszText, NULL);
285 memset(szText, 0, 255);
288 if (*(pwszText + i) == 0)
292 szText[
i] = (char)(*(pwszText + i));
296 mprintf((
"recognized speech : %s \n", szText ));
297 mprintf((
"speech Rule.ulId : %d \n", pElements->Rule.ulId ));
298 mprintf((
"confidence: %f \n", pElements->pProperties->SREngineConfidence));
300 ::CoTaskMemFree(pwszText);
303 int part1, part2, part3;
304 part1 = part2 = part3 = -1;
305 switch ( pElements->Rule.ulId )
311 part1 = pElements->pProperties->vValue.ulVal;
312 if (pElements->pProperties->pNextSibling)
314 part2 = pElements->pProperties->pNextSibling->vValue.ulVal;
315 if (pElements->pProperties->pNextSibling->pNextSibling)
317 part3 = pElements->pProperties->pNextSibling->pNextSibling->vValue.ulVal;
323 const wchar_t* valstr = pElements->pProperties->pszValue;
324 char* wing_name =
new char[wcslen(valstr)+1];
328 for (
size_t i = 0; i < wcslen(valstr); i++) {
329 int c = wctob(valstr[i]);
331 wing_name[j++] =
static_cast<char>(
c);
361 if (Msg_instance < 0 || Msg_instance == Player_obj->instance)
385 action = pElements->pProperties->vValue.ulVal;
392 doVid_Action(action);
400 int action = pElements->pProperties->vValue.ulVal;
401 bool msgWindow =
false;
408 if((msgWindow && action == VID_Cancel) || (!msgWindow && action != VID_Cancel))
423 case VID_AllFighters:
427 if (pElements->pProperties->pFirstChild) {
428 doVid_Action(pElements->pProperties->pFirstChild->vValue.ulVal);
432 case VID_Reinforcements:
436 case VID_SupportShip:
440 case VID_AbortSupport:
453 int action = pElements->pProperties->vValue.ulVal;
473 int action = pElements->pProperties->vValue.ulVal;
485 int action = pElements->pProperties->vValue.ulVal;
494 for (
int i=1; i<7; i++)
503 ::CoTaskMemFree(pElements);
void wing_bash_ship_name(char *ship_name, const char *wing_name, int index)
#define SM_MODE_ALL_FIGHTERS
#define PROTECT_TARGET_ITEM
wingman message: attack current target
int hud_squadmsg_send_wing_command(int wingnum, int command, int send_message, int update_history, int player_num)
void hud_squadmsg_do_mode(int mode)
#define MESSAGE_ALL_FIGHTERS
transfer shield energy to right
#define SM_MODE_WING_SELECT
#define DISARM_TARGET_ITEM
int hud_squadmsg_wing_valid(wing *wingp)
#define IGNORE_TARGET_ITEM
#define ATTACK_TARGET_ITEM
#define ENGAGE_ENEMY_ITEM
wingman message: cover me
void hud_squadmsg_msg_all_fighters()
void hud_squadmsg_send_to_all_fighters(int command, int player_num)
wingman message: disarm current target
#define DISABLE_TARGET_ITEM
wingman message: form on my wing
#define SM_MODE_REPAIR_REARM
int button_function(int n)
bool VOICEREC_init(HWND hWnd, int event_id, int grammar_id, int command_resource)
#define SM_MODE_WING_COMMAND
wingman message: engage enemy
#define SM_MODE_SHIP_SELECT
void hud_squadmsg_shortcut(int command)
#define SM_MODE_REPAIR_REARM_ABORT
int hud_squadmsg_send_ship_command(int shipnum, int command, int send_message, int update_history, int player_num)
#define SM_MODE_REINFORCEMENTS
wingman message: protect current target
equalize shield energy to all quadrants
int MessageBox(HWND h, const char *s1, const char *s2, int i)
transfer shield energy to left
wingman message: disable current target
wingman message: warp out
#define DISABLE_SUBSYSTEM_ITEM
int ship_name_lookup(const char *name, int inc_players)
wingman message: disable current target
increase weapon recharge rate
#define PLAYER_FLAGS_MSG_MODE
transfer shield energy to rear
void hud_squadmsg_toggle()
int wing_lookup(const char *name)
transfer shield energy to front
#define SM_MODE_SHIP_COMMAND
bool hud_squadmsg_ship_valid(ship *shipp, object *objp)
void VOICEREC_process_event(HWND hWnd)