【发布时间】:2018-07-07 17:47:19
【问题描述】:
如何在 UWP 下使用 SpeechSynthesis 类实现等效的 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
【问题讨论】: