public TestServiceCommandSet() { List<Command> commands = new List<Command>(); Command cmd = new Command(); cmd .Phrase("Call service with message") .Dictation() .Handle(context => { var service = context.ServiceContainer.GetService<TestService>(true); service.CallEvent(context.Phrase.ToString()); }); commands.Add(cmd); Commands = commands; }
public SearchCommandSet() { List<Command> commands = new List<Command>(); Command cmd = new Command(); ChoiceSet choices = new ChoiceSet(); choices .Add("google") .Add("youtube"); cmd .Phrase("Search") .Choices("search_provider", choices) .Phrase("for") .Dictation() .Handle(context => { var speechSynthesizer = context.ServiceContainer.GetOrAddService<ISpeechSynthesizer>(); var words = context.Phrase.Words.Skip(3); var text = words.Select(w => w.Text); var searchTerm = string.Join(" ", text); var choice = context.VariableResults.FirstOrDefault(c => c.Key == "search_provider"); switch (choice.Value) { case "youtube": speechSynthesizer?.Speak("Searching You Tube"); SearchYoutube(searchTerm); break; default: speechSynthesizer?.Speak("Searching Google"); SearchGoogle(searchTerm); break; } Console.WriteLine(context.Phrase); }); commands.Add(cmd); Commands = commands; }
public void CanPerformComplexChoiceWithDictation() { ManualResetEvent resetEvent = new ManualResetEvent(false); bool success = false; Command command = new Command(); string firstColor = null; string secondColor = null; string dictation = null; var firstColors = new ChoiceSet(); firstColors .Add("red") .Add("blue") .Add("green"); var secondColors = new ChoiceSet(); secondColors .Add("yellow") .Add("orange") .Add("pink"); command .Phrase("I like the colors") .Choices("first_color", firstColors) .Phrase("and") .Choices("second_color", secondColors) .Phrase("because") .Dictation() .Handle(context => { firstColor = context.VariableResults.FirstOrDefault(c => c.Key == "first_color").Value; secondColor = context.VariableResults.FirstOrDefault(c => c.Key == "second_color").Value; dictation = context.VariableResults.FirstOrDefault(c => c.Key == "dictation").Value; resetEvent.Set(); success = true; }); _recognitionCore.Add(command); string c1 = "red"; string c2 = "yellow"; string d1 = "they are pretty"; string format = string.Format("I like the colors {0} and {1} because {2}", c1, c2, d1); _recognitionEngine.EmulateRecognizeAsync(format); WaitHandle.WaitAll(new[] { resetEvent }); Assert.AreEqual(c1, firstColor); Assert.AreEqual(c2, secondColor); Assert.AreEqual(d1, dictation); resetEvent.Reset(); c1 = "blue"; c2 = "orange"; d1 = "they clash"; format = string.Format("I like the colors {0} and {1} because {2}", c1, c2, d1); _recognitionEngine.EmulateRecognizeAsync(format); WaitHandle.WaitAll(new[] { resetEvent }); Assert.AreEqual(c1, firstColor); Assert.AreEqual(c2, secondColor); Assert.AreEqual(d1, dictation); resetEvent.Reset(); c1 = "green"; c2 = "pink"; d1 = "breast cancer and green bay packers"; format = string.Format("I like the colors {0} and {1} because {2}", c1, c2, d1); _recognitionEngine.EmulateRecognizeAsync(format); WaitHandle.WaitAll(new[] { resetEvent }); Assert.AreEqual(c1, firstColor); Assert.AreEqual(c2, secondColor); Assert.AreEqual(d1, dictation); Assert.IsTrue(success); }
public void CanPerformSimpleDictation() { ManualResetEvent resetEvent = new ManualResetEvent(false); bool success = false; Command builder = new Command(); builder.Phrase("Search for") .Dictation() .Handle(context => { success = true; resetEvent.Set(); }); _recognitionCore.Add(builder); _recognitionEngine.EmulateRecognizeAsync("Search for chicken wranglers"); WaitHandle.WaitAll(new[] { resetEvent }); Assert.IsTrue(success); }
public void CanPerformSimpleChoice() { ManualResetEvent resetEvent = new ManualResetEvent(false); bool success = false; Command builder = new Command(); var colorChoices = new ChoiceSet(); colorChoices .Add("red") .Add("blue") .Add("green"); builder .Phrase("I like the color") .Choices("color_choice", colorChoices) .Handle(context => { success = true; resetEvent.Set(); }); _recognitionCore.Add(builder); _recognitionEngine.EmulateRecognizeAsync("I like the color red"); WaitHandle.WaitAll(new[] { resetEvent }); resetEvent.Reset(); _recognitionEngine.EmulateRecognizeAsync("I like the color blue"); WaitHandle.WaitAll(new[] { resetEvent }); resetEvent.Reset(); _recognitionEngine.EmulateRecognizeAsync("I like the color green"); WaitHandle.WaitAll(new[] { resetEvent }); Assert.IsTrue(success); }
public void CanPerformComplexChoice() { ManualResetEvent resetEvent = new ManualResetEvent(false); bool success = false; Command command = new Command(); string firstColor = null; string secondColor = null; var firstColors = new ChoiceSet(); firstColors .Add("red") .Add("blue") .Add("green"); var secondColors = new ChoiceSet(); secondColors .Add("yellow") .Add("orange") .Add("pink"); command .Phrase("I like the colors") .Choices("first_color", firstColors) .Phrase("and") .Choices("second_color", secondColors) .Handle(context => { firstColor = context.VariableResults.FirstOrDefault(c => c.Key == "first_color").Value; secondColor = context.VariableResults.FirstOrDefault(c => c.Key == "second_color").Value; resetEvent.Set(); success = true; }); _recognitionCore.Add(command); _recognitionEngine.EmulateRecognizeAsync("I like the colors red and yellow"); WaitHandle.WaitAll(new[] { resetEvent }); Assert.AreEqual("red", firstColor); Assert.AreEqual("yellow", secondColor); resetEvent.Reset(); _recognitionEngine.EmulateRecognizeAsync("I like the colors blue and orange"); WaitHandle.WaitAll(new[] { resetEvent }); Assert.AreEqual("blue", firstColor); Assert.AreEqual("orange", secondColor); resetEvent.Reset(); _recognitionEngine.EmulateRecognizeAsync("I like the colors green and pink"); WaitHandle.WaitAll(new[] { resetEvent }); Assert.AreEqual("green", firstColor); Assert.AreEqual("pink", secondColor); Assert.IsTrue(success); }
public CommonCommandSet() { List<Command> commands = new List<Command>(); Command whatTimeIsIt = new Command(); whatTimeIsIt .Phrase("What time is it?") .Handle(SpeakTime); commands.Add(whatTimeIsIt); whatTimeIsIt = new Command(); whatTimeIsIt .Phrase("What's the time?") .Handle(SpeakTime); commands.Add(whatTimeIsIt); whatTimeIsIt = new Command(); whatTimeIsIt .Phrase("What is the time?") .Handle(SpeakTime); commands.Add(whatTimeIsIt); Command whatDayIsIt = new Command(); whatDayIsIt .Phrase("What day is it?") .Handle(SpeakDay); commands.Add(whatDayIsIt); Command todoList = new Command(); todoList .Phrase("I need to") .Dictation("task") .Handle(StoreTask); commands.Add(todoList); todoList = new Command(); todoList .Phrase("What do I need to do") .Handle(SpeakTasks); commands.Add(todoList); todoList = new Command(); todoList .Phrase("List tasks") .Handle(SpeakTasks); commands.Add(todoList); Commands = commands; }