初始化SpeechSynthesizer时出现UnauthorizedAccessException

时间:2013-10-13 10:41:28

标签: c# windows-phone-8 speech-to-text unauthorizedaccessexcepti

我正在使用Microsofts SpeechSynthesizer为我的Windows Phone应用程序创建音频输出。我用这个代码

private async void TextToSpeech_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    SpeechSynthesizer synth = new SpeechSynthesizer();

    await synth.SpeakTextAsync("You have a meeting with Peter in 15 minutes.");
}

我得到了这个例外:

{System.UnauthorizedAccessException: Access is denied.

at Windows.Phone.Speech.Synthesis.SpeechSynthesizer..ctor()
at NerdQuiz.Question.<TextToSpeech_Tap>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)}

我发现错误发生在

new SpeechSynthesizer();

2 个答案:

答案 0 :(得分:4)

确保已将功能ID_CAP_SPEECH_RECOGNITION添加到应用程序清单(WMAppManifest.xml)。

答案 1 :(得分:0)

在Windows通用应用程序(UWP应用程序)中,使用 SpeechSynthetizer需要麦克风功能。 (我不知道为什么,但一旦启用我就不再得到例外了)