gpt4 book ai didi

c# - SpeechSynthesizer 到 Storyboard

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:17 26 4
gpt4 key购买 nike

我创建了一个 Storyboard,其中包含一些移动元素/对象,我想将 SpeechSynthesizer 添加到 Storyboard中。

这可能吗?我正在使用 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);

或者有没有办法将音频添加到 Storyboard中?

最佳答案

如果您愿意使用音频文件,可以使用 MediaTimeLine类(class)。然后您可以使用 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>

请注意,一旦 Storyboard 播放该文件,它将对其保持锁定状态。

关于c# - SpeechSynthesizer 到 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17914655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com