コード例 #1
0
        public static CortanaCommand ProcessCommand(SpeechRecognitionResult speechRecognitionResult, CommandDiagnostics diagnostics)
        {
            // Get the name of the voice command and the text spoken
            string voiceCommandName = speechRecognitionResult.RulePath[0];
            string textSpoken = speechRecognitionResult.Text;

            string argument = null;
            CortanaCommand processedCommand = null;

            //bool modelUsed = ModelHolder != null;
            //if (modelUsed) {
            //    UserCortanaCommand userCommand = ProcessUserCommand(voiceCommandName, speechRecognitionResult, diagnostics);
            //    bool wasUserCommand = userCommand != null;
            //    if (wasUserCommand) {
            //        return userCommand;
            //    }
            //}

            switch (voiceCommandName)
            {
                case CortanaCommand.Execute:
                    argument = GetPhraseArg(speechRecognitionResult, "filename"); // filename
                    //argument = CortanaCommand.StripOffCommandName(voiceCommandName, textSpoken);
                    processedCommand = new ExecuteCortanaCommand(argument, diagnostics);
                    break;

                case CortanaCommand.ToggleListening:
                    processedCommand = new ToggleListeningCortanaCommand(null, diagnostics); // no argument needed
                    break;

                case CortanaCommand.YouTube:
                    const string youtube = "YouTube";
                    argument = CortanaCommand.StripOffCommandName(youtube, textSpoken); // search text
                    processedCommand = new YoutubeCortanaCommand(argument, diagnostics);
                    break;

                case CortanaCommand.Notepad:
                    const string notepad = "Notepad";
                    argument = CortanaCommand.StripOffCommandName(notepad, textSpoken); // text
                    processedCommand = new NotepadCortanaCommand(argument, diagnostics);
                    break;

                case CortanaCommand.FeedMe:
                    processedCommand = new FeedMeCortanaCommand(null, diagnostics); // no argument needed
                    break;

                case CortanaCommand.Calibrate:
                    processedCommand = new CalibrateCortanaCommand(null, diagnostics); // no argument needed
                    break;

                case CortanaCommand.BriefMe:
                    processedCommand = new BriefMeCortanaCommand(null, diagnostics); // no argument needed
                    break;

                default:
                    Debug.WriteLine("Command Name Not Found:  " + voiceCommandName);
                    break;
            }
            return processedCommand;
        }
コード例 #2
0
        public CortanaCommand(string name, string argument, CommandDiagnostics diagnostics=null) : this()
        {
            Name = name;
            Argument = argument;

            OrganizeFeedback(diagnostics);
        }
コード例 #3
0
        /// <summary>
        /// Converts VoiceCommandActivatedEvent into specific CortanaCommand. 2 purposes:
        /// 1) Parse the "argument" of the command (ex. filename "My Cool Script", notepad note "feed the cat", etc.) into usable format.
        /// 2) Separate the details of "capturing" a voice command (here) from the command's business logic (in it's subclass of CortanaCommand)
        /// </summary>
        public static CortanaCommand ProcessCommand(VoiceCommandActivatedEventArgs commandArgs)
        {
            SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;
            CommandDiagnostics      diagnostics             = new CommandDiagnostics(commandArgs);

            return(ProcessCommand(speechRecognitionResult, diagnostics));
        }
コード例 #4
0
        public CortanaCommand(string name, string argument, CommandDiagnostics diagnostics = null) : this()
        {
            Name     = name;
            Argument = argument;

            OrganizeFeedback(diagnostics);
        }
コード例 #5
0
 private void OrganizeFeedback(CommandDiagnostics diagnostics)
 {
     if (diagnostics != null) {
         RawText = diagnostics.RawText;
         Mode = diagnostics.Mode;
     }
     else {
         RawText = Mode = null;
     }
 }
コード例 #6
0
 private void OrganizeFeedback(CommandDiagnostics diagnostics)
 {
     if (diagnostics != null)
     {
         RawText = diagnostics.RawText;
         Mode    = diagnostics.Mode;
     }
     else
     {
         RawText = Mode = null;
     }
 }
コード例 #7
0
 /// <summary>
 /// Converts VoiceCommandActivatedEvent into specific CortanaCommand. 2 purposes:
 /// 1) Parse the "argument" of the command (ex. filename "My Cool Script", notepad note "feed the cat", etc.) into usable format.
 /// 2) Separate the details of "capturing" a voice command (here) from the command's business logic (in it's subclass of CortanaCommand) 
 /// </summary>
 public static CortanaCommand ProcessCommand(VoiceCommandActivatedEventArgs commandArgs)
 {
     SpeechRecognitionResult speechRecognitionResult = commandArgs.Result;
     CommandDiagnostics diagnostics = new CommandDiagnostics(commandArgs);
     return ProcessCommand(speechRecognitionResult, diagnostics);
 }
コード例 #8
0
 public static UserCortanaCommand ProcessUserCommand(string voiceCommandName, SpeechRecognitionResult speechRecognitionResult, CommandDiagnostics commandArgs)
 {
     SharedModel model = ModelHolder.Model;
     UserCortanaCommand command = null;
     if (model != null) {
         IList<UserCortanaCommand> commands = model.UserCortanaCommands;
         command = commands.Where( c => c.Name.Equals(voiceCommandName) ).First();
         if (command != null) {
             command = command.Spawn(speechRecognitionResult);
         }
     }
     return command;
 }
コード例 #9
0
 public BriefMeCortanaCommand(string argument, CommandDiagnostics diagnostics = null) : base(BriefMe, argument, diagnostics) { /*Super constructor does everything*/ }
コード例 #10
0
 public NotepadCortanaCommand(string argument, CommandDiagnostics diagnostics = null) : base(Notepad, argument, diagnostics) { /*Super constructor does everything*/ }
コード例 #11
0
 public ToggleListeningCortanaCommand(string argument, CommandDiagnostics diagnostics = null) : base(ToggleListening, argument, diagnostics) { /*Super constructor does everything*/ }
コード例 #12
0
        public static CortanaCommand ProcessCommand(SpeechRecognitionResult speechRecognitionResult, CommandDiagnostics diagnostics)
        {
            // Get the name of the voice command and the text spoken
            string voiceCommandName = speechRecognitionResult.RulePath[0];
            string textSpoken       = speechRecognitionResult.Text;

            string         argument         = null;
            CortanaCommand processedCommand = null;

            //bool modelUsed = ModelHolder != null;
            //if (modelUsed) {
            //    UserCortanaCommand userCommand = ProcessUserCommand(voiceCommandName, speechRecognitionResult, diagnostics);
            //    bool wasUserCommand = userCommand != null;
            //    if (wasUserCommand) {
            //        return userCommand;
            //    }
            //}

            switch (voiceCommandName)
            {
            case CortanaCommand.Execute:
                argument = GetPhraseArg(speechRecognitionResult, "filename");     // filename
                //argument = CortanaCommand.StripOffCommandName(voiceCommandName, textSpoken);
                processedCommand = new ExecuteCortanaCommand(argument, diagnostics);
                break;

            case CortanaCommand.ToggleListening:
                processedCommand = new ToggleListeningCortanaCommand(null, diagnostics);     // no argument needed
                break;

            case CortanaCommand.YouTube:
                const string youtube = "YouTube";
                argument         = CortanaCommand.StripOffCommandName(youtube, textSpoken); // search text
                processedCommand = new YoutubeCortanaCommand(argument, diagnostics);
                break;

            case CortanaCommand.Notepad:
                const string notepad = "Notepad";
                argument         = CortanaCommand.StripOffCommandName(notepad, textSpoken); // text
                processedCommand = new NotepadCortanaCommand(argument, diagnostics);
                break;

            case CortanaCommand.FeedMe:
                processedCommand = new FeedMeCortanaCommand(null, diagnostics);     // no argument needed
                break;

            case CortanaCommand.Calibrate:
                processedCommand = new CalibrateCortanaCommand(null, diagnostics);     // no argument needed
                break;

            case CortanaCommand.BriefMe:
                processedCommand = new BriefMeCortanaCommand(null, diagnostics);     // no argument needed
                break;

            default:
                Debug.WriteLine("Command Name Not Found:  " + voiceCommandName);
                break;
            }
            return(processedCommand);
        }
コード例 #13
0
        public static UserCortanaCommand ProcessUserCommand(string voiceCommandName, SpeechRecognitionResult speechRecognitionResult, CommandDiagnostics commandArgs)
        {
            SharedModel        model   = ModelHolder.Model;
            UserCortanaCommand command = null;

            if (model != null)
            {
                IList <UserCortanaCommand> commands = model.UserCortanaCommands;
                command = commands.Where(c => c.Name.Equals(voiceCommandName)).First();
                if (command != null)
                {
                    command = command.Spawn(speechRecognitionResult);
                }
            }
            return(command);
        }
コード例 #14
0
 public ExecuteCortanaCommand(string argument, CommandDiagnostics diagnostics = null) : base(Execute, argument, diagnostics) /*Super constructor does everything*/ }