我该如何在使用SpeechSynthesis类的UWP中实现类似于SpeakProgressEvent的功能呢?WPF/.NET中有这个事件可以挂钩,然而,在UWP框架中他们在哪里隐藏了这个特性我非常困惑。是否.NET SpeakProgressEvent有办法映射到UWP的MediaElement事件上呢?
// NOTE: This is a windows 10 UWP Application (Not WPF/.NET)
using Windows.Media.SpeechSynthesis;
using System.Threading.Tasks;
//XAML: <MediaElement Name="mediaElement"/>
namespace App1
{
public sealed partial class MainPage : Page
{
SpeechSynthesizer synth;
public MainPage()
{
this.InitializeComponent();
synth = new SpeechSynthesizer();
// Doesn't Exist for UWP
synth.SpeakProgress
+= new EventHandler<SpeakProgressEventArgs>
(synthesizer_SpeakProgress);
// Doesn't Exist for UWP
synth.SpeakStarted
+= new EventHandler<SpeakStartedEventArgs>
(synthesizer_SpeakStarted);
// Doesn't Exist for UWP
synth.SpeakCompleted
+= new EventHandler<SpeakCompletedEventArgs>
(synthesizer_SpeakCompleted);
} //MainPage
async Task Speak(string text)
{
SpeechSynthesisStream speech;
speech = await synth.SynthesizeTextToStreamAsync(text);
mediaElement.SetSource(speech, speech.ContentType);
}
void synthesizer_SpeakProgress(
object sender, SpeakProgressEventArgs e)
{
//show the synthesizer's current progress
//labelProgress.Content = e.Text;
//SolidColorBrush highlightColor
// = new SolidColorBrush(Colors.Yellow);
//HighlightWordInRichTextBox(
// richTextBox1, e.Text, highlightColor);
}
} //class
} //namespace