コード例 #1
0
 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) });
     };
 }
コード例 #2
0
        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 });
                        }
                    });
        }