问题:语音合成后显示WPF窗口。 [英] Problem: WPF window displays after the speech is synthesized.
本文介绍了问题:语音合成后显示WPF窗口。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的MainWindow.xaml.cs:
this is my MainWindow.xaml.cs:
using statements...
....;
namespace xyz
{
class abc :Window
{
public SpeechSynthesizer qwe;
public abc()
{
InitializeComponent();
qwe = new SpeechSynthesizer();
qwe.Speak("Hello");
}
}
}
问题是语音是在窗口被显示之前合成的。
i希望窗口加载其所有内容,然后说出文字。
感谢您的帮助
问候
Ratul: - )
我尝试了什么:
我无法从谷歌获得帮助...现在我在这里。
The problem is that speech is synthesized before the window is diaplayed.
i want the window to load all its contents and then speak the text.
thanks for your help
regards
Ratul :-)
What I have tried:
I wasent able to get help from google ... and so now im here.
推荐答案
在窗口的<之前不要调用Speak
方法code>已加载事件触发:
Don't call theSpeak
method until the window'sLoaded
event fires:
public abc()
{
InitializeComponent();
qwe = new SpeechSynthesizer();
Loaded += Window_Loaded;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
qwe.Speak("Hello");
}
如果还是太快,请使用 Dispatcher
:
If that's still too soon, use the Dispatcher
:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke((Action)() => qwe.Speak("Hello")), DispatcherPriority.ContextIdle, null);
}
或者,使用 SpeechSynthesizer.SpeakAsync方法 [ ^ ]:
Alternatively, use the SpeechSynthesizer.SpeakAsync method[^]:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
qwe.SpeekAsync("Hello");
}
这篇关于问题:语音合成后显示WPF窗口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文