Reputation: 7512
I'm trying to write code to read aloud an incoming Toast (this was trivial in WP8.1) I have this so far
I've tried both from the UI thread (MediaElement only works on the UI thread) and BackgroundMediaPlayer from the thread that handles the incoming toast
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();
}
}
I'm obviously missing something simple here but I'm out of ideas how to make this work. The SSML is correct, I think it's probably something to do with scoping and threads
Upvotes: 0
Views: 392
Reputation: 341
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();
Upvotes: 1