private void YesButton_Click(object sender, RoutedEventArgs e) { GlobalVariables.CurrentTracker.SendEvent(EventCategories.VoiceCommand, EventActions.Click, "VoiceCommandYes", 0); switch (searchHitState) { case SearchHitState.Single: Frame.Navigate(typeof(CoverPage)); break; case SearchHitState.None: switch (searchType) { case SearchType.Album: SearchedItemsListView.ItemsSource = allAlbums; break; case SearchType.Artist: SearchedItemsListView.ItemsSource = allArtists; break; case SearchType.Movie: SearchedItemsListView.ItemsSource = allMovies; break; default: SearchedItemsListView.ItemsSource = null; break; } searchHitState = SearchHitState.All; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Collapsed; break; default: break; } }
private async void ExecuteVoiceCommand(SpeechRecognitionResult result) { bool isConnected = await LoadAndConnnect(); if (!isConnected) { return; } string voiceCommandName = result.RulePath[0]; string textSpoken = result.Text; switch (voiceCommandName) { case "PlayArtist": searchType = SearchType.Artist; string artistName = SemanticInterpretation("musicTopic", result); allArtists = await AudioLibrary.GetArtists(); var filteredArtists = allArtists.Where(t => t.Label.ToLower().Contains(artistName.ToLower())).ToList(); if (filteredArtists.Count > 1) { searchHitState = SearchHitState.Multiple; ReceivedCommandTextBlock.Text = "We found multiple artists. Choose one..."; SearchedItemsListView.ItemsSource = filteredArtists; } else if (filteredArtists.Count > 0) { searchHitState = SearchHitState.Single; ReceivedCommandTextBlock.Text = "This is the artist we found..."; SearchedItemsListView.ItemsSource = filteredArtists; Player.PlayArtist(filteredArtists[0]); QuestionNameTextBlock.Text = "Did we get the right one?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { searchHitState = SearchHitState.None; ReceivedCommandTextBlock.Text = "Sorry, we couldn't find what you asked for."; //SearchedItemsListView.ItemsSource = allArtists; QuestionNameTextBlock.Text = "Would you like to see a list of all artists?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } break; case "PlayMovie": searchType = SearchType.Movie; string movieName = SemanticInterpretation("movieTopic", result); allMovies = await VideoLibrary.GetMovies(); var filteredMovies = allMovies.Where(t => t.Title.ToLower().Contains(movieName.ToLower())).ToList(); if (filteredMovies.Count > 1) { searchHitState = SearchHitState.Multiple; ReceivedCommandTextBlock.Text = "We found multiple movies. Choose one..."; SearchedItemsListView.ItemsSource = filteredMovies; } else if (filteredMovies.Count > 0) { searchHitState = SearchHitState.Single; ReceivedCommandTextBlock.Text = "This is the movie we found..."; SearchedItemsListView.ItemsSource = filteredMovies; Player.PlayMovie(filteredMovies[0]); QuestionNameTextBlock.Text = "Did we find the right one?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { searchHitState = SearchHitState.None; ReceivedCommandTextBlock.Text = "Sorry, we couldn't find what you asked for. Here is the list of all movies."; //SearchedItemsListView.ItemsSource = allMovies; QuestionNameTextBlock.Text = "Would you like to see a list of all movies?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } break; case "PlayAlbum": searchType = SearchType.Album; string albumName = SemanticInterpretation("musicTopic", result); allAlbums = await AudioLibrary.GetAlbums(); var filteredAlbums = allAlbums.Where(t => t.Title.ToLower().Contains(albumName.ToLower())).ToList(); if (filteredAlbums.Count > 1) { searchHitState = SearchHitState.Multiple; ReceivedCommandTextBlock.Text = "We found multiple albums. Choose one..."; SearchedItemsListView.ItemsSource = filteredAlbums; } else if (filteredAlbums.Count > 0) { searchHitState = SearchHitState.Single; ReceivedCommandTextBlock.Text = "This is the album we found..."; SearchedItemsListView.ItemsSource = filteredAlbums; Player.PlayAlbum(filteredAlbums[0]); QuestionNameTextBlock.Text = "Did we get the right one?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { searchHitState = SearchHitState.None; ReceivedCommandTextBlock.Text = "Sorry, we couldn't find what you asked for. Here is the list of all albums."; //SearchedItemsListView.ItemsSource = allAlbums; QuestionNameTextBlock.Text = "Would you like to see a list of all albums?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } break; case "StartParty": await Player.PlayPartyMode(); ReceivedCommandTextBlock.Text = "Started party mode!"; await Task.Delay(1000); Frame.Navigate(typeof(CoverPage)); break; default: break; } if (searchHitState == SearchHitState.Single) { GlobalVariables.CurrentTracker.SendEvent(EventCategories.VoiceCommand, EventActions.VoiceCommand, "Single" + voiceCommandName, 0); } else if (searchHitState == SearchHitState.None) { GlobalVariables.CurrentTracker.SendEvent(EventCategories.VoiceCommand, EventActions.VoiceCommand, "Zero" + voiceCommandName, 0); } }
public VoiceCommandsPage() { this.InitializeComponent(); //HardwareButtons.BackPressed += HardwareButtons_BackPressed; searchHitState = SearchHitState.None; }
private async void ExecuteVoiceCommand(SpeechRecognitionResult result) { bool isConnected = await LoadAndConnnect(); if (!isConnected) return; string voiceCommandName = result.RulePath[0]; string textSpoken = result.Text; switch (voiceCommandName) { case "PlayArtist": searchType = SearchType.Artist; string artistName = SemanticInterpretation("musicTopic", result); allArtists = await AudioLibrary.GetArtists(); var filteredArtists = allArtists.Where(t => t.Label.ToLower().Contains(artistName.ToLower())).ToList(); if (filteredArtists.Count > 1) { searchHitState = SearchHitState.Multiple; ReceivedCommandTextBlock.Text = "We found multiple artists. Choose one..."; SearchedItemsListView.ItemsSource = filteredArtists; } else if (filteredArtists.Count > 0) { searchHitState = SearchHitState.Single; ReceivedCommandTextBlock.Text = "This is the artist we found..."; SearchedItemsListView.ItemsSource = filteredArtists; Player.PlayArtist(filteredArtists[0]); QuestionNameTextBlock.Text = "Did we get the right one?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { searchHitState = SearchHitState.None; ReceivedCommandTextBlock.Text = "Sorry, we couldn't find what you asked for."; //SearchedItemsListView.ItemsSource = allArtists; QuestionNameTextBlock.Text = "Would you like to see a list of all artists?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } break; case "PlayMovie": searchType = SearchType.Movie; string movieName = SemanticInterpretation("movieTopic", result); allMovies = await VideoLibrary.GetMovies(); var filteredMovies = allMovies.Where(t => t.Title.ToLower().Contains(movieName.ToLower())).ToList(); if (filteredMovies.Count > 1) { searchHitState = SearchHitState.Multiple; ReceivedCommandTextBlock.Text = "We found multiple movies. Choose one..."; SearchedItemsListView.ItemsSource = filteredMovies; } else if (filteredMovies.Count > 0) { searchHitState = SearchHitState.Single; ReceivedCommandTextBlock.Text = "This is the movie we found..."; SearchedItemsListView.ItemsSource = filteredMovies; Player.PlayMovie(filteredMovies[0]); QuestionNameTextBlock.Text = "Did we find the right one?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { searchHitState = SearchHitState.None; ReceivedCommandTextBlock.Text = "Sorry, we couldn't find what you asked for. Here is the list of all movies."; //SearchedItemsListView.ItemsSource = allMovies; QuestionNameTextBlock.Text = "Would you like to see a list of all movies?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } break; case "PlayAlbum": searchType = SearchType.Album; string albumName = SemanticInterpretation("musicTopic", result); allAlbums = await AudioLibrary.GetAlbums(); var filteredAlbums = allAlbums.Where(t => t.Title.ToLower().Contains(albumName.ToLower())).ToList(); if (filteredAlbums.Count > 1) { searchHitState = SearchHitState.Multiple; ReceivedCommandTextBlock.Text = "We found multiple albums. Choose one..."; SearchedItemsListView.ItemsSource = filteredAlbums; } else if (filteredAlbums.Count > 0) { searchHitState = SearchHitState.Single; ReceivedCommandTextBlock.Text = "This is the album we found..."; SearchedItemsListView.ItemsSource = filteredAlbums; Player.PlayAlbum(filteredAlbums[0]); QuestionNameTextBlock.Text = "Did we get the right one?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } else { searchHitState = SearchHitState.None; ReceivedCommandTextBlock.Text = "Sorry, we couldn't find what you asked for. Here is the list of all albums."; //SearchedItemsListView.ItemsSource = allAlbums; QuestionNameTextBlock.Text = "Would you like to see a list of all albums?"; QuestionWrapper.Visibility = Windows.UI.Xaml.Visibility.Visible; } break; case "StartParty": await Player.PlayPartyMode(); ReceivedCommandTextBlock.Text = "Started party mode!"; await Task.Delay(1000); Frame.Navigate(typeof(CoverPage)); break; default: break; } if (searchHitState == SearchHitState.Single) { GlobalVariables.CurrentTracker.SendEvent(EventCategories.VoiceCommand, EventActions.VoiceCommand, "Single" + voiceCommandName, 0); } else if (searchHitState == SearchHitState.None) { GlobalVariables.CurrentTracker.SendEvent(EventCategories.VoiceCommand, EventActions.VoiceCommand, "Zero" + voiceCommandName, 0); } }