private static void PrimaryGrammar_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result != null & e.Result.Confidence >= 0.925) { DataStore.AddRecentCommand(e.Result.Text); try { if (e.Result.Text.Contains("Pause")) { Task.Run(() => { writeToTextBox(e.Result.Text); }); if (RecogInProgress == true) { GrammarManipulator.HaltRecognition(); PrimaryResponse(new Response(CommandType.Primary, DateTime.Now.TimeOfDay.Hours, e.Result.Text)); RecogInProgress = false; } else { PrimaryResponse(new Response(CommandType.Primary, DateTime.Now.TimeOfDay.Hours, "already paused")); } } else if (e.Result.Text.Contains("Resume Recognition") | e.Result.Text.Contains("Wake up")) { Task.Run(() => { writeToTextBox(e.Result.Text); }); if (RecogInProgress == false) { GrammarManipulator.ResumeRecognition(); PrimaryResponse(new Response(CommandType.Primary, DateTime.Now.TimeOfDay.Hours, e.Result.Text)); RecogInProgress = true; } else { PrimaryResponse(new Response(CommandType.Primary, DateTime.Now.TimeOfDay.Hours, "recognition already in progress")); } } else { throw new Exception("Unknown recognition by PrimaryGrammar "); } } catch (Exception ex) { DataStore.AddToErrorLog(ex.Message); } } }
public SelectUser() { InitializeComponent(); this.DataContext = this; listOfUsers = DataStore.Users; foreach (var item in listOfUsers) { usersListBox.Items.Add(item); } SelectUserRunning = true; this.Activated += (sender, e) => { /* * Fires up when the UI is "InFocus" i.e. is the active window */ try { GrammarManipulator.ResponseBoxLoaded(); //Loads the UIGrammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Deactivated += (sender, e) => { /* * Fires up when the UI has "LostFocus" i.e. is no longer the active window */ try { GrammarManipulator.ResponseBoxDeloaded(); //unloads the UI grammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Closed += (sender, e) => { SelectUserRunning = false; }; GrammarFeeder.UserDialogOk += GrammarFeeder_UserDialogOk; GrammarFeeder.CloseResponseBoxEvent += GrammarFeeder_CloseResponseBoxEvent; }
private static void ResponseBoxGrammar_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { if (e.Result != null & e.Result.Confidence >= 0.825) { Task.Run(() => { writeToTextBox(e.Result.Text); }); DataStore.AddRecentCommand(e.Result.Text); if (e.Result.Text == "Ok") { if (AddUser.AddUserRunning == true) { UserDialogOk(); ResponseBoxResponse(new Response(CommandType.ResponseBox, DateTime.Now.TimeOfDay.Hours, "user dialog ok . ")); } else if (SelectUser.SelectUserRunning == true) { UserDialogOk(); ResponseBoxResponse(new Response(CommandType.ResponseBox, DateTime.Now.TimeOfDay.Hours, "user dialog ok . ")); } else { ProgramManager.SendOpenCommand(openRecogPhrase); GrammarManipulator.EnableCloseGrammar(); CloseResponseBoxEvent(); ResponseBoxResponse(new Response(CommandType.ResponseBox, DateTime.Now.TimeOfDay.Hours, e.Result.Text)); } } else if (e.Result.Text == "Cancel") { CloseResponseBoxEvent(); ResponseBoxResponse(new Response(CommandType.ResponseBox, DateTime.Now.TimeOfDay.Hours, e.Result.Text)); } else { writeToTextBox(""); //remove the text in the analyzed textbox } } }
static public void CreateResponseBox() { Thread thread = new Thread(() => { ResponseBox respBox = new ResponseBox(); respBox.Loaded += (sender, e) => { GrammarManipulator.ResponseBoxLoaded(); }; respBox.Closed += (sender, e) => { GrammarManipulator.ResponseBoxDeloaded(); respBox.Dispatcher.InvokeShutdown(); //so by closing the window the thread is shutdown as well. otherwise we get ghost thread which doesnt allow th application to exit }; respBox.Show(); System.Windows.Threading.Dispatcher.Run(); //for calling the dispatcher of the current window/uielement needed for running }); thread.SetApartmentState(ApartmentState.STA); //STA state in needed by wpf thread.Start(); //starts the thread }
public AddUser() { InitializeComponent(); userImage = new Image(); AddUserRunning = true; this.Activated += (sender, e) => { /* * Fires up when the UI is "InFocus" i.e. is the active window */ try { GrammarManipulator.ResponseBoxLoaded(); //Loads the UIGrammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Deactivated += (sender, e) => { /* * Fires up when the UI has "LostFocus" i.e. is no longer the active window */ try { GrammarManipulator.ResponseBoxDeloaded(); //unloads the UI grammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; GrammarFeeder.UserDialogOk += GrammarFeeder_UserDialogOk; GrammarFeeder.CloseResponseBoxEvent += GrammarFeeder_CloseResponseBoxEvent; }
public MainWindow() { #region Non Essential Stuff initStopwatch = new Stopwatch(); Stopwatch sw = new Stopwatch(); sw.Start(); #endregion InitializeComponent(); //expanderCntrl.IsExpanded = true; #region Event Handlers of the Mainwindow itself this.Closed += (sender, e) => //fires up when the UI Closes { Console.WriteLine(ct.CanBeCanceled.ToString()); cancelToken.Cancel(); //when this ui is closed, hold up the Init.StartInit thread }; this.Closing += (sender, e) => //occurs as soon as this.Close() occurs { MessageBoxResult result = MessageBox.Show("Do you really want to quit?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { e.Cancel = true; } }; this.Activated += (sender, e) => { /* * Fires up when the UI is "InFocus" i.e. is the active window */ try { GrammarManipulator.UILoaded(); //Loads the UIGrammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; this.Deactivated += (sender, e) => { /* * Fires up when the UI has "LostFocus" i.e. is no longer the active window */ try { GrammarManipulator.UIDeloaded(); //unloads the UI grammar } catch (Exception ex) { Console.WriteLine(ex.Message); } }; #endregion #region Additional Stuff Task initRun = new Task(new Action(Init.ProgramInit), cancelToken.Token); initRun.Start(); //starts the Init.StartInit method, which is the main recognizer thread, asynchronously sw.Stop(); #endregion #region Event Handlers for Events of External CLasses DataStore.SetUserNow += DataStore_SetUserNow; //event handler for DataStore's SetUserNow event, which notifies when User is set GrammarFeeder.writeToTextBox += GrammarFeeder_writeToTextBox; //event handler for GrammarFeeder's writeToTextBox event GrammarFeeder.UpdateSlider += GrammarFeeder_UpdateSlider; //event handler for GrammarFeeder's UpdateSlider event GrammarFeeder.CloseMainWindow += GrammarFeeder_CloseMainWindow; //Close Window Event GrammarFeeder.ExpandIt += GrammarFeeder_ExpandIt; //ExpanderExpanding event #endregion #region Dumping some Data Task.Run(() => { DataStore.AddToMessageDump(string.Format("Time elapsed during loading of main window : {0}", sw.ElapsedMilliseconds)); }); logoRectangle.ToolTip = "This is the official logo of Project Voix ." + "\n As opposed to the program itself, the logo is copyright protected." + " Any unauthorised use is subjected to copyright infringement actions ." + "\n Designed by Grafoholics (tm)."; #endregion }
public static void ProgramInit() { try { MainWindow.initStopwatch.Start(); if (MainWindow.ct.IsCancellationRequested) { return; } Task.Run(() => { DataStore.StartDataStoreManager(); }); waitHandle2.WaitOne(); speechEngine = new SpeechRecognitionEngine(); Stopwatch watch = new Stopwatch(); DataStore.DisplayCurrentUser(); watch.Start(); GrammarFeeder.GrammarLoader(ref speechEngine); //call to the public method of GrammarFeeder class List <Grammar> grammarList = new List <Grammar>(speechEngine.Grammars); GrammarManipulator.RegisterWithManipulator(ref speechEngine); ProgramManager.InitializeManager(); watch.Stop(); waitHandle.WaitOne(); speechEngine.SetInputToDefaultAudioDevice(); MainWindow.initStopwatch.Stop(); DataStore.AddToMessageDump(string.Format("time taken in the Init instantiator {0} ms", MainWindow.initStopwatch.ElapsedMilliseconds)); speechEngine.RecognizeAsync(RecognizeMode.Multiple); } catch (OutOfMemoryException outOfMemEx) { DataStore.AddToErrorLog(string.Format("Out of memory exception occured.---------\n Message : {0} \n StackTrace : {1}", outOfMemEx.Message, outOfMemEx.StackTrace)); Task.Run(() => { MessageBox.Show("Critical Exception occured. {0} \n Application Restart Recommended", outOfMemEx.Message); }); } catch (IOException ioEx) { DataStore.AddToErrorLog(string.Format("exception occured.---------\n Message : {0} \n StackTrace : {1}", ioEx.Message, ioEx.StackTrace)); } catch (InvalidOperationException invalidOpEx) { DataStore.AddToErrorLog(string.Format("An exception occured.---------\n Message : {0} \n StackTrace : {1}", invalidOpEx.Message, invalidOpEx.StackTrace)); } catch (NotSupportedException nsEx) { DataStore.AddToErrorLog(string.Format("An exception occured.---------\n Message : {0} \n StackTrace : {1}", nsEx.Message, nsEx.StackTrace)); } catch (NullReferenceException nullRefEx) { DataStore.AddToErrorLog(string.Format("An exception occured.---------\n Message : {0} \n StackTrace : {1}", nullRefEx.Message, nullRefEx.StackTrace)); } catch (WaitHandleCannotBeOpenedException waitHandleExcep) { DataStore.AddToErrorLog(string.Format("Critical Exception occured.---------\n Message : {0} \n StackTrace : {1}", waitHandleExcep.Message, waitHandleExcep.StackTrace)); Task.Run(() => { MessageBox.Show("Critical Exception occured. {0} \n Application Restart Recommended", waitHandleExcep.Message); }); } catch (ThreadStartException tsEx) { DataStore.AddToErrorLog(string.Format("Critical Exception occured.---------\n Message : {0} \n StackTrace : {1}", tsEx.Message, tsEx.StackTrace)); Task.Run(() => { MessageBox.Show("Critical Exception occured. {0} \n Application Restart Recommended (if no crash occured)", tsEx.Message); }); } catch (ApplicationException appEx) { DataStore.AddToErrorLog(string.Format("Application level Exception occured.---------\n Message : {0} \n StackTrace : {1}", appEx.Message, appEx.StackTrace)); Task.Run(() => { MessageBox.Show("Application level Exception occured. {0} \n Application Restart Recommended (if no crash occured)", appEx.Message); }); } catch (SystemException systemEx) { DataStore.AddToErrorLog(string.Format("System Level Exception occured.---------\n Message : {0} \n StackTrace : {1}", systemEx.Message, systemEx.StackTrace)); Task.Run(() => { MessageBox.Show("System level Exception occured. {0} \n Non recoverable \n Application Restart Recommended (if no crash occured)", systemEx.Message); }); } catch (Exception e) { DataStore.AddToErrorLog(string.Format("Exception occured.---------\n Message : {0} \n StackTrace : {1}", e.Message, e.StackTrace)); } }