原文:UWP-电子音读出文字
源码: 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 声音
参考:http://www.cnblogs.com/tcjiaan/
参考: http://www.win10.me/?p=535
时间: 2024-10-02 18:47:29