private async Task DisambiguateAsync(string promptMessage, string repromptMessage) { var prompt = new VoiceCommandUserMessage(); prompt.DisplayMessage = prompt.SpokenMessage = promptMessage; var reprompt = new VoiceCommandUserMessage(); reprompt.DisplayMessage = reprompt.SpokenMessage = repromptMessage; var contentTiles = new List <VoiceCommandContentTile>(); for (var i = 1; i < 7; i++) { var tile = new VoiceCommandContentTile(); tile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; tile.Image = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///ControlPanel.BackgroundServices/Assets/68_Dice_{i}.png")); tile.AppContext = i; tile.AppLaunchArgument = $"type={i}"; tile.Title = $"The dice result is {i}"; contentTiles.Add(tile); } response = VoiceCommandResponse.CreateResponseForPrompt(prompt, reprompt, contentTiles); try { var result = await voiceServiceConn.RequestDisambiguationAsync(response); if (result != null) { System.Diagnostics.Debug.WriteLine(result); } } catch (Exception ex) { } }
/// <summary> /// Demonstrates providing the user with a choice between multiple items. /// </summary> /// <param name="items">The set of items to choose between</param> /// <param name="titleFunc"> /// A function that returns the title of the item. /// </param> /// <param name="descriptionFunc"> /// A function that returns the description of the item. /// </param> /// <param name="message">The initial disambiguation message</param> /// <param name="secondMessage">Repeat prompt retry message</param> /// <returns></returns> private async Task <T> Disambiguate <T>(IEnumerable <T> items, Func <T, string> titleFunc, Func <T, string> descriptionFunc, string message, string secondMessage) { // Create the first prompt message. var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = message; // Create a re-prompt message if the user responds with an out-of-grammar response. var userReprompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = secondMessage; // Create items for each item. Ideally, should be limited to a small number of items. var destinationContentTiles = new List <VoiceCommandContentTile>(); foreach (T item in items) { var destinationTile = new VoiceCommandContentTile(); // Use a generic background image. This can be fetched from a service call, potentially, but // be aware of network latencies and ensure Cortana does not time out. destinationTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; destinationTile.Image = await Package.Current.InstalledLocation.GetFileAsync("CortanaTodo.Background\\Images\\TodoIcon.png"); // The AppContext can be any arbitrary object, and will be maintained for the // response. destinationTile.AppContext = item; // Format title and description destinationTile.Title = titleFunc(item); destinationTile.TextLine1 = descriptionFunc(item); // Add destinationContentTiles.Add(destinationTile); } // Cortana will handle re-prompting if the user does not provide a valid response. var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, destinationContentTiles); // If cortana is dismissed in this operation, null will be returned. var result = await voiceConnection.RequestDisambiguationAsync(response); if (result != null) { return((T)result.SelectedItem.AppContext); } return(default(T)); }
private async Task HandleSearchWhereBusList() { await ShowProgressScreen("处理中 ..."); // 提供 VoiceCommenContentTile 给用户选择 List <BusData> result = await new SearchService().SearchBusList(); result = result.Take(5).ToList(); List <VoiceCommandContentTile> vcTiles = new List <VoiceCommandContentTile>(); int i = 0; foreach (var item in result) { vcTiles.Add(new VoiceCommandContentTile { Title = item.Name, TextLine1 = String.Format("{0}_{1}", item.Name, i), ContentTileType = VoiceCommandContentTileType.TitleWithText, Image = await StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appx:///BusSearchVCService/Images/GreyTile.png")), AppContext = item }); i += 1; } // Create a VoiceCommandUserMessage for the initial question. VoiceCommandUserMessage userMsg = new VoiceCommandUserMessage(); userMsg.DisplayMessage = userMsg.SpokenMessage = "请选择"; // Create a VoiceCommandUserMessage for the second question, // in case Cortana needs to reprompt. VoiceCommandUserMessage repeatMsg = new VoiceCommandUserMessage(); repeatMsg.DisplayMessage = repeatMsg.SpokenMessage = "请重新选择"; //如果要使用 RequestDisambiguationAsync 需要使用 CreateResponseForPrompt VoiceCommandResponse response = VoiceCommandResponse.CreateResponseForPrompt(userMsg, repeatMsg, vcTiles); // 显示多个选择 var vcResult = await vcConnection.RequestDisambiguationAsync(response); // 取得选择结果 BusData selectedItem = vcResult.SelectedItem.AppContext as BusData; VoiceCommandUserMessage resultMsg = new VoiceCommandUserMessage(); resultMsg.DisplayMessage = resultMsg.SpokenMessage = "选择:" + selectedItem.Name; VoiceCommandResponse response1 = VoiceCommandResponse.CreateResponse(resultMsg); await vcConnection.ReportSuccessAsync(response1); }
/// <summary> /// Provide the user with a way to identify which record to select. /// </summary> /// <param name="records">The set of records</param> private async Task <Record> DisambiguateRecords(IEnumerable <Record> records) { if (records.Count() > 1) { // Create the first prompt message. var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = "Which record do you want to select?"; // Create a re-prompt message if the user responds with an out-of-grammar response. var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = "Sorry, which one do you want to select?"; // Create card for each item. var destinationContentTiles = new List <VoiceCommandContentTile>(); int i = 1; foreach (Record record in records) { var destinationTile = new VoiceCommandContentTile(); destinationTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; //destinationTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AdventureWorks.VoiceCommands/Images/GreyTile.png")); // The AppContext can be any arbitrary object. destinationTile.AppContext = record; destinationTile.Title = record.recordName; destinationContentTiles.Add(destinationTile); i++; } // Cortana handles re-prompting if no valid response. var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, destinationContentTiles); // If cortana is dismissed in this operation, null is returned. var voiceCommandDisambiguationResult = await voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null) { return((Record)voiceCommandDisambiguationResult.SelectedItem.AppContext); } } return(null); }
async Task <string> DisambiguateRoomAsync( VoiceCommandServiceConnection voiceConnection, List <Room> rooms) { var firstMessage = new VoiceCommandUserMessage() { DisplayMessage = "which room did you want to change?" }; firstMessage.SpokenMessage = firstMessage.DisplayMessage; var repeatMessage = new VoiceCommandUserMessage() { DisplayMessage = "sorry, I missed that - which room was it?" }; repeatMessage.SpokenMessage = repeatMessage.DisplayMessage; var tiles = new List <VoiceCommandContentTile>(); var tile = await MakeTileAsync("Building", "ms-appx:///Assets/House68x68.png"); tiles.Add(tile); foreach (var room in rooms) { tile = await MakeTileAsync( room.RoomType.ToString(), $"ms-appx:///Assets/{room.RoomType}68x68.png"); tiles.Add(tile); } var response = VoiceCommandResponse.CreateResponseForPrompt( firstMessage, repeatMessage, tiles); var choice = await voiceConnection.RequestDisambiguationAsync(response); var selectedRoom = choice.SelectedItem.Title == "Building" ? null : choice.SelectedItem.Title; return(selectedRoom); }
private async Task <CabEstimate> AvailableList(IEnumerable <CabEstimate> selected, string selectionMessage, string secondSelectionMessage) { var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = selectionMessage; var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = secondSelectionMessage; var ContentTiles = new List <VoiceCommandContentTile>(); foreach (var cabAvailable in selected) { var cabTile = new VoiceCommandContentTile(); // cabTile.ContentTileType = VoiceCommandContentTileType.TitleWithText; cabTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; if (cabAvailable.Provider.Equals("UBER")) { cabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/uber.png")); } else { cabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ContosoCabs.VoiceCommandService/img/ola.png")); } cabTile.AppContext = cabAvailable; // cabTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri(cabAvailable.ImageURL)); cabTile.Title = cabAvailable.Provider; cabTile.TextLine1 = cabAvailable.Type; cabTile.TextLine3 = "Es. Fare: " + cabAvailable.CurrentEstimate.LowRange + "-" + cabAvailable.CurrentEstimate.HighRange; cabTile.TextLine2 = "ETA : " + cabAvailable.Eta; ContentTiles.Add(cabTile); } var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, ContentTiles); var voiceCommandDisambiguationResult = await voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null) { return((CabEstimate)voiceCommandDisambiguationResult.SelectedItem.AppContext); } return(null); }
private static async Task <VoiceCommandDisambiguationResult> AsyncRequestDisambiguation(VoiceCommandServiceConnection connection, string promptSpokenMessage, string promptDisplayMessage, string repromptSpokenMessage, string repromptDisplayMessage, IEnumerable <VoiceCommandContentTile> contentTiles) { var prompt = new VoiceCommandUserMessage { DisplayMessage = promptDisplayMessage, SpokenMessage = promptSpokenMessage }; var reprompt = new VoiceCommandUserMessage { DisplayMessage = repromptDisplayMessage, SpokenMessage = repromptSpokenMessage }; var response = VoiceCommandResponse.CreateResponseForPrompt(prompt, reprompt, contentTiles); try { var result = await connection.RequestDisambiguationAsync(response); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return(null); }
/// <summary> /// Handles an interaction with Cortana where the user selects /// from randomly chosen colors to change the lights to. /// </summary> private async Task SelectColorAsync() { var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = "Here's some colors you can choose from."; var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = "Sorry, didn't catch that. What color would you like to use?"; // Randomly select 6 colors for Cortana to show var random = new Random(); var colorContentTiles = _colors.Select(x => new VoiceCommandContentTile { ContentTileType = VoiceCommandContentTileType.TitleOnly, Title = x.Value.Name }).OrderBy(x => random.Next()).Take(6); var colorResponse = VoiceCommandResponse.CreateResponseForPrompt( userPrompt, userReprompt, colorContentTiles); var disambiguationResult = await _voiceServiceConnection.RequestDisambiguationAsync(colorResponse); if (null != disambiguationResult) { var selectedColor = disambiguationResult.SelectedItem.Title; foreach (Light light in _lights) { await ExecutePhrase(light, selectedColor); await Task.Delay(500); } var response = CreateCortanaResponse($"Turned your lights {selectedColor}."); await _voiceServiceConnection.ReportSuccessAsync(response); } }
private async Task SearchCheckedOutDocumentsAsync(string rootSiteUrl, string searchAPIUrl) { await ShowProgressScreen("Finding documents checked out to you..."); VoiceCommandResponse response; var destinationsContentTiles = new List <VoiceCommandContentTile>(); var documents = await Core.Helpers.SharePointHelper.GetSharePointDocuments(rootSiteUrl, searchAPIUrl); if (documents.Count > 0) { foreach (var document in documents) { var destinationTile = new VoiceCommandContentTile(); try { destinationTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; destinationTile.Image = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Office365Search.Services.Background" + document.IconUrl.EnsureStartsWith("/"))); // destinationTile.AppLaunchArgument = "type=" + "SharePointWhatsCheckedOutQueryCommand" + "&itemId=" + document.ItemId.ToString(); destinationTile.AppLaunchArgument = document.Url; destinationTile.Title = document.Title; destinationTile.TextLine1 = "Last modified: " + document.ModifiedDate.ToString(); // destinationTile.TextLine2 = "test"; // destinationTile.TextLine1 = document.AuthorInformation.DisplayName; // destinationTile.TextLine1 = "modified: " + document; // destinationTile.TextLine2 = "views: " + document.ViewCount; destinationTile.AppContext = document; destinationsContentTiles.Add(destinationTile); } catch (Exception ex) { } } await ShowProgressScreen("I found " + documents.Count + " documents..."); var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = "Which document you want to open?"; var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = "Please suggest, Which document you want to open?"; response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, destinationsContentTiles); // await voiceServiceConnection.ReportSuccessAsync(response); try { var voiceCommandDisambiguationResult = await voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null && voiceCommandDisambiguationResult.SelectedItem != null) { string uriToLaunch = voiceCommandDisambiguationResult.SelectedItem.AppLaunchArgument; var uri = new Uri(uriToLaunch); // var success = Windows.System.Launcher.LaunchUriAsync(uri); var userMessage = new VoiceCommandUserMessage(); userMessage.DisplayMessage = "Opening the Document."; userMessage.SpokenMessage = "Opening the Document."; response = VoiceCommandResponse.CreateResponse(userMessage); response.AppLaunchArgument = uri.ToString(); await voiceServiceConnection.RequestAppLaunchAsync(response); //var userConfirmMessage = new VoiceCommandUserMessage(); //userConfirmMessage.DisplayMessage = userConfirmMessage.SpokenMessage = "Requested Document Opened. Thank you!"; //response = VoiceCommandResponse.CreateResponse(userConfirmMessage); //response.AppLaunchArgument = uri.ToString(); //await voiceServiceConnection.ReportSuccessAsync(response); } } catch (Exception ex) { } } else { response = VoiceCommandResponse.CreateResponse(new VoiceCommandUserMessage() { DisplayMessage = "There's nothing checked out to you", SpokenMessage = "I didn't find anything checked out to you. Time to get working on something." }, destinationsContentTiles); await voiceServiceConnection.ReportSuccessAsync(response); } return; }
private async Task <Model.Light> DisambiguateLights(IEnumerable <Model.Light> lights, string disambiguationMessage, string secondDisambiguationMessage) { // Create the first prompt message. var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = disambiguationMessage; // Create a re-prompt message if the user responds with an out-of-grammar response. var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = secondDisambiguationMessage; // Create items for each item. Ideally, should be limited to a small number of items. var roomContentTiles = new List <VoiceCommandContentTile>(); int i = 1; foreach (Model.Light light in lights) { var roomTile = new VoiceCommandContentTile(); // To handle UI scaling, Cortana automatically looks up files with FileName.scale-<n>.ext formats based on the requested filename. // See the VoiceCommandService\Images folder for an example. roomTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; roomTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///ListenApp.VoiceCommands/Images/GreyTile.png")); // The AppContext can be any arbitrary object, and will be maintained for the // response. roomTile.AppContext = light; string message = ""; if (light.Color != null) { message = light.Color; } else { // The app allows a trip to not have a date, but the choices must be unique // so they can be spoken aloud and be distinct, so add a number to identify them. message = string.Format("{0}", i); } roomTile.Title = light.Room + " " + message; roomTile.TextLine1 = light.Description; roomContentTiles.Add(roomTile); i++; } // Cortana will handle re-prompting if the user does not provide a valid response. var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, roomContentTiles); // If cortana is dismissed in this operation, null will be returned. var voiceCommandDisambiguationResult = await voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null) { return((Model.Light)voiceCommandDisambiguationResult.SelectedItem.AppContext); } return(null); }
private async Task SendCompletionMessageForAmbiance() { await ShowProgressScreen("Changement d'ambiance ..."); var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = "Quelle ambiance voulez vous choisir ?"; var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = "Quelle ambiance ?"; var ambianceContentTiles = new List <VoiceCommandContentTile>(); var ambianceWork = new VoiceCommandContentTile(); ambianceWork.ContentTileType = VoiceCommandContentTileType.TitleWithText; ambianceWork.Title = "Ambiance de travail"; ambianceWork.TextLine1 = "Permet de mettre les lampes en vert"; ambianceWork.AppContext = "work"; var ambianceCool = new VoiceCommandContentTile(); ambianceCool.ContentTileType = VoiceCommandContentTileType.TitleWithText; ambianceCool.Title = "Ambiance de détente"; ambianceCool.TextLine1 = "Permet de mettre les lampes en bleu"; ambianceCool.AppContext = "cool"; ambianceContentTiles.Add(ambianceWork); ambianceContentTiles.Add(ambianceCool); var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, ambianceContentTiles); var voiceCommandDisambiguationResult = await _voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null) { string ambiance = voiceCommandDisambiguationResult.SelectedItem.AppContext as string; userPrompt.DisplayMessage = userPrompt.SpokenMessage = "Activer l'ambiance " + ambiance; userReprompt.DisplayMessage = userReprompt.DisplayMessage = "Voulez vous activer l'ambiance " + ambiance + "?"; response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt); var voiceCommandConfirmation = await _voiceServiceConnection.RequestConfirmationAsync(response); // If RequestConfirmationAsync returns null, Cortana's UI has likely been dismissed. if (voiceCommandConfirmation != null) { if (voiceCommandConfirmation.Confirmed == true) { await ShowProgressScreen("Activation de l'ambiance"); var dataAccess = new DataAccess.Light(); // Job to Active Ambiance switch (ambiance) { case "work": await dataAccess.On(new Light() { State = true, LightId = 1, Color = new Color() { B = 1 } }); break; case "cool": await dataAccess.On(new Light() { State = true, LightId = 1, Color = new Color() { G = 1 } }); break; default: break; } var userMessage = new VoiceCommandUserMessage(); userMessage.DisplayMessage = userMessage.SpokenMessage = "L'ambiance " + ambiance + " a été activée"; response = VoiceCommandResponse.CreateResponse(userMessage); await _voiceServiceConnection.ReportSuccessAsync(response); } } } }
/// <summary> /// Demonstrates providing the user with a choice between multiple items. In this case, if a user /// has two trips to the same destination with different dates, this will provide a way to differentiate /// them. Provide a way to choose between the items. /// </summary> /// <param name="trips">The set of trips to choose between</param> /// <param name="disambiguationMessage">The initial disambiguation message</param> /// <param name="secondDisambiguationMessage">Repeat prompt retry message</param> /// <returns></returns> private async Task <Model.Trip> DisambiguateTrips(IEnumerable <Model.Trip> trips, string disambiguationMessage, string secondDisambiguationMessage) { // Create the first prompt message. var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = disambiguationMessage; // Create a re-prompt message if the user responds with an out-of-grammar response. var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = secondDisambiguationMessage; // Create items for each item. Ideally, should be limited to a small number of items. var destinationContentTiles = new List <VoiceCommandContentTile>(); int i = 1; foreach (Model.Trip trip in trips) { var destinationTile = new VoiceCommandContentTile(); // Use a generic background image. This can be fetched from a service call, potentially, but // be aware of network latencies and ensure Cortana does not time out. destinationTile.ContentTileType = VoiceCommandContentTileType.TitleWith68x68IconAndText; destinationTile.Image = await Package.Current.InstalledLocation.GetFileAsync("AdventureWorks.VoiceCommands\\Images\\GreyTile.png"); // The AppContext can be any arbitrary object, and will be maintained for the // response. destinationTile.AppContext = trip; string dateFormat = ""; if (trip.StartDate != null) { dateFormat = trip.StartDate.Value.ToString(dateFormatInfo.LongDatePattern); } else { // The app allows a trip to not have a date, but the choices must be unique // so they can be spoken aloud and be distinct, so add a number to identify them. dateFormat = string.Format("{0}", i); } //destinationTile.Title = trip.Destination + " " + dateFormat; //destinationTile.TextLine1 = trip.Description; destinationTile.Title = trip.Description; //REVERT lines above destinationTile.TextLine1 = dateFormat; destinationContentTiles.Add(destinationTile); i++; } // Cortana will handle re-prompting if the user does not provide a valid response. var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, destinationContentTiles); // If cortana is dismissed in this operation, null will be returned. var voiceCommandDisambiguationResult = await voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null) { xyz = voiceCommandDisambiguationResult.SelectedItem; return((Model.Trip)voiceCommandDisambiguationResult.SelectedItem.AppContext); } return(null); }
/// <summary> /// Demonstrates providing the user with a choice between multiple items. In this case, if a user /// has two trips to the same destination with different dates, this will provide a way to differentiate /// them. Provide a way to choose between the items. /// </summary> /// <param name="trips">The set of trips to choose between</param> /// <param name="disambiguationMessage">The initial disambiguation message</param> /// <param name="secondDisambiguationMessage">Repeat prompt retry message</param> /// <returns></returns> private async Task <Model.Trip> DisambiguateTrips(IEnumerable <Model.Trip> trips, string disambiguationMessage, string secondDisambiguationMessage) { // Create the first prompt message. var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = disambiguationMessage; // Create a re-prompt message if the user responds with an out-of-grammar response. var userReprompt = new VoiceCommandUserMessage(); userReprompt.DisplayMessage = userReprompt.SpokenMessage = secondDisambiguationMessage; // Create items for each item. Ideally, should be limited to a small number of items. var destinationContentTiles = new List <VoiceCommandContentTile>(); int i = 1; foreach (Model.Trip trip in trips) { var destinationTile = new VoiceCommandContentTile(); // To handle UI scaling, Cortana automatically looks up files with FileName.scale-<n>.ext formats based on the requested filename. // See the VoiceCommandService\Images folder for an example. destinationTile.ContentTileType = VoiceCommandContentTileType.TitleWith280x140Icon; destinationTile.Image = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///AdventureWorks.VoiceCommands/Images/GreyTile.png")); // The AppContext can be any arbitrary object, and will be maintained for the // response. destinationTile.AppContext = trip; string dateFormat = ""; if (trip.StartDate != null) { dateFormat = trip.StartDate.Value.ToString(dateFormatInfo.LongDatePattern); } else { // The app allows a trip to not have a date, but the choices must be unique // so they can be spoken aloud and be distinct, so add a number to identify them. dateFormat = string.Format("{0}", i); } destinationTile.Title = trip.Destination + " " + dateFormat; destinationTile.TextLine1 = trip.Description; destinationContentTiles.Add(destinationTile); i++; } // Cortana will handle re-prompting if the user does not provide a valid response. var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt, destinationContentTiles); // If cortana is dismissed in this operation, null will be returned. var voiceCommandDisambiguationResult = await voiceServiceConnection.RequestDisambiguationAsync(response); if (voiceCommandDisambiguationResult != null) { return((Model.Trip)voiceCommandDisambiguationResult.SelectedItem.AppContext); } return(null); }
private async Task <string> GetSingleTask(List <string> ListOfTasks, string Message, string SecondMessage) { var UserMessage = new VoiceCommandUserMessage(); UserMessage.DisplayMessage = UserMessage.SpokenMessage = Message; var UserReMessage = new VoiceCommandUserMessage(); UserReMessage.DisplayMessage = UserReMessage.SpokenMessage = SecondMessage; string SelectedTask; int Result; do { var TaskTiles = new List <VoiceCommandContentTile>(); int i = 1; foreach (string Task in ListOfTasks) { if (i <= 10) { var TaskTile = new VoiceCommandContentTile(); TaskTile.ContentTileType = VoiceCommandContentTileType.TitleOnly; TaskTile.AppContext = TaskTile; TaskTile.AppLaunchArgument = Task; TaskTile.Title = Task; TaskTiles.Add(TaskTile); i++; } else { UserMessage.SpokenMessage += " I'm showing only first ten."; break; } } // Cortana will handle re-prompting if the user does not provide a valid response. var Response = VoiceCommandResponse.CreateResponseForPrompt(UserMessage, UserReMessage, TaskTiles); // If cortana is dismissed in this operation, null will be returned. var VoiceCommandDisambiguationResult = await VoiceServiceConnection.RequestDisambiguationAsync(Response); if (VoiceCommandDisambiguationResult != null) { SelectedTask = (string)VoiceCommandDisambiguationResult.SelectedItem.AppContext; } else { return(null); } Result = await CheckInput(SelectedTask, Message : $"Is {SelectedTask} your task?", SecondMessage : $"Is {SelectedTask} your task?"); if (Result == -1) { return(null); } }while (Result == 0); return(SelectedTask); }