/// <summary> /// Configures the speech recognition. /// </summary> private bool ConfigureSpeechRecognition() { /* Create the AudioSource instance */ source = session.CreateAudioSource(); /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(sourceDeviceInfo[_activeSource]); /* Set Module */ PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = modulesIuID[_activeModule]; pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(_activeLanguage, out pinfo); sr.SetProfile(pinfo); /* Set Command/Control or Dictation */ if (SpeechModuleMode == SpeechModuleModeType.CommandControl) { string[] cmds = Commands; if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sr.BuildGrammarFromStringList(1, cmds, null); sr.SetGrammar(1); } else { Debug.Log("Speech Command List Empty!"); SetError(SpeechManagerErrorType.VoiceThreadError_CommandsListEmpty); //Switch to dictaction mode //SpeechModuleMode = SpeechModuleModeType.Dictation; //sr.SetDictation(); } } else { sr.SetDictation(); } } else { Debug.Log("VoiceThreadError - InitFailed - CreateImpl!"); SetError(SpeechManagerErrorType.VoiceThreadError_InitFailed_CreateImpl); return(false); } return(true); }
void initSession(PXCMSession session) { if (source == null) { Debug.Log("Source was null! No audio device?"); return; } // Set audio volume to 0.2 source.SetVolume(setVolume); // Set Audio Source Debug.Log("Using device: " + device.name); source.SetDevice(device); // Set Module PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = 0; pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { // Configure PXCMSpeechRecognition.ProfileInfo pinfo; // Language sr.QueryProfile(0, out pinfo); Debug.Log(pinfo.language); sr.SetProfile(pinfo); // Set Command/Control or Dictation sr.SetDictation(); // Initialization Debug.Log("Init Started"); PXCMSpeechRecognition.Handler handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = OnRecognition; handler.onAlert = OnAlert; sts = sr.StartRec(source, handler); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.Log("Voice Rec Started"); } else { Debug.Log("Voice Rec Start Failed"); } } else { Debug.Log("Voice Rec Session Failed"); } }
private void ConfigureRealSenseSpeech() { // Instantiate session and audio source objects session = PXCMSession.CreateInstance(); audioSource = session.CreateAudioSource(); // Select the first audio device PXCMAudioSource.DeviceInfo deviceInfo; deviceInfo = new PXCMAudioSource.DeviceInfo(); audioSource.QueryDeviceInfo(0, out deviceInfo); audioSource.SetDevice(deviceInfo); // Set the audio recording volume audioSource.SetVolume(0.2f); // Create a speech recognition instance session.CreateImpl <PXCMSpeechRecognition>(out speechRecognition); // Initialize the speech recognition module PXCMSpeechRecognition.ProfileInfo profileInfo; speechRecognition.QueryProfile(0, out profileInfo); profileInfo.language = PXCMSpeechRecognition.LanguageType.LANGUAGE_US_ENGLISH; speechRecognition.SetProfile(profileInfo); // Build and set the active grammar pxcmStatus status = speechRecognition.BuildGrammarFromFile(1, PXCMSpeechRecognition.GrammarFileType.GFT_JSGF, "grammarsvm.jsgf"); if (status == pxcmStatus.PXCM_STATUS_NO_ERROR) { speechRecognition.SetGrammar(1); } else { MessageBox.Show("Java Speech Grammar Format (JSGF) file not found!"); this.Close(); } // Display device information //lblDeviceInfo.Content = string.Format("[Device: {0}, Language Profile: {1}]", deviceInfo.name, profileInfo.language); // Set the speech recognition handler PXCMSpeechRecognition.Handler handler = new PXCMSpeechRecognition.Handler(); handler.onRecognition = OnRecognition; speechRecognition.StartRec(null, handler); }
private bool ConfigureSpeechRecognition() { /* Create the AudioSource instance */ source = session.CreateAudioSource(); /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(sourceDeviceInfo[_activeSource]); pxcmStatus sts = session.CreateImpl <PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(_activeLanguage, out pinfo); sr.SetProfile(pinfo); /* Set Command/Control or Dictation */ string[] cmds = new String[4] { "Create", "Save", "Load", "Run" }; if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sr.BuildGrammarFromStringList(1, cmds, null); sr.SetGrammar(1); } } else { Debug.Log("VoiceThreadError - InitFailed - CreateImpl!"); return(false); } return(true); }
private PXCMAudioSource FindAudioSource() { PXCMAudioSource audioSource = _session.CreateAudioSource(); audioSource.ScanDevices(); int devicesCount = audioSource.QueryDeviceNum(); var deviceIndex = 0; PXCMAudioSource.DeviceInfo deviceInfo; for (int i = 0; i < devicesCount; i++) { audioSource.QueryDeviceInfo(i, out deviceInfo); if (deviceInfo.name.Contains("Array")) { deviceIndex = i; break; } } audioSource.QueryDeviceInfo(deviceIndex, out deviceInfo); audioSource.SetDevice(deviceInfo); audioSource.SetVolume(0.8f); return(audioSource); }
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"); }
public void DoIt(MainForm form1, PXCMSession session, PXCMAudioSource s) { Debug.Log("DoIt"); form = form1; Debug.Log("DoIt:01"); /* Create the AudioSource instance */ //source = s; source =session.CreateAudioSource(); Debug.Log("DoIt:02"); if (source == null) { CleanUp(); form.PrintStatus("Stopped"); return; } Debug.Log("DoIt:03"); /* Set audio volume to 0.2 */ source.SetVolume(0.2f); Debug.Log("DoIt:04"); /* Set Audio Source */ source.SetDevice(form.GetCheckedSource()); Debug.Log("DoIt:05"); /* Set Module */ PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid = form.GetCheckedModule(); Debug.Log("DoIt:06"); pxcmStatus sts = session.CreateImpl<PXCMSpeechRecognition>(out sr); Debug.Log("DoIt:07"); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.Log("DoIt:10"); PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(form.GetCheckedLanguage(), out pinfo); sr.SetProfile(pinfo); if (form.IsCommandControl()) { Debug.Log("DoIt:20"); string[] cmds = form.GetCommands(); if (form.g_file != null && form.g_file.Length != 0) { Debug.Log("DoIt:30"); if (form.g_file.EndsWith(".list")){ Debug.Log("DoIt:40"); 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)) { Debug.Log("DoIt:41"); form.PrintStatus("Can not set Grammar From File."); CleanUp(); return; }; } else if (cmds != null && cmds.GetLength(0) != 0) { Debug.Log("DoIt:31"); // voice commands available, use them sts = sr.BuildGrammarFromStringList(1, cmds, null); sts = sr.SetGrammar(1); } else { Debug.Log("DoIt:32"); 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 { Debug.Log("DoIt:21"); 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; } form.PrintStatus("Init Started"); 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"); // 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"); } Debug.Log("DoIt:98"); CleanUp(); form.PrintStatus("Stopped"); Debug.Log("DoIt:99"); }
/// <summary> /// Configures the speech recognition. /// </summary> private bool ConfigureSpeechRecognition() { /* Create the AudioSource instance */ source=session.CreateAudioSource(); /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(sourceDeviceInfo[_activeSource]); /* Set Module */ PXCMSession.ImplDesc mdesc = new PXCMSession.ImplDesc(); mdesc.iuid=modulesIuID[_activeModule]; pxcmStatus sts = session.CreateImpl<PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(_activeLanguage, out pinfo); sr.SetProfile(pinfo); /* Set Command/Control or Dictation */ if (SpeechModuleMode == SpeechModuleModeType.CommandControl) { string[] cmds = Commands; if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sr.BuildGrammarFromStringList(1, cmds, null); sr.SetGrammar(1); } else { Debug.Log("Speech Command List Empty!"); SetError(SpeechManagerErrorType.VoiceThreadError_CommandsListEmpty); //Switch to dictaction mode //SpeechModuleMode = SpeechModuleModeType.Dictation; //sr.SetDictation(); } } else { sr.SetDictation(); } } else { Debug.Log("VoiceThreadError - InitFailed - CreateImpl!"); SetError(SpeechManagerErrorType.VoiceThreadError_InitFailed_CreateImpl); return false; } return true; }
private bool ConfigureSpeechRecognition() { /* Create the AudioSource instance */ source = session.CreateAudioSource(); /* Set audio volume to 0.2 */ source.SetVolume(0.2f); /* Set Audio Source */ source.SetDevice(sourceDeviceInfo[_activeSource]); pxcmStatus sts = session.CreateImpl<PXCMSpeechRecognition>(out sr); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { /* Configure */ PXCMSpeechRecognition.ProfileInfo pinfo; sr.QueryProfile(_activeLanguage, out pinfo); sr.SetProfile(pinfo); /* Set Command/Control or Dictation */ string[] cmds = new String[4] { "Create", "Save", "Load", "Run" }; if (cmds != null && cmds.GetLength(0) != 0) { // voice commands available, use them sr.BuildGrammarFromStringList(1, cmds, null); sr.SetGrammar(1); } } else { Debug.Log("VoiceThreadError - InitFailed - CreateImpl!"); return false; } return true; }