You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HoloLens 2 Unity发布版语音助手连接失败:代理配置消息格式错误

HoloLens 2 Azure Bot Framework语音识别在Release构建失效(错误1002:Malformed agent config message)

问题描述

基于Unity、MRTK和Azure Bot Framework开发HoloLens 2语音助手,遵循《Made with MRTK: Bot Integration》视频教程实现。Unity编辑器和ARM64 UWP Debug构建下语音识别功能正常,但ARM64/ARM32 UWP Release构建(使用IL2CPP脚本后端)中语音识别完全失效,触发连接错误。

报错信息

Cancelled with reason: Error.
Error Reason: ConnectionFailure.
Error Message: Connection was closed by the remote host. Error code: 1002. Error details: Malformed agent config message. SessionId: REDACTED.

核心代码片段

private void CreateDialogServiceConnector()
{
    Debug.Log($"creatDialogSerciveConnector enter");
    if (dialogServiceConnector == null )
    {
        if (subscriptionKey == string.Empty || region == string.Empty )
        {
            Debug.Log($"One or more input fields weren't provided. Check the fields in the Canvas object or in the script");
            throw new InvalidOperationException("DialogServiceConfig Creation Failed");
        }
        dialogServiceConfig = BotFrameworkConfig.FromSubscription(subscriptionKey, region,botID);
        dialogServiceConfig.Language = connectionLanguage;
        if (dialogServiceConfig == null)
        {
            Debug.Log($"One or more input fields weren't provided. Check the fields in the Canvas object or in the script");
            throw new InvalidOperationException("DialogServiceConfig Creation Failed");
        }
        AudioConfig audioConfig = AudioConfig.FromDefaultMicrophoneInput();
        dialogServiceConnector = new DialogServiceConnector(dialogServiceConfig, audioConfig);

        dialogServiceConnector.ActivityReceived += DialogServiceConnector_ActivityReceived;
        dialogServiceConnector.Canceled += DialogServiceConnector_Canceled;
        dialogServiceConnector.Recognized += DialogServiceConnector_Recognized;
    }

    stateIndicatorString = "DialogServiceConnector created";
    Debug.Log($"CreateDialogServiceConnector exit");
}

注:botID变量为空字符串

已尝试操作

  • 预期能正常获取包含识别结果的ActivityReceivedEventArgs
  • 验证编辑器及ARM64 UWP Debug构建功能正常,仅Release构建出现问题
  • 测试ARM32架构的Release和Debug构建,结果一致(Debug正常,Release报错)
  • 重新按照视频教程步骤实现Bot Framework集成,问题依旧
  • 搜索相关问题未找到有效解决方案

补充:项目使用IL2CPP脚本后端

解决方案建议

1. 调整IL2CPP代码裁剪设置

Release构建下IL2CPP默认启用代码裁剪,可能误删Azure Bot Framework SDK依赖的序列化/反射代码:

  • 打开Unity项目设置:Edit > Project Settings > Player > Other Settings > Configuration
  • 将Managed Stripping Level设为Low或Disabled(测试用,后续可按需优化)
  • 添加link.xml链接器配置文件到项目根目录,保留Azure SDK必要代码:
    <linker>
        <assembly fullname="Microsoft.CognitiveServices.Speech" preserve="all"/>
        <assembly fullname="Microsoft.CognitiveServices.Speech.Dialog" preserve="all"/>
    </linker>
    

2. 修复空botID的序列化异常

报错提示Malformed agent config message,空字符串的botID在Release序列化时可能被优化为异常格式:

  • 若无需指定botID,改用无botID的重载:BotFrameworkConfig.FromSubscription(subscriptionKey, region)
  • 若必须传入botID,设置为非空占位符(如""改为"placeholder"),避免空字符串被IL2CPP优化

3. 验证Azure Speech SDK兼容性

确保使用的Azure Speech SDK版本支持HoloLens 2 UWP Release构建:

  • 重新下载并导入最新版的Azure Speech SDK for Unity UWP专用包
  • 确认SDK已正确适配ARM/ARM64架构

4. 启用Release构建调试日志

获取更详细的错误上下文:

  • 在Unity Player设置的Scripting Define Symbols中添加ENABLE_LOGGING
  • 修改代码中日志输出,确保dialogServiceConfig的内部参数在Release中能正常打印
  • 通过HoloLens设备门户查看Release构建的日志,确认配置信息是否正确传递

5. 检查权限配置

虽然Debug正常,但Release构建可能需要显式权限声明:

  • 在Package.appxmanifest中确认已添加Internet (Client)和Microphone权限
  • 确保HoloLens设备能正常访问Azure Speech服务的区域端点(无防火墙/代理限制)

内容的提问来源于stack exchange,提问作者RensV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 02:10:36