AccessViolationException in Windows.Media.SpeechSynthesis.Sp

本文关键字:SpeechSynthesis Sp Media Windows in AccessViolationException | 更新日期: 2023-09-27 17:56:16

我的应用在调用Windows.Media.SpeechSynthesis.SpeechSynthesizer类的默认构造函数时出现AccessViolationException。这只发生在一台特定的机器上(至少到目前为止),这是运行Windows 8.1的Surface Pro 3。安装了该应用程序的所有其他计算机都不会遇到此问题。

我的代码是这样的:

class Speech
{
    private Windows.Media.SpeechSynthesis.SpeechSynthesizer _Synthesizer;
    public Speech()
    {
        SetVoice();
    }
    private void SetVoice()
    {
        try
        {
            // Exception is raised here
            _Synthesizer = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
        }
        catch (Exception e)
        {
        }
    }
}

事件日志中显示的堆栈跟踪如下所示:

Description: The process was terminated due to an unhandled exception
Exception Info: System.AccessViolationException
Stack:
    at Windows.Media.SpeechSynthesis.SpeechSynthesizer..ctor()
    at ... Speech.SetVoice()
    at ... Speech..ctor()

我使用 ProcDump 捕获了一个转储文件,并且可以在堆栈跟踪中看到它(它不显示"我的代码",只显示它后面的代码):

sapi.dll!CSpObjectTokenEnumBuilder::CheckTokenSignature(struct ISpDataKey *) Unknown
sapi.dll!CSpObjectTokenEnumBuilder::AddTokensFromDataKey(struct ISpDataKey *,unsigned short const *,unsigned short const *) Unknown
sapi.dll!CSpObjectTokenCategory::InternalEnumTokens(unsigned short const *,unsigned short const *,struct IEnumSpObjectTokens * *,int) Unknown
sapi.dll!CSpObjectTokenCategory::EnumTokens(unsigned short const *,unsigned short const *,struct IEnumSpObjectTokens * *) Unknown
Windows.Media.SpeechSynthesis.dll!SpEnumTokens(unsigned short const *,unsigned short const *,unsigned short const *,struct IEnumSpObjectTokens * *) Unknown
Windows.Media.SpeechSynthesis.dll!Windows::Media::SpeechSynthesis::InstalledVoicesStatic::get_AllVoices(struct Windows::Foundation::Collections::IVectorView<class Windows::Media::SpeechSynthesis::VoiceInformation *> * *) Unknown
Windows.Media.SpeechSynthesis.dll!Windows::Media::SpeechSynthesis::InstalledVoicesStatic::get_DefaultVoiceWithRank(struct Windows::Media::SpeechSynthesis::IVoiceInformation * *,unsigned int *) Unknown
Windows.Media.SpeechSynthesis.dll!Windows::Media::SpeechSynthesis::CSpeechSynthesizer::GetDefaultVoice(struct Windows::Media::SpeechSynthesis::IVoiceInformation * *,unsigned int *) Unknown
Windows.Media.SpeechSynthesis.dll!Windows::Media::SpeechSynthesis::CSpeechSynthesizer::CreateSynthesizerObject(void) Unknown
Windows.Media.SpeechSynthesis.dll!Windows::Media::SpeechSynthesis::CSpeechSynthesizer::RuntimeClassInitialize(void) Unknown
Windows.Media.SpeechSynthesis.dll!Microsoft::WRL::Details::MakeAndInitialize<class Windows::Media::SpeechSynthesis::CSpeechSynthesizer,class Windows::Media::SpeechSynthesis::CSpeechSynthesizer>(class Windows::Media::SpeechSynthesis::CSpeechSynthesizer * *) Unknown
Windows.Media.SpeechSynthesis.dll!Windows::Media::SpeechSynthesis::InstalledVoicesStatic::ActivateInstance(struct IInspectable * *) Unknown

奇怪的是,错误似乎正在逃避try/catch块。这仅在一个客户的计算机上

知道发生了什么吗?

AccessViolationException in Windows.Media.SpeechSynthesis.Sp

我相信您的客户在注册表项HKEY_LOCAL_MACHINE'SOFTWARE'MICROSOFT'Speech'Voices'Tokens中有错误数据,这是SAPI存储有关系统上安装了哪些语音的信息的地方。

显然,存在一些键(假设代码正在尝试从注册表项添加令牌),但值已损坏,导致本机代码中的 AV。

要检查的其他区域(如果适用于您的系统)包括:

  • HKEY_CURRENT_USER'SOFTWARE'MICROSOFT'Speech'Voices'Tokens
  • HKEY_LOCAL_MACHINE'WOW6432Node'SOFTWARE'MICROSOFT'Speech'Voices'Tokens
  • HKEY_CURRENT_USER'WOW6432Node'SOFTWARE'MICROSOFT'Speech'Voices'Tokens