Skip to content

feat(asr): 新增百炼 Qwen3-ASR-Flash 实时供应商(OpenAI Realtime WS 协议)#775

Open
bigsongeth wants to merge 2 commits into
Open-Less:betafrom
bigsongeth:feat/qwen3-asr-realtime
Open

feat(asr): 新增百炼 Qwen3-ASR-Flash 实时供应商(OpenAI Realtime WS 协议)#775
bigsongeth wants to merge 2 commits into
Open-Less:betafrom
bigsongeth:feat/qwen3-asr-realtime

Conversation

@bigsongeth

@bigsongeth bigsongeth commented Jul 10, 2026

Copy link
Copy Markdown

User description

摘要

Closes #774依赖 #773(分支基于其之上,请先合并该 PR;本 PR 复用其引入的 endpoint_scheme_is_websocket 校验)。

实现 asr/bailian.rs 头注释预留的 follow-up 协议线:Qwen3-ASR-Flash 实时版(OpenAI Realtime 风格 WebSocket,/api-ws/v1/realtime),作为独立供应商 bailian-qwen3-realtime 与经典 fun-asr-realtime 并列。业务空间专属域名(wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com)用户与受限工作空间 Key(仅授权 Qwen3 系模型)用户由此获得可用的实时通道。

修复 / 新增 / 改进

  • asr/qwen_realtime.rs(新增,核心):Realtime 协议 client。base64 JSON 事件流(input_audio_buffer.append,3200B/100ms 块)+ server_vad 服务端自动断句;按到达顺序收集 completed 句段(CJK 直连、拉丁词间补空格);session.finish 依赖服务端冲刷尾段后回 session.finished。整体结构、并发模型(send worker + 弱引用 reader)、超时口径(5s 会话建立 / 12s 最终结果)与 bailian.rs 保持同构。
  • 协议行为均经 2026-07 线上实测(公共网关 + 专属域名):尾段冲刷(说到一半松手不丢字)、纯静音验证干净返回、language 省略走服务端自动检测。
  • 接线coordinator / asr_wiring / dictation / qa_session / resources 按 Bailian 分支同构接入(流式 WS + DeferredAsrBridge 缓冲开链前音频),含听写、悬浮问答、重转录、取消全路径。
  • 连接检查:「验证」发 500ms 静音做真实会话检查;「拉取模型」先连通性检查再返回官方文档在案的模型列表(稳定别名 + 2 个快照版);协议头校验返回 qwen3EndpointSchemeInvalid(含默认 Realtime 地址的明确提示)。
  • 前端:ASR 供应商下拉新增「阿里云百炼 Qwen3 实时 ASR」预设;i18n 5 语言(en / zh-CN / zh-TW / ja / ko)。

兼容

  • 不包含:热词(Realtime 协议文档未提供 vocabulary 下发);手动 commit 模式(采用 server_vad,非 VAD 模式官方建议 ≤60s,不适合不限时长听写);批式 qwen3-asr-flash(兼容模式 chat/completions,另一条协议线)。
  • 对现有用户 / 本地环境 / 构建流程的影响:纯增量——新增供应商 id bailian-qwen3-realtime,不改动任何现有供应商的行为、凭据格式与默认值。

测试计划

  • 命令:cargo test --manifest-path src-tauri/Cargo.toml → 573 passed / 0 failed(含新增 18 个 client 单测:URL 拼接/专属域名、消息构造、interim stash/text 语义、completed 收集、尾段兜底、错误事件、静音空会话、句段拼接、音频缓冲)
  • 命令:npm run build(tsc + vite)→ 通过
  • 协议实测:独立 WebSocket 脚本直连线上验证 VAD 断句、session.finish 尾段冲刷(含刻意截断音频尾部的场景)、静音会话、省略 language、专属域名全链路真实语音转写逐字正确。
  • 手工验证(macOS 15 / Apple Silicon,scripts/build-mac.sh 本地构建安装):
    • 新预设选择后默认值正确填充;「验证」「拉取模型」通过。
    • 公共网关与业务空间专属域名两种 endpoint 均实测听写正常。
    • 多句带停顿听写断句拼接正常;说到一半立即松手尾段不丢。

PR Type

Bug fix, Enhancement


Description

  • Added new ASR provider for Qwen3-ASR-Flash Realtime (OpenAI Realtime WS protocol)

  • Fixed bailian ASR connection check: increased silence duration and endpoint scheme validation

  • Updated frontend and i18n for new provider and error codes across 5 languages

  • Wired new provider into coordinator, dictation, and QA sessions


Diagram Walkthrough

flowchart LR
  User["User"] -- "configures" --> Provider["Qwen3Realtime Provider"]
  Provider -- "connects WS" --> Gateway["DashScope Realtime WS"]
  Gateway -- "sends audio events" --> Client["qwen_realtime.rs client"]
  Client -- "receives transcription events" --> Result["RawTranscript"]
Loading

File Walkthrough

Relevant files
Bug fix
2 files
bailian.rs
Added WebSocket scheme validation helper                                 
+27/-0   
providers.rs
Added validation for Qwen3 and fixed bailian EmptyAudio   
+71/-1   
Enhancement
10 files
mod.rs
Exported Qwen3RealtimeASR and credentials                               
+2/-0     
qwen_realtime.rs
Implemented Qwen3-ASR-Flash realtime WS client                     
+802/-0 
credentials.rs
Added credential check for new Qwen3 realtime provider     
+3/-1     
coordinator.rs
Integrated Qwen3 realtime ASR into coordinator                     
+41/-2   
asr_wiring.rs
Added Qwen3 realtime ASR wiring                                                   
+24/-0   
dictation.rs
Added dictation session support for Qwen3 realtime             
+104/-0 
qa_session.rs
Added QA session support for Qwen3 realtime                           
+39/-0   
resources.rs
Added cancel support for Qwen3 realtime                                   
+1/-0     
ProvidersSection.tsx
Added preset entry for Bailian Qwen3 Realtime                       
+6/-0     
shared.tsx
Added AsrPresetId for new provider                                             
+1/-0     
Documentation
5 files
en.ts
Added i18n for new provider name and error messages           
+3/-0     
ja.ts
Added i18n for new provider name and error messages           
+3/-0     
ko.ts
Added i18n for new provider name and error messages           
+3/-0     
zh-CN.ts
Added i18n for new provider name and error messages           
+3/-0     
zh-TW.ts
Added i18n for new provider name and error messages           
+3/-0     

三个缺陷叠加导致「阿里云百炼实时 ASR」的连接检查完全不可用:

1. 「验证」必然失败:只发 1 个 100ms 静音块就 finish-task,DashScope 对
   <200ms 音频必返回 task-failed: EmptyAudio(2026-07 实测边界:100ms 拒、
   200ms 起收)——有效凭据也永远显示「操作失败」。改为发送 500ms 静音。
2. 「拉取模型」假成功:直接返回硬编码列表、不发任何网络请求,Key/endpoint
   全错也显示成功。现在先执行与「验证」相同的 WebSocket 连通性检查
   (百炼无模型列表接口,列表本身仍为静态)。
3. 接口地址误填 https://(百炼控制台兼容模式/专属域名地址)时,WS 握手报的
   "URL scheme not supported" 被前端兜底成笼统「操作失败」。现在验证入口
   校验协议头必须为 ws:// / wss://,返回专用错误码
   bailianEndpointSchemeInvalid,前端映射为含默认 wss 地址的明确提示
   (en / zh-CN / zh-TW / ja / ko)。

测试:cargo test 555 passed;npm run build (tsc + vite) 通过;
DashScope 线上协议行为已用独立脚本实测确认。
bailian.rs 头注释预留的 follow-up 协议线:/api-ws/v1/realtime,与经典
/api-ws/v1/inference 并列为独立供应商 bailian-qwen3-realtime。

- asr/qwen_realtime.rs:新客户端。base64 JSON 事件流 + server_vad 自动断句,
  按序收集 completed 句段;session.finish 冲刷尾段后回 session.finished。
  关键协议行为均经 2026-07 线上实测:尾段冲刷(说到一半松手不丢字)、
  纯静音验证干净返回、language 省略走自动检测、业务空间专属域名
  (wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com)同样承载此路径。
- coordinator / asr_wiring / dictation / qa_session / resources:与 Bailian
  分支同构接线(流式 WS + DeferredAsrBridge)。
- 验证与拉取模型:真实 WS 连通性检查;协议头校验(qwen3EndpointSchemeInvalid)。
- 前端:ASR 预设下拉新增一项;i18n 5 语言。

测试:cargo test 573 passed(新增 18 个客户端单测);npm run build 通过。
@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

774 - Partially compliant

Compliant requirements:

  • 新增独立 ASR 供应商 (bailian-qwen3-realtime),包含专用 client (qwen_realtime.rs) 和 provider kind。
  • 默认 endpoint 为 wss://dashscope.aliyuncs.com/api-ws/v1/realtime,默认模型为 qwen3-asr-flash-realtime
  • 支持用户自定义 endpoint(包含业务空间专属域名),connect_url 正确拼接模型参数或保留已有查询。
  • 验证 (validate_qwen3_realtime_asr_provider) 和拉取模型 (list_provider_models) 均执行真实 WebSocket 连通性检查。
  • 验证前校验 endpoint 协议头必须为 ws:// 或 wss://,不符合时返回专用错误码 qwen3EndpointSchemeInvalid
  • 未移除或修改现有 bailian (fun-asr-realtime) 供应商。

Non-compliant requirements:

(无)

Requires further human verification:

(无)

773 - Partially compliant

Compliant requirements:

  • 验证音频长度从 1 个 chunk (100ms) 改为 5 个 chunk (500ms)。
  • list_provider_models 的 bailian 分支在返回静态列表前调用 validate_bailian_asr_provider 执行连通性检查。
  • 验证前调用 endpoint_scheme_is_websocket 检查协议头,不符合时返回 bailianEndpointSchemeInvalid
  • 新增 endpoint_scheme_is_websocket 函数(bailian.rs)及其单元测试。
  • 所有 5 种语言 i18n 文件均已添加 bailianEndpointSchemeInvalidqwen3EndpointSchemeInvalid 条目。

Non-compliant requirements:

(无)

Requires further human verification:

(无)

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[asr] 新增百炼 Qwen3-ASR-Flash 实时供应商(OpenAI Realtime WS 协议),支持业务空间专属域名

1 participant