/// <summary> /// Runs on a different thread /// </summary> private void DoVoiceRecognition() { if (running) { Debug.Log("Failed to start voice recognition - already running"); SetError(SpeechManagerErrorType.VoiceThreadError_AlreadyRunning); return; } running = true; if (ConfigureSpeechRecognition()) { /* Initialization */ PXCMSpeechRecognition.Handler handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = OnRecognition; handler.onAlert = OnAlert; pxcmStatus sts = sr.StartRec(source, handler); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { while (!stop) { if (reset) { sr.StopRec(); ConfigureSpeechRecognition(); sts = sr.StartRec(source, handler); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.Log("VoiceThreadError - ResetFailed - StartRec!"); SetError(SpeechManagerErrorType.VoiceThreadError_ResetFailed_StartRec); stop = true; CleanUp(); running = false; return; } reset = false; } System.Threading.Thread.Sleep(50); } sr.StopRec(); } else { Debug.Log("VoiceThreadError - InitFailed - StartRec!"); SetError(SpeechManagerErrorType.VoiceThreadError_InitFailed_StartRec); } } CleanUp(); running = false; }
public void DisableRecognition() { if (_speechRecognition == null) { return; } _speechRecognition.StopRec(); _speechRecognition.SilentlyDispose(); }
//Recordボタンを押すと呼び出されるメソッド public void SetRecord() { //Recordがtrueなら(最初に押されたら) if (Record) { //handler.onRecognition = (x) => Dataoutput(x.scores[0].sentence); //わかりません sr.StartRec(source, handler); //音声認識の開始 Record = false; //Recordをfalseにする Debug.Log("Record True"); //デバッグログ } //Recordがfalseなら(音声認識中に押されたら) else { sr.StopRec(); //音声認識の終了 Record = true; //Recordをtrueにする Debug.Log("Record False"); //デバッグログ } }
void Update() { if (isReadyToLoadLevel) { Application.LoadLevel("RealSense_Testing"); sr.StopRec(); isReadyToLoadLevel = false; Debug.Log("Cleaning up in Update whilst Initializing ApplicationLoadLevel"); sr.Dispose(); } if (isReadyToRestartLevel) { Application.LoadLevel("SettingUpVoiceTests"); sr.StopRec(); isReadyToRestartLevel = false; Debug.Log("Cleaning up in Update whilst Restart for ApplicationLoadLevel"); sr.Dispose(); } }
static void Main(string[] args) { // create client instance client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS)); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId, "guest", "guest"); SubscribeMessage(); isActive = false; //Init speech recognizer session = PXCMSession.CreateInstance(); SetupRecognizer(session); Console.WriteLine("Siap melayani boss..."); Console.WriteLine("Teken 'x' kalau mau mecat saya"); while (true) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); char keychar = pressedKey.KeyChar; if (keychar == 'x') { break; } } Console.WriteLine("Selamat tinggal bos, senang melayani.."); client.Disconnect(); try { if (sr != null) { sr.StopRec(); sr.Dispose(); sr = null; } if (source != null) { source.Dispose(); source = null; } if (session != null) { session.Dispose(); } } catch (Exception ex) { Console.WriteLine(ex.Message + " : " + ex.StackTrace); } }
void OnDisable() { if (sr != null) { sr.StopRec(); sr.Dispose(); } if (session != null) { session.Dispose(); } }
private void ReleaseResources() { speechRecognition.StopRec(); speechRecognition.Dispose(); audioSource.Dispose(); session.Dispose(); // Stop the worker thread processingThread.Abort(); // Release resources faceData.Dispose(); senseManager.Dispose(); }
public void DoIt(MainForm form1, PXCMSession session) { form = form1; /* Create the AudioSource instance */ source = session.CreateAudioSource(); if (source == null) { CleanUp(); form.PrintStatus("Stopped"); return; } /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(form.GetCheckedSource()); /* Set Module */ PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = form.GetCheckedModule(); pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(form.GetCheckedLanguage(), out pinfo); sr.SetProfile(pinfo); ///////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// /* Set Command/Control or Dictation */ if (form.IsCommandControl()) { string[] cmds = form.GetCommands(); if (form.g_file != null && form.g_file.Length != 0) { if (form.g_file.EndsWith(".list")) { form.FillCommandListConsole(form.g_file); cmds = form.GetCommands(); if (cmds.GetLength(0) == 0) { form.PrintStatus("Command List Load Errors"); } } // input Command/Control grammar file available, use it if (!SetGrammarFromFile(form.g_file)) { form.PrintStatus("Can not set Grammar From File."); CleanUp(); return; } ; } else if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sts = sr.BuildGrammarFromStringList(1, cmds, null); sts = sr.SetGrammar(1); } else { form.PrintStatus("No Command List. Dictation instead."); if (form.v_file != null && form.v_file.Length != 0) { SetVocabularyFromFile(form.v_file); } sts = sr.SetDictation(); } } else { if (form.v_file != null && form.v_file.Length != 0) { SetVocabularyFromFile(form.v_file); } sts = sr.SetDictation(); } if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { form.PrintStatus("Can't start recognition."); CleanUp(); return; } /* Initialization */ form.PrintStatus("Init Started"); form.PutLabel1Text("初期化中..."); PXCMSpeechRecognition.Handler handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = OnRecognition; handler.onAlert = OnAlert; sts = sr.StartRec(source, handler); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { form.PrintStatus("Init OK"); // form.PutLabel1Text("認識中..."); form.PutLabel1Text("マイクに向かって話してください"); /* Wait until the stop button is clicked */ while (!form.IsStop()) { System.Threading.Thread.Sleep(5); } sr.StopRec(); } else { form.PrintStatus("Failed to initialize"); } } else { form.PrintStatus("Init Failed"); } CleanUp(); form.PrintStatus("Stopped"); }