我有一个C#Windows应用商店应用,每当我尝试使用语音合成时都会收到System.UnauthorizedAccessException:
SpeechSynthesisStream stream = await this._tts.SynthesizeTextToStreamAsync("Hello ragdoll man!");
// Send the stream to the media object.
this._mediaElement.SetSource(stream, stream.ContentType);
this._mediaElement.Play();
当我调用SynthesizeTextToStreamAsync()时,第一行发生异常。这不是像Windows Phone 8上的某些人那样的软件包清单功能问题:
UnauthorizedAccessException when initializing SpeechSynthesizer
我这样说是因为首先,Windows应用商店应用清单没有ID_CAP_SPEECH_RECOGNITION功能,其次,作为测试我检查功能选项卡上的每个可用功能框我仍然得到例外。
导致此错误的原因是什么?如何解决?
答案 0 :(得分:0)
在新的空Windows 8.1应用程序项目中,这对我来说很好用:
private async void UIElement_OnTapped(object sender, TappedRoutedEventArgs e)
{
// The media object for controlling and playing audio.
MediaElement mediaElement = this.media;
// The object for controlling the speech synthesis engine (voice).
var synth = new SpeechSynthesizer();
// Generate the audio stream from plain text.
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync("Hello World");
// Send the stream to the media object.
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}