Ejemplo n.º 1
0
        private void CreateCustomCommand(string command, CommandRepository commandRepository)
        {
            SpeechSynthesisService.Speak("Teach me how to do it");
            IList <ICoreCommand> subCommands = new List <ICoreCommand>();
            var newCommand = SpeechRecognitionService.Listen();

            while (true)
            {
                var intent = IntentService.GetIntent(newCommand);
                if (CommandsHelper.GetCoreCommandIntents().Contains(intent.TopScoringIntent.Name) && intent.TopScoringIntent.Score > 0.7)
                {
                    var factory     = new CoreCommandFactory();
                    var coreCommand = factory.Create(intent.TopScoringIntent.Name);
                    coreCommand.Validate(new List <string>(), true);
                    subCommands.Add(coreCommand);
                    SpeechSynthesisService.Speak("Anything else");
                }
                else
                {
                    if (intent.TopScoringIntent.Name == "no")
                    {
                        break;
                    }
                    SpeechSynthesisService.Speak("Cannot do that");
                }
                newCommand = SpeechRecognitionService.Listen();
                intent     = IntentService.GetIntent(newCommand);
                if (intent.TopScoringIntent.Name == "no")
                {
                    break;
                }
            }
            commandRepository.SaveCustomCommand(command, subCommands, Guid.NewGuid().ToString());
        }
Ejemplo n.º 2
0
        public void Detect()
        {
            SpeechSynthesisService.Speak("What do you want?");
            var command = SpeechRecognitionService.Listen();

            if (string.IsNullOrEmpty(command))
            {
                return;
            }
            var intent = IntentService.GetIntent(command);

            if (CommandsHelper.GetCoreCommandIntents().Contains(intent.TopScoringIntent.Name) && intent.TopScoringIntent.Score > 0.7)
            {
                var factory     = new CoreCommandFactory();
                var coreCommand = factory.Create(intent.TopScoringIntent.Name);
                var response    = coreCommand.Execute(new List <string>());
                var output      = response.ElementAtOrDefault(0);
                if (output != null)
                {
                    SpeechSynthesisService.Speak(output);
                }
                return;
            }
            ICustomCommand customCommand = SearchCommand(_commandRepository, command);

            if (customCommand == null)
            {
                CreateCustomCommand(command, _commandRepository);
            }
            else
            {
                customCommand.Execute();
            }
        }