//Method to handle main menu page button presses public void menuEvents(Button btn) { //Get the button name that was pressed switch (btn.Content.ToString()) { case "New": //Open code page from the Kinect instance kinect.openCode(); break; case "Open": //Trigger the speech to text event to listen for the file name that the user wants to open //This is the name of the event used in the Speech class String result = "open page"; Boolean check = false; kinect.speech.varResult = "open page"; //Call the method in the Speech class giving the above values as parameters kinect.speech.speechToText(result, check); break; case "Help": //Open help page from the Kinect instance kinect.openHelp(); break; case "Settings": //Open settings page from the Kinect instance kinect.openSettings(); break; case "Quit": //Exit the program kinect.quitProgram(); break; } }
private void speechRecognised(object sender, SpeechRecognizedEventArgs e) { //Handles all of the commands when they are recognised in people's speech //Used in speech to text confirmation Boolean confirm = false; //Converts the speech detection result to lower case for cosnsitency String result = e.Result.Text.ToLower(); //Stores the confidence of the result of the current speech detection as a double double conf = e.Result.Confidence; //Ensures that the confidence for the result is high enough and that the result is not null to prevent null exception errors if (conf >= 0.75 && result != null) { Console.WriteLine("Speech detection result: " + result); switch (result) { case "save": //Allows for saving the current program, but only whilst in the code window if (kinect.currentWindow == "main") { events.savePress(); } break; case "run": //Allows for running of the code whilst in the code window if (kinect.currentWindow == "main") { events.runPress(); } break; case "switch": //If the right hand is currently being tracked... if (Settings.rightHandTracked) { //... sets the left hand to be tracked Settings.rightHandTracked = false; //Removes the previously drawn cursor from the screen kinect.removePerson(kinect.People[0]); kinect.removePerson(kinect.People[1]); //And then re-initialises the hand skeleton kinect.initialisePeople(); } //Else if the right hand is not being tracked... else if (!Settings.rightHandTracked) { //... sets the right hand to be tracked Settings.rightHandTracked = true; //And performs the same function as switching to the left hand kinect.removePerson(kinect.People[0]); kinect.removePerson(kinect.People[1]); kinect.initialisePeople(); } break; case "mute": case "quiet": //Stops the text to speech from making any noise Settings.ttsVolume = 0; break; case "unmute": Settings.ttsVolume = 100; break; case "select": //Runs the method for selecting the currently hovered icon with speech rather than a push gesture speechSelect(); break; case "undo": //Undoes the previous entry into the code window, checking if the current window is the code window if (kinect.currentWindow == "main") { events.removeLastStatement(); } break; case "start text": //Checks to see if the user is in the input window if (kinect.currentWindow == "input") { //Runs the speech to text method using the current commands result and the current confirm boolean speechToText(result, confirm); } break; case "back": //Checks the current window to know where to navigate back to //Potential for improvement - acquire previous window and set window content back to previous window when back is said switch (kinect.currentWindow) { case "input": kinect.openCode(); events.removeLastStatement(); break; case "menu": //Used to prevent the users from going back in the menu kinect.frame.textToSpeech("You are already in the main window"); break; default: kinect.openMenu(); break; } break; case "confirm": //If the current window is input, allows for confirming of the current statement using speech if (kinect.currentWindow == "input") { events.addStatement(); } break; case "decline": //Or if the user wishes to decline the current input, that can be done using speech if (kinect.currentWindow == "input") { //Removing the previous empty statement and opening the code window again events.removeLastStatement(); kinect.openCode(); } break; case "set": case "value": //Allows the user to use speech to text to enter values for variable names and values if (kinect.currentWindow == "input") { //varResult is used in checking which part of the variable is being set //...as well as which speech to text command is being run in the relevant method varResult = result; speechToText(result, confirm); } break; case "change title": //Changes the title of the current project using speech to text if (kinect.currentWindow == "main") { //Sets varResult to be used as a check when running the speech to text commands varResult = result; speechToText(result, confirm); } break; case "close": //If the current window is either the menu or the main window... if (kinect.currentWindow == "main" || kinect.currentWindow == "menu") { try { //Saying close closes the current running Python window //Both pages allow for closing due to the open function in the menu allowing for opening of projects from the menu events.cmd.Kill(); } catch (InvalidOperationException e2) { //Prints the invalid operation exception if thrown, caused by the command trying to be killed if it isn't open Console.WriteLine("InvalidOperationException in speech: " + e2.Message + e2.Source); } } break; //Opens either settings or help depending on which command is used, allowing for navigation using speech case "help": kinect.openHelp(); break; case "settings": kinect.openSettings(); break; default: //Otherwise, if no command is recognised the user is informed about this kinect.frame.textToSpeech("Difficulty understanding command, please repeat"); Console.WriteLine("Difficulty understanding command, please repeat"); break; } } }