I'm writing a WP8.1 app, and am trying to output a voice in the following way:
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
var voiceStream = await synth.SynthesizeTextToStreamAsync("test 1");
MediaElement mediaElement = new MediaElement();
mediaElement.SetSource(voiceStream, voiceStream.ContentType);
mediaElement.AutoPlay = false;
mediaElement.Volume = 1;
mediaElement.IsMuted = false;
mediaElement.Play();
}
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
var voiceStream = await synth.SynthesizeTextToStreamAsync("test 2");
MediaElement mediaElement = new MediaElement();
mediaElement.SetSource(voiceStream, voiceStream.ContentType);
mediaElement.AutoPlay = false;
mediaElement.Volume = 1;
mediaElement.IsMuted = false;
mediaElement.Play();
}
And this does work... but it appears to be playing both at the same time - so it just sounds like an echo. I can't see any way to wait the play to finish, or to be notified when it does - is there one?
Play
? Or event? (I fail to find documentation ofMediaElement.Play()
method).