オーディオファイルを使用する場合は、MediaTimeLine
クラスを使用できます。その後、 SpeechSynthesizer の SetOutputToWaveFile
メソッドの1 つを使用してファイルを作成できます。
2 番目のリンクから変更された 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>
ストーリーボードがファイルを再生すると、ロックが維持されることに注意してください。