我正在尝试编写代码来朗读传入的Toast(这在WP8.1中是微不足道的) 到目前为止我有这个
我已尝试过UI线程(MediaElement仅适用于UI线程)和来自处理传入Toast的线程的BackgroundMediaPlayer
var mediaElement = new MediaElement();
using (var tts = new SpeechSynthesizer())
{
using (var ttsStream = await tts.SynthesizeSsmlToStreamAsync(ssml))
{
//BackgroundMediaPlayer.Current.SetStreamSource(ttsStream);
mediaElement.SetSource(ttsStream, ttsStream.ContentType);
mediaElement.Play();
}
}
我显然在这里错过了一些简单的东西但是我没有想法如何使这项工作。 SSML是正确的,我认为它可能与范围和线程
有关答案 0 :(得分:1)
var synth = new SpeechSynthesizer();
var voice = SpeechSynthesizer.DefaultVoice;
var newuserText = TheMessage
var stream = await synth.SynthesizeTextToStreamAsync(newuserText);
var mediaElement = new MediaElement();
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();