void StartRecognizer() { try { // initialize Kinect sensor as needed int rc = SpeechWrapper.InitKinectSensor(); if (rc != 0) { throw new Exception("Initialization of Kinect sensor failed"); } // Initialize the kinect speech wrapper string sCriteria = String.Format("Language={0:X};Kinect=True", languageCode); rc = SpeechWrapper.InitSpeechRecognizer(sCriteria, true, false); if (rc < 0 && errorHandler == null) { errorHandler = new SpeechErrorHandler(); string sErrorMessage = errorHandler.GetSapiErrorMessage(rc); throw new Exception(String.Format("Error initializing Kinect/SAPI: " + sErrorMessage)); } if (requiredConfidence > 0) { SpeechWrapper.SetRequiredConfidence(requiredConfidence); } if (grammarFileName != string.Empty) { rc = SpeechWrapper.LoadSpeechGrammar(grammarFileName, (short)languageCode); if (rc < 0 && errorHandler == null) { errorHandler = new SpeechErrorHandler(); string sErrorMessage = errorHandler.GetSapiErrorMessage(rc); throw new Exception("Error loading grammar file " + grammarFileName + ": " + sErrorMessage); } } instance = this; sapiInitialized = true; DontDestroyOnLoad(gameObject); } catch (DllNotFoundException ex) { Debug.LogError(ex.ToString()); } catch (Exception ex) { Debug.LogError(ex.ToString()); } }
void StartRecognizer() { try { if (errorHandler == null && debugText != null) { debugText.GetComponent <GUIText>().text = "Please, wait..."; } // initialize Kinect sensor as needed int rc = SpeechWrapper.InitKinectSensor(); if (rc != 0) { throw new Exception("Initialization of Kinect sensor failed"); } // Initialize the kinect speech wrapper string sCriteria = String.Format("Language={0:X};Kinect=True", languageCode); rc = SpeechWrapper.InitSpeechRecognizer(sCriteria, true, false); if (rc < 0 && errorHandler == null) { errorHandler = new SpeechErrorHandler(); string sErrorMessage = errorHandler.GetSapiErrorMessage(rc); throw new Exception(String.Format("Error initializing Kinect/SAPI: " + sErrorMessage)); } if (requiredConfidence > 0) { SpeechWrapper.SetRequiredConfidence(requiredConfidence); } if (grammarFileName != string.Empty) { rc = SpeechWrapper.LoadSpeechGrammar(grammarFileName, (short)languageCode, dynamicGrammar); if (rc < 0 && errorHandler == null) { errorHandler = new SpeechErrorHandler(); string sErrorMessage = errorHandler.GetSapiErrorMessage(rc); throw new Exception("Error loading grammar file " + grammarFileName + ": " + sErrorMessage); } // // test dynamic grammar phrases // rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Nancy Anderson", true, false); // rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Cindy White", false, false); // rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Oliver Lee", false, false); // rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "Alan Brewer", false, false); // rc = SpeechWrapper.AddGrammarPhrase("addressBook", string.Empty, "April Reagan", false, true); } instance = this; sapiInitialized = true; DontDestroyOnLoad(gameObject); if (errorHandler == null && debugText != null) { debugText.GetComponent <GUIText>().text = "Ready."; } } catch (DllNotFoundException ex) { Debug.LogError(ex.ToString()); if (debugText != null) { debugText.GetComponent <GUIText>().text = "Please check the Kinect and SAPI installations."; } } catch (Exception ex) { Debug.LogError(ex.ToString()); if (debugText != null) { debugText.GetComponent <GUIText>().text = ex.Message; } } }