win10 UWP 你写我读

想要电脑读出我们写的内容,在win10,很简单
其实这个技术在windows7就有了,但是现在win10让写出一个你写我读的软件很简单。
我们需要一个类MediaElement来播放,因为windows10的Markdown软件用的不是很好,所有我自己写一个。
这个软件我用了你写我读,https://github.com/lindexi/Markdown
这里写图片描述

点击这里写图片描述 读出文本

在使用SpeechSynthesizer需要代码功能点麦克风

这里写图片描述

这里写图片描述

代码我放在model
代码很少就可以你写我读

        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/

原文地址:https://www.cnblogs.com/lindexi/p/12087654.html