private void ButtonStopListening_Click(object sender, RoutedEventArgs e) { //microphone.Stop(); PopupVoice.IsOpen = false; client.RecognizeAsync( Settings.CachedAuthenticationToken, encodedFrames.ToArray(), true, null, null); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (String.IsNullOrEmpty(Settings.CachedAuthenticationToken)) { NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative)); return; } if (e.NavigationMode == NavigationMode.Back) { return; } User.Text = "Hello " + Settings.Username; client = new SpeechServiceClient( GetBinding(), GetEndpointAddress("Speech")); client.RecognizeCompleted += (o1, e1) => { HideProgress(); if (e1.Error != null) { if (e1.Error.GetType() == typeof(FaultException <AuthenticationFault>)) { GetAuthenticationToken( new Action( () => { client.RecognizeAsync( Settings.CachedAuthenticationToken, encodedFrames.ToArray(), false, null, null); } )); } else { MessageBox.Show(e1.Error.Message); } return; } if (e1.Result.AnswerSpeech != null && e1.Result.AnswerSpeech.Length > 0) { // Play the audio in a new thread so the UI can update. new Thread( () => { byte[] speechBuffer = Speex.DecodeAllFrames(e1.Result.AnswerSpeech); //SoundEffect sound = new SoundEffect(speechBuffer, 24000, AudioChannels.Mono);//microphone.SampleRate, AudioChannels.Mono); //soundInstance = sound.CreateInstance(); //soundInstance.Play(); }).Start(); } // TODO: MessageBox.Show(String.Format("I am {0}% confident you said \"{1}\". To which I reply \"{2}\".", e1.Result.Confidence * 100, e1.Result.Command, e1.Result.AnswerText)); }; int counter = 0; foreach (var endpoint in Settings.Endpoints) { if (endpoint.Key == "Speech" || endpoint.Key == "Recipes") { continue; } HubTile tile = new HubTile() { Margin = new Thickness(12, 12, 0, 0), Source = new BitmapImage(new Uri("/Images/" + endpoint.Key + ".png", UriKind.Relative)), Name = endpoint.Key, //Title = endpoint.Key, IsFrozen = true, //Background = (SolidColorBrush)Resources["PhoneAccentBrush"], //Message = "Message", //DisplayNotification = true, //Notification = "Notification", }; tile.SetValue(Grid.ColumnProperty, counter % 2); tile.SetValue(Grid.RowProperty, counter / 2); tile.Tap += (o1, e1) => { NavigationService.Navigate(new Uri("/" + ((HubTile)o1).Name + "Page.xaml", UriKind.Relative)); }; tile.MouseLeftButtonDown += (o1, e1) => { System.Windows.Point tmpPoint = e1.GetPosition(null); contextMenuSelectedHubTile = null; List <UIElement> oControls = (List <UIElement>)VisualTreeHelper.FindElementsInHostCoordinates(tmpPoint, this); foreach (UIElement ctrl in oControls) { if (ctrl is HubTile) { contextMenuSelectedHubTile = (HubTile)ctrl; break; } } }; TileGrid.Children.Add(tile); counter++; } HideProgress(); }