如果您願意使用audiofile,則可以使用MediaTimeLine
類。然後,您可以使用SpeachSynthesizer's SetOutputToWaveFile
方法之一來創建文件。
保存waveFile從第二個鏈接修改:
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
synth.SetOutputToWaveFile(@"C:\temp\Sample.wav");
PromptBuilder builder = new PromptBuilder();
builder.AppendText("Hello World !");
synth.Speak(builder);
}
的XAML
從第一鏈接修改播放文件
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="100" Width="200">
<StackPanel Background="Black">
<Label Name="clickMe" Content="Click Me" Foreground="White" FontFamily="Arabic Typesetting" FontSize="20" HorizontalContentAlignment ="Center" />
<MediaElement Name="myMediaElement" Width="0" Height="0" />
<StackPanel.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.MouseDown" SourceName="clickMe">
<EventTrigger.Actions>
<BeginStoryboard Name= "myBegin">
<Storyboard x:Name="myStoryBoard" SlipBehavior="Slip">
<MediaTimeline Source="C:\temp\Sample.wav" Storyboard.TargetName="myMediaElement" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</Window>
注意,一旦故事板播放文件時,它將保持鎖定。
SpeechSynthesizer我不是一個框架元素,所以你不能動畫它,你只是想找一種方法來動畫屏幕上的文字? –
不需要。我想將SpeechSynthesizer加入故事板。 基本上我有一個包含許多動畫的故事板。我還想添加SpeechSynthesizer。 – galaxias
和你期望會發生什麼,即使你可以添加它什麼都不會做,SpeechSynthesizer只是一個類, –