public async void Speak(MediaElement audioPlayer, SpeechMessage speech) { var synth = new SpeechSynthesizer(); var ttsStream = await synth.SynthesizeTextToStreamAsync(speech.Message); audioPlayer.SetSource(ttsStream, ""); audioPlayer.CurrentStateChanged += async (object sender, Windows.UI.Xaml.RoutedEventArgs e) => { await MainPage.Instance.SendResult(new ResultMessage(speech) { ResultId = (int)audioPlayer.CurrentState, Result = Enum.GetName(typeof(MediaElementState), audioPlayer.CurrentState) }); }; }
private async void Speak(SpeechMessage speech) { var service = new Speech(); await this.dispatcher.RunAsync( CoreDispatcherPriority.Normal, async () => { try { if (speech.Action != null && speech.Action.Equals("STOP")) { this.player?.Stop(); } else { service.Speak(this.player, speech); } } catch (Exception e) { await this.SendResult(new ResultMessage(speech) { Result = e.Message, ResultId = e.HResult }); } }); }