我已经创建了一个有一些移动元素/对象的故事板,我想在一个故事板中添加一个SpeechSynthesizer。
这有可能吗?我正在研究C#。
Storyboard myStoryboard=new Storyboard();
SpeechSynthesizer reader = new SpeechSynthesizer();
reader.Speak("This is my first speech project"); /* instead of speak I want
to add this into the storyboard
.....
myStoryboard.Children.Add(readerAnimation);还是有一种方法可以将音频添加到故事板中?
发布于 2013-07-29 03:38:06
如果您愿意使用音频文件,则可以使用MediaTimeLine类。然后,您可以使用其中一个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>请注意,一旦Storyboard播放该文件,它将维护对它的锁定。
https://stackoverflow.com/questions/17914655
复制相似问题