static private WriteToLog ( string text, |
||
text | string | |
parent | ||
Résultat | void |
void engine_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e) { if (verbose) { HelperMethods.WriteToLog("Speech Rejected!", parent); } }
private void SaveLogMenuItem_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "Text File (*.txt)|*.txt"; if ((bool)saveDlg.ShowDialog()) { using (FileStream file = new FileStream(saveDlg.FileName, FileMode.Create)) { StreamWriter writer = new StreamWriter(file); try { writer.Write(LogTextBox.Text.ToCharArray()); } catch { MessageBox.Show("Error: The log file failed to save!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); HelperMethods.WriteToLog("Log file (" + saveDlg.FileName + ") failed to save."); } writer.Close(); writer.Dispose(); } } }
void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { for (int i = 0; i < server.serverMasterOptions.voiceCommands.Count; i++) { if (server.serverMasterOptions.voiceCommands[i].recognizedWord.ToLower() == e.Result.Text.ToLower()) { if (e.Result.Confidence >= server.serverMasterOptions.voiceCommands[i].confidence) { //Send across VRPN if (server.serverMasterOptions.voiceCommands[i].serverType == ServerType.Button) { for (int j = 0; j < server.serverMasterOptions.buttonServers.Count; j++) { if (server.serverMasterOptions.buttonServers[j].serverName == server.serverMasterOptions.voiceCommands[i].serverName) { VoiceButtonCommand shortCommand = (VoiceButtonCommand)server.serverMasterOptions.voiceCommands[i]; if (shortCommand.buttonType == ButtonType.Momentary) { server.UpdateButtonData(j, shortCommand.buttonNumber, shortCommand.setState); //Run a delegate to change the state back, that way, even though it uses a blocking call, it will be blocking a thread we don't care about ToggleBackMomentaryButtonDelegate buttonDelegate = ToggleBackMomentaryButton; buttonDelegate.BeginInvoke(j, shortCommand.buttonNumber, !shortCommand.setState, null, null); } else if (shortCommand.buttonType == ButtonType.Setter) { server.UpdateButtonData(j, shortCommand.buttonNumber, shortCommand.setState); } else //Toggle button { server.InvertButton(j, shortCommand.buttonNumber); } } } } else if (server.serverMasterOptions.voiceCommands[i].serverType == ServerType.Text) { for (int j = 0; j < server.serverMasterOptions.textServers.Count; j++) { if (server.serverMasterOptions.textServers[j].serverName == server.serverMasterOptions.voiceCommands[i].serverName) { server.UpdateTextData(j, ((VoiceTextCommand)server.serverMasterOptions.voiceCommands[i]).actionText); } } } //Write out to the log HelperMethods.WriteToLog("Recognized the word \"" + e.Result.Text + "\", with the confidence of " + e.Result.Confidence.ToString("F2") + ".", parent); } else { if (verbose) { HelperMethods.WriteToLog("Recognized the word \"" + e.Result.Text + "\", but the confidence (" + e.Result.Confidence.ToString("F2") + ") was too low.", parent); } } } } }
void engine_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e) { Debug.WriteLine("Hypothesized word at time: " + e.Result.Audio.StartTime.ToString()); if (verbose) { HelperMethods.WriteToLog("Hypothesized the word \"" + e.Result.Text + "\"", parent); } }
public void launchServer() { //These don't need a lock to be thread safe since they are volatile forceStop = false; serverState = ServerRunState.Starting; string errorMessage = ""; if (serverMasterOptions.parseSettings(out errorMessage)) { //Start the Kinect audio streams and create the per Kinect skeleton lists for (int i = 0; i < kinects.Count; i++) { kinects[i].StartKinectAudio(); //TODO: This will crash if the Kinects are in another thread (i.e. console mode) } //Start the feedback client if necessary if (serverMasterOptions.feedbackOptions.useFeedback) { feedbackCore = new FeedbackCore(verbose, this, parent); feedbackCore.StartFeedbackCore(serverMasterOptions.feedbackOptions.feedbackServerName, serverMasterOptions.feedbackOptions.feedbackSensorNumber); } runServerCoreDelegate serverDelegate = runServerCore; serverDelegate.BeginInvoke(null, null); //Start voice recognition, if necessary if (serverMasterOptions.voiceCommands.Count > 0) { voiceRecog = new VoiceRecogCore(this, verbose, parent); launchVoiceRecognizerDelegate voiceDelegate = voiceRecog.launchVoiceRecognizer; //Dispatcher newDispatch = new Dispatcher(); voiceDelegate.BeginInvoke(new AsyncCallback(voiceStartedCallback), null); //voiceRecog.launchVoiceRecognizer(); } else { //Because the voice callback will not be called, we need to call this stuff here if (GUI) { parent.startServerButton.Content = "Stop"; parent.startServerButton.IsEnabled = true; parent.ServerStatusItem.Content = "Running"; parent.ServerStatusTextBlock.Text = "Running"; } } } else { HelperMethods.ShowErrorMessage("Error", "Settings parsing failed! See the log for more details.", parent); HelperMethods.WriteToLog(errorMessage, parent); } }
private void voiceStartedCallback(IAsyncResult ar) { HelperMethods.WriteToLog("Voice started!", parent); if (GUI) { parent.Dispatcher.BeginInvoke((Action)(() => { parent.startServerButton.Content = "Stop"; parent.startServerButton.IsEnabled = true; parent.ServerStatusItem.Content = "Running"; parent.ServerStatusTextBlock.Text = "Running"; }), null ); } }
internal static void RunServerInConsole(bool isVerbose, bool autoStart, string startupFile) { Console.Clear(); Console.WriteLine("Welcome to the Kinect With VR (KiwiVR) Server!"); Console.WriteLine("Press the \"E\" key at any time to exit."); MasterSettings settings = new MasterSettings(); try { settings = HelperMethods.LoadSettings(startupFile); } catch { HelperMethods.WriteToLog("Cannot open settings file!"); } ServerCore server = new ServerCore(isVerbose, settings); for (int i = 0; i < server.serverMasterOptions.kinectOptions.Count; i++) //Launch the Kinects { server.kinects.Add(new KinectCore(server, null, server.serverMasterOptions.kinectOptions[i].kinectID)); } server.launchServer(); //This will still try to launch with default settings even if the settings load fails bool running = true; while (running) { Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(false); if (key.Key == ConsoleKey.E || (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control)) { running = false; } } } Console.WriteLine("Shutting down the server. Please wait..."); server.stopServer(); NativeInterop.FreeConsole(); }
private void SaveSettingsMenuItem_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.Filter = "XML File (*.xml)|*.xml"; if ((bool)saveDlg.ShowDialog()) { try { HelperMethods.SaveSettings(saveDlg.FileName, server.serverMasterOptions); } catch { MessageBox.Show("Error: The settings file failed to save!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); HelperMethods.WriteToLog("Settings file (" + saveDlg.FileName + ") failed to save."); } } }
private void OpenSettingsMenuItem_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Filter = "XML File (*.xml)|*.xml|All Files|*.*"; openDlg.FilterIndex = 0; openDlg.Multiselect = false; if ((bool)openDlg.ShowDialog()) { try { server.serverMasterOptions = HelperMethods.LoadSettings(openDlg.FileName); UpdateGUISettings(); } catch { MessageBox.Show("Error: The settings file failed to open!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); HelperMethods.WriteToLog("Settings file (" + openDlg.FileName + ") failed to load."); } } }
private void Window_Initialized(object sender, EventArgs e) { //Setup the timer to update the GUI with the server runtime uptimeUpdateTimer = new System.Timers.Timer(); uptimeUpdateTimer.Interval = 500; uptimeUpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(uptimeUpdateTimer_Elapsed); MasterSettings tempSettings = new MasterSettings(); //Create the server core (this does NOT start the server) server = new ServerCore(verbose, tempSettings, this); //Set all the data for the data grids VoiceButtonDataGrid.ItemsSource = server.serverMasterOptions.voiceButtonCommands; VoiceTextDataGrid.ItemsSource = server.serverMasterOptions.voiceTextCommands; KinectStatusBlock.Text = "1"; if (startupFile != null && startupFile != "") { try { server.serverMasterOptions = HelperMethods.LoadSettings(startupFile); UpdateGUISettings(); } catch { MessageBox.Show("Error: The startup settings file failed to load!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); HelperMethods.WriteToLog("Startup settings (" + startupFile + ") failed to load."); } } //TODO: Handle starting Kinects based on the loaded settings file //Initialize the data for the available Kinects for (int i = 0; i < KinectSensor.KinectSensors.Count; i++) { AvailableKinectData tempData = new AvailableKinectData(); tempData.ConnectionID = KinectSensor.KinectSensors[i].DeviceConnectionId; tempData.Status = KinectSensor.KinectSensors[i].Status; if (i == 0 && tempData.Status == KinectStatus.Connected) { tempData.UseKinect = true; tempData.KinectID = 0; server.serverMasterOptions.kinectOptions.Add(new KinectSettings(tempData.ConnectionID, (int)tempData.KinectID)); server.kinects.Add(new KinectCore(server, this, (int)tempData.KinectID)); } else { tempData.UseKinect = false; tempData.KinectID = null; } tempData.PropertyChanged += useKinect_PropertyChanged; availableKinects.Add(tempData); } kinectsAvailableDataGrid.ItemsSource = availableKinects; UpdatePageListing(); GenerateImageSourcePickerLists(); KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged; //Populate the skeleton data and set the binding for the data grid GenerateSkeletonDataGridData(); SkeletonSettingsDataGrid.ItemsSource = server.serverMasterOptions.skeletonOptions.individualSkeletons; //Populate and setup the voice recognition lists GenerateVoiceRecogEngineList(); GenerateAudioSourceList(); VoiceKinectComboBox.SelectedIndex = 0; //Set defaults where needed FeedbackJointTypeComboBox.SelectedIndex = 0; SkelSortModeComboBox.SelectedIndex = 5; if (startOnLaunch) { startServerButton_Click(this, new RoutedEventArgs()); } }
internal static void RunServerInConsole(bool isVerbose, bool autoStart, string startupFile, AvaliableDLLs dlls) { Console.Clear(); Console.WriteLine("Welcome to the Kinect With VR (KVR) Server!"); Console.WriteLine("Press the \"E\" key at any time to exit."); //Notify the user if DLLs are missing if (!dlls.HasKinectV1) { Console.WriteLine("Warning: Kinect v1 support is unavaliable due to missing DLLs"); } if (!dlls.HasKinectV2) { Console.WriteLine("Warning: Kinect v2 support is unavaliable due to missing DLLs"); } if (!dlls.HasNetworkedKinect) { Console.WriteLine("Warning: Networked Kinect support is unavaliable due to missing DLLs"); } KinectBase.MasterSettings settings = new KinectBase.MasterSettings(); try { settings = HelperMethods.LoadSettings(startupFile); } catch { HelperMethods.WriteToLog("Cannot open settings file!"); } ServerCore server = new ServerCore(isVerbose, settings); for (int i = 0; i < server.serverMasterOptions.kinectOptionsList.Count; i++) //Launch the Kinects { if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.KinectV1) { if (dlls.HasKinectV1) { //server.kinects.Add(new KinectV1Core.KinectCoreV1(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID)); server.kinects.Add(new KinectV1Wrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID)); } else { Console.WriteLine("Cannot load Kinect v1 with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID); } } else if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.KinectV2) { if (dlls.HasKinectV2) { server.kinects.Add(new KinectV2Wrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID)); } else { Console.WriteLine("Cannot load Kinect v2 with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID); } } else if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.NetworkKinect) { if (dlls.HasNetworkedKinect) { server.kinects.Add(new NetworkKinectWrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID, server.serverMasterOptions.kinectOptionsList[i].uniqueKinectID)); } else { Console.WriteLine("Cannot load network Kinect with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID); } } else { Console.WriteLine("Kinect number {0} was of an unknown version and could not be opened.", i); } } server.launchServer(); //This will still try to launch with default settings even if the settings load fails bool running = true; while (running) { Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(false); if (key.Key == ConsoleKey.E || (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control)) { running = false; } } } Console.WriteLine(); //Write a blank so the next statement has its own line Console.WriteLine("Shutting down the server. Please wait..."); server.stopServer(); NativeInterop.FreeConsole(); }