void StartRecognizer() { // only do this on awake ? //SAPIWrapper.ExtractGrammarFile (GrammarFileName, GrammarFileName.Replace ("/Resources/","")); //SAPIWrapper.CopySystemDlls(); // just for testing, do this always... // reload the same level try { // Initialize the speech wrapper int rc = 0; string sCriteria = String.Format("Language={0:X}", LanguageCode); rc = SAPIWrapper.InitSpeechRecognizer("", false, true); if (rc < 0) { Debug.LogWarning ("Error initializing SAPI: " + SAPIWrapper.GetSystemErrorMessage(rc)); // put up a dialog message explaining spesh cound not be initialized. if (!hasShownWarning) { DialogMsg msg = new DialogMsg(); msg.xmlName = "traumaErrorPopup"; msg.className = "TraumaError"; msg.modal = true; msg.arguments.Add("Speech Error"); msg.arguments.Add("Speech could not be initialized. Is your microphone plugged in?"); GUIManager.GetInstance().LoadDialog(msg); hasShownWarning = true; } throw new Exception(String.Format("Error initializing SAPI: " + SAPIWrapper.GetSystemErrorMessage(rc))); } else { sapiInitialized = true; } instance = this; if (inputMode == eInputMode.pushToTalk){ //SAPIWrapper.Mute(); StopListening(); Speak ("<volume level='50'> Push Space Bar To Talk"); } else Speak ("<volume level='50'> Voice is Listening"); rc = SAPIWrapper.LoadSpeechGrammar(Application.dataPath+GrammarFileName,(short)LanguageCode); if (rc < 0) { sapiInitialized = false; Speak ("Error loading grammar"); // put up a dialog message explaining spesh cound not be initialized. if (!hasShownWarning) { DialogMsg msg = new DialogMsg(); msg.xmlName = "traumaErrorPopup"; msg.className = "TraumaError"; msg.modal = true; msg.arguments.Add("Speech Error"); msg.arguments.Add("Speech could not be initialized. Is your microphone plugged in?"); GUIManager.GetInstance().LoadDialog(msg); hasShownWarning = true; } throw new Exception(String.Format("Error loading Grammar: " + SAPIWrapper.GetSystemErrorMessage(rc))); } // SAPIWrapper.SetRuleState("playercommand",0); // test setting this rule inactive //!!TEST SAPIWrapper.SetSpeechRecoCallback (SpeechRecognizedCallback); //!!TEST SAPIWrapper.SetSpeechRejectCallback (SpeechRejectedCallback); // we should delay this until the level is up and loaded... // SAPIWrapper.StartListening(); // listening = true; // DontDestroyOnLoad(gameObject); // I think this has already been done in Awake() } catch(DllNotFoundException ex) { Debug.LogError(ex.ToString()); // see if it's the dll not found error, if so copy the .dll's and init again... SAPIWrapper.CopySystemDlls(); Application.Quit(); // Application.LoadLevel(Application.loadedLevel); // this fails for Trauma, so we just quit after copying the .dll's if(debugText != null) debugText.guiText.text = "Please check the SAPI installations."; } catch (Exception ex) { Debug.LogError(ex.ToString()); if(debugText != null) debugText.guiText.text = ex.Message; } }
void Awake(){ #if UNITY_STANDALONE_WIN // make sure we remain a singleton if (instance != null && instance != this){ DestroyImmediate(this.gameObject); return; } // otherwise, we are the first instance = this; DontDestroyOnLoad (gameObject); SAPIWrapper.ExtractGrammarFile (GrammarFileName, GrammarFileName.Replace ("/Resources/","")); unrecognizedClips = new List<SpeechInputRecord>(); #else instance = null; DestroyImmediate( this ); #endif }