Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(voice): support Gateway Qwen speech models
JiangJiahao84a29c4327d7
diff --git a/apps/desktop/src/main/voice-conversation/__tests__/models.test.ts b/apps/desktop/src/main/voice-conversation/__tests__/models.test.tsindex 19054dc2dd..2d6d4fc536 100644--- a/apps/desktop/src/main/voice-conversation/__tests__/models.test.ts+++ b/apps/desktop/src/main/voice-conversation/__tests__/models.test.ts@@ -93,6 +93,27 @@ it('rejects unsupported speed on an official binding before opening a call', ());});+// Unit regression: the real Gateway Qwen route rejects OpenAI's wider speed+// range. Exercise admission and request serialization at the verified boundaries.+it('uses Qwen Audio 3.1 Plus speed limits on the OpenAI-compatible Gateway', () => {+ const modelId = 'qwen/qwen-audio-3.1-tts-plus';+ const d = deps([{ id: 'xd', audioModels: [model(modelId)] }] as Catalog['providers']);+ const choice = { providerId: 'xd', modelId, voice: 'longanlingxin_v3.1' };+ for (const speed of [0.5, 2]) {+ const selected = { ...choice, speed };+ const connection = resolveSpeechConnection(d, selected);+ expect(connection.protocol).toBe('openai');+ expect(JSON.parse(speechRequest(connection, { ...selected, text: 'hello' }).body)).toMatchObject({+ model: modelId,+ speed,+ response_format: 'pcm',+ });+ }+ for (const speed of [0.25, 4]) {+ expect(() => resolveSpeechConnection(d, { ...choice, speed })).toThrow('invalid_speech_speed');+ }+});+it('keeps Gateway entitlement and supported-protocol gates', () => {const d = deps([{@@ -115,8 +136,13 @@ it('keeps Gateway entitlement and supported-protocol gates', () => {});// Unit: a new Gateway selection needs a usable reference default, while a saved-// manual ID remains the request value. Existing OpenAI-only fixtures missed this.-it.each(['elevenlabs/eleven_multilingual_v2', 'minimax/speech-2.8-hd'])(+// manual ID remains the request value. Qwen 3.1 Plus was advertised as audio_speech+// but its chat-family rule excluded it; the earlier vendor cases missed this route.+it.each([+ 'elevenlabs/eleven_multilingual_v2',+ 'minimax/speech-2.8-hd',+ 'qwen/qwen-audio-3.1-tts-plus',+])('uses the reference default without restricting manual voices for %s',async (modelId) => {const d = deps([{ id: 'xd', audioModels: [model(modelId)] }] as Catalog['providers']);@@ -136,6 +162,27 @@ it.each(['elevenlabs/eleven_multilingual_v2', 'minimax/speech-2.8-hd'])(},);+// Unit regression: both Registry layers must receive the discovered media mode.+// Without it, a previously unknown Qwen TTS ID inherits the bundled chat prefix.+// Exact declarations (including null) remain authoritative over the mode hint.+it.each(['current', 'bundled'] as const)(+ 'keeps Gateway speech mode when resolving %s Registry protocols',+ (layer) => {+ const modelId = 'qwen/qwen-audio-3.1-tts-plus';+ const media = model(modelId);+ const d = deps([{ id: 'xd', audioModels: [media] }] as Catalog['providers']);+ if (layer === 'bundled') d.catalog.modelRegistry = undefined;+ expect(speechModels(d)).toMatchObject([{ id: modelId, protocol: 'openai' }]);+ const selected = { providerId: 'xd', modelId, voice: 'longanlingxin_v3.1' };+ expect(resolveSpeechConnection(d, selected).protocol).toBe('openai');+ for (const nativeApi of [null, 'openai-completions'] as const) {+ media.nativeApi = nativeApi;+ expect(speechModels(d)).toEqual([]);+ expect(() => resolveSpeechConnection(d, selected)).toThrow('model_unavailable');+ }+ },+);+// Unit regression: resolveSpeechConnection -> speechRequest must send Gateway TTS// to /v1/audio/speech. Live root endpoints returned 404; previous fixtures already// included /v1. Cover the root, existing API base and deployment prefix without I/O.diff --git a/apps/desktop/src/main/voice-conversation/__tests__/speech.test.ts b/apps/desktop/src/main/voice-conversation/__tests__/speech.test.tsindex c72252baf1..ed56671b32 100644--- a/apps/desktop/src/main/voice-conversation/__tests__/speech.test.ts+++ b/apps/desktop/src/main/voice-conversation/__tests__/speech.test.ts@@ -175,6 +175,9 @@ it.each([it.each([['openai', 'tts', 4.1],+ // Live Gateway rejects these speeds; transport must guard direct callers too.+ ['openai', 'qwen/qwen-audio-3.1-tts-plus', 0.25],+ ['openai', 'qwen/qwen-audio-3.1-tts-plus', 4],['elevenlabs', 'eleven_flash_v2_5', 1.25],['elevenlabs', 'eleven_v3', 1],['minimax', 'speech-02-hd', 0.4],diff --git a/apps/desktop/src/main/voice-conversation/__tests__/voices.test.ts b/apps/desktop/src/main/voice-conversation/__tests__/voices.test.tsindex 14ffd8b046..36750a5383 100644--- a/apps/desktop/src/main/voice-conversation/__tests__/voices.test.ts+++ b/apps/desktop/src/main/voice-conversation/__tests__/voices.test.ts@@ -49,7 +49,13 @@ describe('provider voice catalogs', () => {voices: [],});// A known vendor prefix alone must not invent compatibility for new versions.- for (const modelId of ['elevenlabs/eleven_v4', 'minimax/speech-3.0-hd', 'speech-2.8-hd']) {+ for (const modelId of [+ 'elevenlabs/eleven_v4',+ 'minimax/speech-3.0-hd',+ 'speech-2.8-hd',+ 'qwen/qwen-audio-3.1-tts-flash',+ 'qwen/qwen-audio-3.2-tts-plus',+ ]) {expect(await loadSpeechVoices(connection('openai'), modelId, fetcher, () => {}, 'xd'),).toEqual({ source: 'manual', voices: [] });@@ -57,6 +63,22 @@ describe('provider voice catalogs', () => {expect(fetcher).not.toHaveBeenCalled();});+ // Unit: the newly admitted Gateway Qwen model needs its own verified references.+ // Existing OpenAI/native Alibaba cases did not cover this namespaced Gateway route.+ it('offers Qwen 3.1 Plus references only on its Gateway route without requesting a voice API', async () => {+ const fetcher = vi.fn();+ const modelId = 'qwen/qwen-audio-3.1-tts-plus';+ const result = await loadSpeechVoices(connection('openai'), modelId, fetcher, () => {}, 'xd');+ expect(result.source).toBe('reference');+ expect(result.voices).toHaveLength(4);+ expect(result.voices[0]).toMatchObject({ id: 'longanlingxin_v3.1' });+ expect(await loadSpeechVoices(connection('openai'), modelId, fetcher, () => {}, 'custom')).toEqual({+ source: 'manual',+ voices: [],+ });+ expect(fetcher).not.toHaveBeenCalled();+ });+it('paginates ElevenLabs within the selected origin/prefix and preserves account voices regardless of high-quality labels', async () => {const fetcher = vi.fn<typeof fetch>()diff --git a/apps/desktop/src/main/voice-conversation/models.ts b/apps/desktop/src/main/voice-conversation/models.tsindex 65b1254251..362e2e509c 100644--- a/apps/desktop/src/main/voice-conversation/models.ts+++ b/apps/desktop/src/main/voice-conversation/models.ts@@ -59,13 +59,15 @@ function apiBase(raw: string): URL | null {* See docs/product-rules/companion-voice-mode.md, "后续扩展计划".*/function nativeProtocol(catalog: Catalog, providerId: string, model: ProviderMediaModel) {+ // Family rules describe chat protocols. Pass the discovered mode so a new+ // media model cannot inherit one; explicit route declarations still win.const declared =model.nativeApi !== undefined? model.nativeApi- : resolveModelNativeApi(catalog.modelRegistry, providerId, model.id);+ : resolveModelNativeApi(catalog.modelRegistry, providerId, model.id, model.mode);return declared !== undefined? declared- : resolveModelNativeApi(BUNDLED_CATALOG.modelRegistry, providerId, model.id);+ : resolveModelNativeApi(BUNDLED_CATALOG.modelRegistry, providerId, model.id, model.mode);}/** The provider endpoint owns the adapter. Alibaba exposes different APIs on itsdiff --git a/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx b/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsxindex 1a9b755428..8dad6b08ca 100644--- a/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx+++ b/apps/desktop/src/renderer/features/bots/voice/__tests__/CompanionVoiceSettings.test.tsx@@ -435,6 +435,51 @@ it('reconciles the saved speed on model changes and keeps it when changing the vexpect(saved).not.toHaveProperty('speed');});+// Unit regression at the actual settings entry: Gateway Qwen accepts 0.5–2,+// although its transport is OpenAI-compatible. The old protocol-only range let+// users save 4x and receive a Gateway error; retain the existing adjustment flow.+it('clamps speed when switching to Gateway Qwen and previews the adjusted choice', async () => {+ const openai = {+ id: 'tts-1',+ name: 'OpenAI speech',+ providerId: 'xd',+ protocol: 'openai' as const,+ protocolLocked: true,+ defaultVoice: 'alloy',+ };+ const qwen = {+ ...openai,+ id: 'qwen/qwen-audio-3.1-tts-plus',+ name: 'Qwen speech',+ defaultVoice: 'longanlingxin_v3.1',+ };+ models = [openai, qwen];+ vi.mocked(window.electronAPI.voiceConversation.preference).mockResolvedValueOnce({+ selection: { providerId: 'xd', modelId: openai.id, voice: 'alloy', speed: 4 },+ customized: true,+ });+ renderSettings();+ const model = await screen.findByRole('combobox', { name: 'bots.voiceMode.model' });+ await waitFor(() => expect((model as HTMLSelectElement).disabled).toBe(false));+ fireEvent.change(model, { target: { value: voiceModelKey(qwen) } });+ await waitFor(() =>+ expect(window.electronAPI.voiceConversation.setPreference).toHaveBeenLastCalledWith(+ 'bot',+ expect.objectContaining({ modelId: qwen.id, voice: qwen.defaultVoice, speed: 2 }),+ ),+ );+ const slider = await screen.findByRole('slider', { name: 'bots.voiceMode.speed' });+ expect(slider.getAttribute('aria-valuemin')).toBe('0.5');+ expect(slider.getAttribute('aria-valuemax')).toBe('2');+ expect(screen.getByText('bots.voiceMode.speedAdjusted')).toBeTruthy();+ fireEvent.click(await screen.findByRole('button', { name: 'bots.voiceMode.preview' }));+ await waitFor(() =>+ expect(window.electronAPI.voiceConversation.preview).toHaveBeenCalledWith(+ expect.objectContaining({ modelId: qwen.id, voice: qwen.defaultVoice, speed: 2 }),+ ),+ );+});+it('defaults to sentence playback, persists a playback-only change, and restores the default', async () => {models = [{ id: 'tts', name: 'Speech', defaultVoice: 'alloy' }];const view = renderSettings();diff --git a/apps/desktop/src/shared/speechProtocols.ts b/apps/desktop/src/shared/speechProtocols.tsindex 4085ad0592..9ed4c75d72 100644--- a/apps/desktop/src/shared/speechProtocols.ts+++ b/apps/desktop/src/shared/speechProtocols.ts@@ -8,8 +8,8 @@ export const SPEECH_PROTOCOLS = [] as const;export type SpeechProtocol = (typeof SPEECH_PROTOCOLS)[number];-/** Native synthesis limits, shared by settings and Main. Compatible proxies must- * implement their selected protocol; this is not a claim about gateway forwarding.+/** Synthesis limits, shared by settings and Main. Compatible proxies must+ * implement their selected protocol, subject to verified model-specific limits.* Eleven v3 currently excludes speed: https://elevenlabs.io/docs/eleven-creative/playground/text-to-speech#speed*/export function speechSpeedRange(modelId: string, protocol?: SpeechProtocol) {@@ -20,6 +20,10 @@ export function speechSpeedRange(modelId: string, protocol?: SpeechProtocol) {case 'minimax':return { min: 0.5, max: 2 };case 'openai':+ // Gateway Qwen retains the provider's limits: 0.5/2 verified on 2026-10-23;+ // 0.25/4 fail. Do not apply this exception to unknown Qwen versions.+ // https://www.alibabacloud.com/help/en/model-studio/qwen-audio-tts-http-api+ if (modelId === 'qwen/qwen-audio-3.1-tts-plus') return { min: 0.5, max: 2 };return { min: 0.25, max: 4 };default:return null;diff --git a/apps/desktop/src/shared/speechVoices.ts b/apps/desktop/src/shared/speechVoices.tsindex b12afcf6e8..757372da3c 100644--- a/apps/desktop/src/shared/speechVoices.ts+++ b/apps/desktop/src/shared/speechVoices.ts@@ -22,9 +22,20 @@ const GATEWAY_MINIMAX: readonly SpeechVoice[] = [{ id: 'English_Trustworth_Man', name: 'Trustworthy Man' },];+// Qwen-Audio 3.1 Plus system voices, verified through Gateway /v1/audio/speech+// with 24 kHz PCM on 2026-10-23. These are not Qwen3-TTS or 3.0 voice aliases.+// https://help.aliyun.com/zh/model-studio/qwen-audio-tts-voice-list+const GATEWAY_QWEN_AUDIO_31_PLUS: readonly SpeechVoice[] = [+ { id: 'longanlingxin_v3.1', name: '龙安灵心_v3.1' },+ { id: 'xunanchuan_v3.1', name: '许南川' },+ { id: 'longanhuan_v3.1', name: '龙安欢_v3.1' },+ { id: 'longanfengyue_v3.1', name: '龙安风悦_v3.1' },+];+export function gatewayReferenceSpeechVoices(modelId: string): readonly SpeechVoice[] {if (['elevenlabs/eleven_multilingual_v2', 'elevenlabs/eleven_v3'].includes(modelId))return GATEWAY_ELEVENLABS;+ if (modelId === 'qwen/qwen-audio-3.1-tts-plus') return GATEWAY_QWEN_AUDIO_31_PLUS;// Exact documented versions, including their Gateway namespace. Unknown/new// models stay manual until their voice contract has been checked.if (/^minimax\/speech-(?:2\.[68]|0[12])-(?:hd|turbo)$/.test(modelId)) return GATEWAY_MINIMAX;diff --git a/docs/product-rules/companion-voice-mode.md b/docs/product-rules/companion-voice-mode.mdindex 21d14dae12..f7575291a3 100644--- a/docs/product-rules/companion-voice-mode.md+++ b/docs/product-rules/companion-voice-mode.md@@ -36,7 +36,7 @@- 当前仅支持 Desktop、本机伙伴一对一。群聊、Mobile、远程控制的麦克风、原生 Realtime speech-to-speech 不在此实现内。- 新 IPC 只接受可信应用顶层 Renderer,按窗口、账号代次、callId 和 canonical 任务绑定。callId 在发起请求前生成,使结束按钮也能取消连接过程;它不是授权凭证。接口不加入 device-link 或插件白名单。输入静音控制仍绑定当前窗口与 callId,输入每次重开分配新代次;旧代次 PCM 和识别回调不能进入新输入,结束中的迟到麦克风或 ASR 分配仍须释放。模型权限在开始和每次 TTS 请求、读取时复核。- ASR 适配器额外提供按上游 utterance/item ID 标识的分段事件,现有累积 `AsrEvent` 合同保持不变。连接在 150 秒轮换,沿用 voice-server 的 dictation 协议;切换期间最多缓存 5 秒输入,不能无声丢弃或重复发送前文。-- Gateway 执行合同为 OpenAI 兼容 `POST <语音 API base>/audio/speech`。服务端下发的是与密钥配对的推理部署地址:仅在本地 Cindy AI TTS 连接中补齐末尾 `/v1`,已有 `/v1` 不重复添加,保留部署路径前缀;不回写聊天、图像等共用的 endpoint,也不改 BYOK 配置的 API base。body 包含 `model`、`voice`、`input`、`response_format: pcm`。PCM 固定为该协议规定的 24kHz、单声道、16bit little-endian。显式声明其他 native API 或 `null` 未验证 API 的 Cindy AI 模型不进入选择器;未声明协议的 Gateway 新模型沿用此端点合同。下发 `mode` 只代表能力分类,不证明具体音色、音频格式或端点可用。+- Gateway 执行合同为 OpenAI 兼容 `POST <语音 API base>/audio/speech`。服务端下发的是与密钥配对的推理部署地址:仅在本地 Cindy AI TTS 连接中补齐末尾 `/v1`,已有 `/v1` 不重复添加,保留部署路径前缀;不回写聊天、图像等共用的 endpoint,也不改 BYOK 配置的 API base。body 包含 `model`、`voice`、`input`、`response_format: pcm`。PCM 固定为该协议规定的 24kHz、单声道、16bit little-endian。显式声明其他 native API 或 `null` 未验证 API 的 Cindy AI 模型不进入选择器;未声明协议的 Gateway 新模型沿用此端点合同。解析当前及内置 Registry 时均传入已发现的媒体 `mode`,避免 Qwen 等品牌的聊天前缀规则误排除语音型号;精确协议声明仍优先,不因 `mode` 绕过。下发 `mode` 只代表能力分类,不证明具体音色、音频格式或端点可用。回归见 `main/voice-conversation/__tests__/models.test.ts`。- 凭证只在 Main:Gateway 使用当前账号配对的 baseUrl / 密钥,BYOK 复用对应连接、对应 runtime 的 safeStorage 密钥和固定请求头。排除原生订阅 OAuth、远程或共享供应商;per-model 地址不得跨越凭证所属连接的 origin。开始时固定连接,每次合成与音频读取复核资格及路由/密钥是否变化;变化则停止该语音请求。禁止自动切换到其他供应商、系统朗读或另一条凭证。响应按 Renderer 播放速度读取,播放只预排约 300ms;中断丢弃旧请求和迟到音频。原始音频只在内存,不新增录音文件或对话音频归档。- 初始实现的声音活动判断是带迟滞的音量检测,配合浏览器回声消除与降噪。它不是语义 VAD,不能保证所有扬声器、蓝牙或噪声环境都能准确分辨插话。@@ -94,7 +94,8 @@- 参数依据:[OpenAI Speech](https://developers.openai.com/api/reference/resources/audio/subresources/speech/methods/create)、[ElevenLabs speed](https://elevenlabs.io/docs/eleven-creative/playground/text-to-speech#speed)、[MiniMax HTTP TTS](https://platform.minimax.io/docs/api-reference/speech-t2a-http)。- **OpenAI 兼容**:仅对已知精确型号及已知格式的日期版本提供代码内的官方参考列表;`gpt-4o-mini-tts` 与 `tts-1` / `tts-1-hd` 的集合分开。未知型号不强行填 `alloy`,也不探测不存在的通用 `/voices`。兼容服务可能只实现部分音色,列表明确标注为参考,是否可用仍需试听。[资料来源](https://developers.openai.com/api/docs/guides/text-to-speech#voice-options)。-- **Cindy AI Gateway**:在服务端尚未提供音色目录接口时,仅为明确匹配的 `elevenlabs/eleven_multilingual_v2`、`elevenlabs/eleven_v3` 和 `minimax/speech-{2.8,2.6,02,01}-{hd,turbo}` 提供各 4 个公共参考音色,维护在 `shared/speechVoices.ts`。ElevenLabs 采用官方旧默认音色的替代项 Talia、Darian、Eldrin、Elowen;MiniMax 采用官方系统音色候选,不宣称已通过 Gateway 验证。进入页面和刷新均读取本地参考表,不探测 `/voices`,不增加可用模型或授权。仅新选择使用参考默认值,已有音色 ID 和手动输入继续保留,试听仍使用当前 Gateway 的真实合成接口。未来接入 Gateway 音色目录时,应以该连接的成功响应为准(包括空列表),不能用参考列表掩盖服务端结果。[ElevenLabs 替代说明](https://elevenlabs.io/docs/help-center/product/voices/my-voices/what-are-default-voices)、[MiniMax 系统音色](https://platform.minimax.io/docs/faq/system-voice-id)。+- **Cindy AI Gateway**:在服务端尚未提供音色目录接口时,为明确匹配的 `elevenlabs/eleven_multilingual_v2`、`elevenlabs/eleven_v3` 和 `minimax/speech-{2.8,2.6,02,01}-{hd,turbo}` 提供各 4 个公共参考音色,维护在 `shared/speechVoices.ts`。ElevenLabs 采用官方旧默认音色的替代项 Talia、Darian、Eldrin、Elowen;MiniMax 采用官方系统音色候选,不宣称已通过 Gateway 验证。进入页面和刷新均读取本地参考表,不探测 `/voices`,不增加可用模型或授权。仅新选择使用参考默认值,已有音色 ID 和手动输入继续保留,试听仍使用当前 Gateway 的真实合成接口。未来接入 Gateway 音色目录时,应以该连接的成功响应为准(包括空列表),不能用参考列表掩盖服务端结果。[ElevenLabs 替代说明](https://elevenlabs.io/docs/help-center/product/voices/my-voices/what-are-default-voices)、[MiniMax 系统音色](https://platform.minimax.io/docs/faq/system-voice-id)。+- **Gateway Qwen**:`qwen/qwen-audio-3.1-tts-plus` 同样走 OpenAI 兼容接口,提供龙安灵心_v3.1、许南川、龙安欢_v3.1、龙安风悦_v3.1 四个参考音色,新选择默认龙安灵心_v3.1。名称和完整 ID 来自 [Qwen-Audio 官方目录](https://help.aliyun.com/zh/model-studio/qwen-audio-tts-voice-list),2026-10-23 已通过 Gateway 实测四个音色的 PCM 合成;该结论不扩展到其他 Qwen 型号或 BYOK 原生接口。该型号的语速范围为 0.5–2,UI 与 Main 共用限制;Gateway 实测 0.5 / 1.2 / 2 成功,0.25 / 4 失败,不能直接套用 OpenAI 的宽范围。范围依据见 [Qwen-Audio HTTP 参数](https://www.alibabacloud.com/help/en/model-studio/qwen-audio-tts-http-api),更换模型沿用已有的语速调整提示,不自动重写旧偏好。刷新、手动输入、已有偏好和试听仍沿用上述 Gateway 规则。实现见 `shared/speechVoices.ts`,回归见 `main/voice-conversation/__tests__/voices.test.ts`。- **BYOK ElevenLabs**:从对应连接的 `/v2/voices` 分页查询账号音色;由既有 `/v1` base 替换末段,保留代理 origin 和路径前缀。无版本后缀的自定义代理尝试其 `<base>/voices` 旧接口。`high_quality_base_model_ids` 不作为模型可用性的硬过滤条件。失败时允许重试或手动输入。[资料来源](https://elevenlabs.io/docs/api-reference/voices/search)。- **BYOK MiniMax**:调用 `<base>/get_voice`,`voice_type: all`,合并 `system_voice`、`voice_cloning`、`voice_generation`;名称与 ID 分开,缺名称时显示 ID。音色 ID 接受真实型号所需的空格、括号等字符,保留长度、控制字符和路径分隔符校验。[资料来源](https://platform.minimax.io/docs/api-reference/voice-management-get)。- 音色选项与当前选中项默认只显示名称及供应商提供的风格说明;同名音色附加短 ID 尾缀,尾缀冲突时延长至可区分,缺名称时回退为完整 ID。不提供已选音色的 ID 展示栏或复制入口;手动输入仅作为目录外音色的兜底。显示缩写不改变选择值、伙伴偏好或合成请求中的完整 ID,也不触发已有偏好重写。