源码: https://github.com/lindexi/Markdown
代码
private async void speech(string str, MediaElement media_element)
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(str);
media_element.SetSource(stream, stream.ContentType);
media_element.Play();
}
实例化SpeechSynthesizer,使用SynthesizeTextToStreamAsync把文本变为流
可以使用MediaElement播放,MediaElement播放需要把流和格式放到MediaElement
media_element.Play();
<MediaElement Grid.Row=“0” x:Name=“mediaelement” AutoPlay=“True” Volume=“1.0” />
Volume 声音