示例#1
0
        //Method to handle settings page button presses
        public void settingEvents(Button btn)
        {
            //Has to be btn.Name rather than btn.Content because there are 2 sets of buttons name "normal" and "large"
            //Each of these buttons manipulates the settings in a specific way
            switch (btn.Name.ToString())
            {
            case "btn_Left":
                //Switches the currently tracked hand to left
                Settings.rightHandTracked = false;
                //Remove the hand from the screen
                kinect.removePerson(kinect.People[0]);
                //Redraw the new hand
                kinect.initialisePeople();
                break;

            case "btn_Right":
                //Switches the currently tracked hand to right
                Settings.rightHandTracked = true;
                //Remove the hand from the screen
                kinect.removePerson(kinect.People[0]);
                //Redraw the hand
                kinect.initialisePeople();
                break;

            case "btn_normText":
                //Scales the font back down to the original scale
                Settings.fontScale = 1.0;
                break;

            case "btn_largeText":
                //Upscales the font to increase readability
                Settings.fontScale = 1.15;
                break;

            case "btn_normScreen":
                //Sets the screen size to be the default kinect camera resolution
                Settings.windowHeight = 480;
                Settings.windowWidth  = 640;
                kinect.frame.scaleSize();
                break;

            case "btn_largeScreen":
                //Sets the screen size to be 720p
                Settings.windowHeight = 720;
                Settings.windowWidth  = 1280;
                kinect.frame.scaleSize();
                break;

            case "btn_back":
                //Go back to the main menu
                kinect.openMenu();
                break;

            case "btn_apply":
                //Settings options are applied automatically, makes users sure that settings are confirmed
                kinect.frame.textToSpeech("Settings have been applied");
                break;
            }
            //Reload the page with the new settings
            kinect.settings.init();
        }
示例#2
0
        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;
                }
            }
        }