As I described here:
I have a method
async SpeakAsync(string language, string text)
:var synth = new SpeechSynthesizer(); var player = new MediaPlayer(); SetVoice(language, ref synth); var source = await synth.SynthesizeTextToStreamAsync(text); player.SetStreamSource(source); synth.Dispose(); player.MediaEnded += (_, _) => { source.Dispose(); player.Dispose(); } player.Play();
If I call this method twice with
.Wait()
followed, my app will stuck atvar source = await synth.SynthesizeTextToStreamAsync(text);
forever for the second call (the first call runs perfectly).
I did what @DarranRowe said with storing a MediaPlayer
instance and a SpeechSynthesisStream
instance in a field of my class. I set the SpeechSynthesisStream
instance to null
at every time the method got called. But the problem still exists, and I don't know why this would solve my problem.
Please comment or answer here, the GitHub discussion I referenced above is not a place for this question.