win10 UWP 你写我读
最后更新于:2022-04-01 20:23:32
想要电脑读出我们写的内容,在win10,很简单
其实这个技术在windows7就有了,但是现在win10让写出一个你写我读的软件很简单。
我们需要一个类`MediaElement`来播放,因为windows10的Markdown软件用的不是很好,所有我自己写一个。
这个软件我用了你写我读,[https://github.com/lindexi/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();
~~~
~~~
~~~
Volume 声音
参考:[http://www.cnblogs.com/tcjiaan/](http://www.cnblogs.com/tcjiaan/)
';