private async Task SayPromptAsync(AdaptiveSpeechPrompt prompt) { await SayTextAsync(prompt.GetTextToSay()); if (prompt.Choices.Any()) { var choices = prompt.GetSpeechChoices(); var speechRecognizer = new SpeechRecognizer(); speechRecognizer.Constraints.Add(new SpeechRecognitionListConstraint(choices)); await speechRecognizer.CompileConstraintsAsync(); var results = await speechRecognizer.RecognizeWithUIAsync(); var selectedChoice = results.Text; int index = choices.ToList().IndexOf(selectedChoice); await Task.Delay(500); // Delay some time so the speaking doesn't get cut off if (index == -1) { await SayTextAsync("I'm sorry, I didn't understand that."); return; } if (index >= prompt.Choices.Count) { // "I'm done" return; } var choice = prompt.Choices[index]; if (choice.FollowUpPrompts.Any()) { await SayPromptsAsync(choice.FollowUpPrompts); } else { await SayTextAsync("Excellent, we're done!"); } } }
private AdaptiveSpeechPrompt GetCurrentSpeechPrompt() { var prompt = new AdaptiveSpeechPrompt(); if (Title != null) { prompt.Statements.Add(Title); } if (Subtitle != null) { prompt.Statements.Add(Subtitle); } var actions = GetSimplifiedActions().ToArray(); if (actions.Any()) { prompt.Choices = actions.Select(i => i.CreateSpeechChoice()).ToList(); } return(prompt); }