feat: 桌面端语音输入(右 Alt 录音 → 智谱 ASR 转写)#888
Conversation
- 前端右 Alt 切换录音,ScriptProcessor 采 PCM 并编码 WAV(智谱 ASR 仅支持 wav/mp3) - 本地 server 新增 /api/voice/transcribe,读取用户设置中的 endpoint/key/model 转发到语音识别 provider - 设置 → 供应商 拆分为「语言模型」与「语音模型」两个分区 - 转写文字插入输入框光标处(不自动发送),录音/识别/错误状态有指示器 - 5 语言 i18n 同步 Co-Authored-By: Claude <noreply@anthropic.com>
PR quality triageChanged areas: area:cli-core, area:desktop, area:release, area:server CLI core policy: Blocked by policy until a maintainer applies Missing-test policy: Blocked by policy until a maintainer applies Coverage baseline policy: No coverage-baseline policy block detected. CLI core files:
Coverage policy files:
Expected checks:
Test coverage signals:
Risk notes:
Hard merge gates still come from GitHub Actions, not AI review. Dosu handoff: Dosu can be used as the AI reviewer for risk explanation, missing-test prompts, and maintainer Q&A. If it does not comment automatically from the PR template, ask: @dosubot review this PR for changed-area risk, missing tests, docs impact, desktop startup risk, and CLI core impact. |
Summary
在聊天输入框按右 Alt 开始录音,再按一次结束,语音经识别后转成文字插入输入框(不自动发送,可编辑)。语音识别模型在设置 → 供应商」配置,默认用智谱
glm-asr-2512测试。方案
调用链:前端录音 → 本地 server(3456)→ server 用配置的 Key 调用语音识别 provider →
返回文字 → 插入输入框。
走 server 中转:前端 CSP 禁止直连外部域名(只允许 localhost),且与现有 provider/Tavily
key 一致——外部 Key 由 server 持有并发起调用。
关键点
ScriptProcessorNode采 PCM 并内联编码成 WAV(无第三方依赖)document级监听右 Alt,toggle录音/停止;录音/识别中/错误状态有指示器,错误透传真实原因
Agent)与「语音模型」**(语音转文字配置)两个分区
改动
Server:新增
server/api/voice.ts(POST /api/voice/transcribe)、路由注册、设置schema 增加
voiceInput桌面端:新增
api/voice.ts+hooks/useVoiceInput.ts,接入ChatInput(光标插入 +指示器),
Settings.tsx增加语音配置区,store/types/i18n(5 语言)同步验证
cd desktop && bun run lint(tsc)通过/api/voice/transcribe路由实测 400/405/404 符合预期备注
智谱 GLM-ASR 仅支持 wav/mp3(≤25MB),故前端必须录成 WAV。macOS 可能需在 src-tauri 的
Info.plist 补
NSMicrophoneUsageDescription(本次未涉及)。