【发布时间】:2014-09-08 16:44:51
【问题描述】:
我正在创建一个 windows phone 8.1 应用程序。当应用程序启动时,应用程序会提示用户拨打某个电话号码。它通过语音来做到这一点。应用程序告知指令后,将显示电话对话框。 这是代码:
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
StartSpeaking("Please call number !");
CallDialog();
}
private async void StartSpeaking(string text)
{
MediaElement mediaElement = this.media;
// The object for controlling the speech synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(text);
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
private async void CallDialog()
{
Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI("123", "123");
var messageDialog = new Windows.UI.Popups.MessageDialog("call ended", "Text spoken");
await messageDialog.ShowAsync();
}
问题是我必须使用 synth.SynthesizeTextToStreamAsync 方法,它是异步方法,所以调用对话框会在文本说之前出现。我怎样才能避免这种情况?
【问题讨论】:
标签: c# asynchronous speech-recognition windows-phone-8.1 speech-to-text