用途:Azure.AI.VoiceLive 是面向 .NET 的实时语音 AI SDK,用于构建与 Azure AI 进行双向 WebSocket 通信的语音助手。
安装:dotnet add package Azure.AI.VoiceLive;dotnet add package Azure.Identity;dotnet add package NAudio。当前版本为稳定版 v1.0.0 与预览版 v1.1.0-beta.1。
认证:推荐使用 Microsoft Entra ID 的 DefaultAzureCredential,需分配 Cognitive Services User 角色;也可使用 AzureKeyCredential 传入 API 密钥。
主要能力:通过 VoiceLiveClient 创建 VoiceLiveSession,使用 ConfigureSessionAsync 配置模型、指令、语音、轮次检测与音频格式;通过 GetUpdatesAsync 处理音频增量、文本增量、函数调用与错误等事件;使用 AddItemAsync 发送用户消息或函数调用结果,SendAudioAsync 发送音频,StartResponseAsync 触发响应。支持 Azure 标准、HD 与自定义语音,以及 gpt-4o-realtime-preview、gpt-4o-mini-realtime-preview、phi4-mm-realtime 等模型。
用法要点:同时启用 Text 与 Audio 模态;使用 AzureSemanticVadTurnDetection 实现自然对话,静音时长通常设为 500ms;音频输入输出为 Pcm16,建议 24kHz、单声道;用 using 确保会话释放;避免硬编码密钥。
限制:资料未提供价格、配额、区域可用性及性能数据;部分错误(如 Cancellation failed: no active response)为良性可忽略。