UnauthorizedAccessException when initializing SpeechSynthesizer

為{幸葍}努か 提交于 2019-12-01 05:53:23

问题


I'm using Microsofts SpeechSynthesizer to create audio output for my Windows Phone app. I use this code

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.");
}

I get this exception:

{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)}

I found out that the error occurs at

new SpeechSynthesizer();

回答1:


Make sure you have added the capability ID_CAP_SPEECH_RECOGNITION to the application manifest (WMAppManifest.xml).




回答2:


In Windows Universal Apps (UWP apps), Using the SpeechSynthetizer requires the Microphone capability. (I don't know why, but once enabled I didn't get the exception anymore)



来源:https://stackoverflow.com/questions/19344253/unauthorizedaccessexception-when-initializing-speechsynthesizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!