初始化 SpeechSynthesizer 时的 UnauthorizedAccessException
本文关键字:UnauthorizedAccessException 时的 SpeechSynthesizer 初始化 | 更新日期: 2023-09-27 18:35:05
我正在使用Microsoft的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();
确保已将功能ID_CAP_SPEECH_RECOGNITION
添加到应用程序清单 (WMAppManifest.xml)。
在 Windows 通用应用(UWP 应用)中,使用语音合成器需要麦克风功能。(我不知道为什么,但是一旦启用,我就不再收到异常了)