Skip to content

feat(asr): 接入通义千问/SiliconFlow/智谱 GLM 与国外常见 ASR 作为可选项 #212

Closed

Description

@appergb

背景

目前 coordinator.rs 只路由两条 ASR:

  • volcengine — 火山 SAUC bigmodel,自建 WebSocket(asr/volcengine.rs)
  • whisper — WhisperBatchASR(asr/whisper.rs),任意 OpenAI 兼容 POST /audio/transcriptions,凭据走 asr.api_key / asr.endpoint / asr.model

设置页 Settings.tsx:279 的 ASR_PRESETS 也只列了这两项。Issue #58 中曾尝试加入 SiliconFlow,因后端未路由被回退(注释见 Settings.tsx:277)。

目标

把以下 ASR 服务商作为新的可选项接入,复用 OpenAI 兼容批处理通道,让用户在「设置 → 服务商 → ASR」中通过下拉切换、自动预填 baseURL/model:

服务商 端点 推荐模型 兼容性
通义千问(阿里 DashScope) https://dashscope.aliyuncs.com/compatible-mode/v1 qwen3-asr-flash OpenAI 兼容(待复核)
硅基流动 SiliconFlow https://api.siliconflow.cn/v1 FunAudioLLM/SenseVoiceSmall OpenAI 兼容 ✅
智谱 GLM https://open.bigmodel.cn/api/paas/v4 glm-asr-2512 OpenAI 兼容 ✅
OpenAI Whisper https://api.openai.com/v1 whisper-1 / gpt-4o-transcribe 已支持(现有 whisper preset)
Groq https://api.groq.com/openai/v1 whisper-large-v3-turbo OpenAI 兼容 ✅

设计原则

  1. 后端零侵入或最小侵入:能用现有 WhisperBatchASR 通道的,就不新增 Rust 模块——「采用标准接口形式」即 OpenAI /audio/transcriptions。
  2. 凭据隔离:用现有 asr.api_key / asr.endpoint / asr.model 三个 CredentialAccount,切换 preset 时由前端把 asr.endpoint 和 asr.model 默认值填上(参考 LLM preset 切换逻辑)。
  3. 失败保护沿用既有契约:CLAUDE.md 明确 ASR fallback 是静默的——凭据缺失走 mock 占位,不抛硬错。新 preset 必须遵循。
  4. 不引入流式实现:通义/SiliconFlow/GLM 等的批处理已能满足 OpenLess 的 hold-to-talk 模型;如果未来要 Aliyun NLS Paraformer 的真流式 / Deepgram / AssemblyAI(非 OpenAI 兼容),单独开 issue。

V1 实施清单(本 issue 范围)

Frontend(openless-all/app/src/pages/Settings.tsx)

  • 扩展 ASR_PRESETS:新增 qwen / siliconflow / zhipu / groq 四项;保留 whisper(OpenAI 原生)。
  • 切换 preset 时自动写 asr.endpoint 与 asr.model 默认值(onAsrProviderChange 中加 preset 表)。
  • i18n:在 i18n/zh-CN.ts 与 i18n/en.ts 的 settings.providers.presets.* 节点补对应文案。

Backend(仅扩枚举,不新增 ASR 客户端)

  • coordinator.rs:906 的 if active_asr == \"whisper\" 分支扩成 "任意非 volcengine 都走 WhisperBatchASR";或显式列入 qwen / siliconflow / zhipu / groq。
  • read_whisper_credentials 的 model fallback 保留 whisper-1,但当 base_url 是非 OpenAI 时不强制——前端 preset 已经塞入正确 model。

验证(CLAUDE.md 要求逐项实测)

  • 切换至 SiliconFlow(API key 自备),录一段中文,capsule → polish → insertion 全链路通过
  • 切换至 Qwen3-ASR-Flash(DashScope key 自备),同上
  • 切换至 GLM-ASR(智谱 key 自备),同上
  • 凭据缺失时不抛硬错(fallback 静默契约)
  • 凭据从 Volcengine 切换到 Whisper preset 后再切回去,UI 状态正确

待复核风险

  • DashScope 是否真的对 Qwen3-ASR-Flash 暴露 OpenAI /audio/transcriptions:阿里 help 中心 JS 渲染,curl 抓不到正文;实施前需先 curl 一发 16 kHz mono WAV 验证,若不兼容则 Qwen 这一项落到 V2(单独客户端)。
  • 采样率:WhisperBatchASR 固定写 16 kHz mono PCM → WAV,理论上各家都接受,但 DashScope/SiliconFlow 个别模型可能需要 16 kHz 以上;先按 16 kHz 试,失败再加配置。

不在范围(V2 候选,单独提 issue)

  • Aliyun NLS Paraformer 真流式(WebSocket)—— 需要新 Rust 模块,工作量与 volcengine 客户端相当
  • Deepgram /v1/listen、AssemblyAI 上传+轮询 —— 非 OpenAI 兼容,需独立客户端
  • 与 Issue feat(ASR): 增加对本地 ASR AI 的支持 #211(本地 ASR)协调统一抽象层

Activity

  1. self-assigned this
    on May 3, 2026
  2. appergb commented on May 3, 2026

    @appergb
    CollaboratorAuthor

    开始认领并实施 V1。

    任务详细描述

    目标:把通义千问(DashScope 兼容模式)、SiliconFlow、智谱 GLM、Groq 作为 ASR 服务商加入「设置 → 服务商 → ASR」的下拉,复用现有 WhisperBatchASR(OpenAI /audio/transcriptions 通道),不引入新 Rust 客户端。

    改动清单

    Backend(openless-all/app/src-tauri/src/coordinator.rs)

    • start_session(line 908):把 if active_asr == "whisper" 扩成 matches!(active_asr.as_str(), "whisper" | "qwen" | "siliconflow" | "zhipu" | "groq"),全部走 WhisperBatchASR 路径。
    • ensure_asr_credentials(line 1543):同样扩条件;错误文案改通用一些(不再写死 "Whisper")。
    • QA 路径不动 —— qa_hotkey 强制 Volcengine(line 1760 注释要求低延迟)。

    Frontend(openless-all/app/src/pages/Settings.tsx)

    • ASR_PRESETS 扩 4 项;每项带 baseUrl + model 默认值。
    • onAsrProviderChange:切换时按 LLM preset 同款逻辑 overwrite asr.endpoint 与 asr.model,让用户切到一个新厂商时直接可用。
    • 把 asrProvider !== 'volcengine' 块下的硬编码 defaultValue="https://api.openai.com/v1" 与 placeholder whisper-1 替换为按当前 preset 的 baseUrl/model。

    i18n(openless-all/app/src/i18n/zh-CN.ts 与 en.ts)

    • settings.providers.presets.* 增 asrQwen / asrSiliconFlow / asrZhipu / asrGroq 四条文案。

    不在范围(V2,单独提)

    验收

    • cargo check --manifest-path src-tauri/Cargo.toml 通过
    • npm run build(tsc + vite)通过
    • 切到 SiliconFlow / Qwen / Zhipu / Groq,凭据缺失时不抛硬错(CLAUDE.md 静默 fallback 契约)
    • 风险:DashScope 兼容模式是否真支持 qwen3-asr-flash 走 /audio/transcriptions —— 实施时若 curl 一发实测不通,将在 PR 描述里标记「Qwen preset 已加但需用户自测/V2 单独适配」,不阻塞其余 4 家合并。

    分支:feat/asr-providers-presets

  3. appergb commented on May 3, 2026

    @appergb
    CollaboratorAuthor

    PR-Agent 在 #213 指出验收清单里"凭据缺失时不抛硬错(fallback 静默契约)"与代码现状不符——核实后确认:coordinator.rs::ensure_asr_credentials 在 main 上对 whisper / Volcengine 分支本就返回 Err 并弹错误胶囊,PR #213 的扩条件继承了相同语义,不是新引入的回归。

    修订验收:删掉「凭据缺失时不抛硬错」这条;保留 V1 实际行为(沿用既有"提示用户去填凭据"的硬错语义)。是否把 ensure_asr_credentials 整体改静默 fallback 是独立 UX 决策,需要时单独提 follow-up issue。

  4. added a commit that references this issue on May 4, 2026
    94d6a71
  5. added a commit that references this issue on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions