语音合成
在System.Speech程序集中,微软增加了一些非常酷的东西:语音合成,将文本转换为语音的能力,以及语音识别,将语音识别成文本的能力。 我们将专注于本文中的语音合成,然后在下一章进行语音识别。
要将文本转换为语音,我们将使用SpeechSynthesizer类。 这个类在System.Speech程序集中,我们需要添加它以在我们的应用程序中使用它。 根据您使用的Visual Studio版本,该过程如下所示:
添加适当的程序集后,我们现在可以使用System.Speech.Synthesis命名空间中的SpeechSynthesizer类。 有了这个,我们将开始另一个非常简单的“Hello,world!” 的例子,这次用语音:
<Window x:Class="WpfTutorialSamples.Audio_and_Video.SpeechSynthesisSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="SpeechSynthesisSample" Height="150" Width="150">
<Grid>
<Button Name="btnSayIt" Click="btnSayHello_Click" VerticalAlignment="Center" HorizontalAlignment="Center">Say hello!</Button>
</Grid>
</Window>