feat(asr): 百炼 ASR 支持 fun-asr-flash 并统一三协议为单一入口 - #793
Conversation
PR Reviewer Guide 🔍(Review updated until commit fec5331)Here are some key observations to aid the review process:
|
|
开始审查 |
|
Persistent review updated to latest commit 5f4078b |
LauraGPT
left a comment
There was a problem hiding this comment.
整体协议主路径、跨平台接线和测试覆盖做得很完整。我按阿里云当前公开 API 文档逐项核对后,发现 3 个 CI 不会捕获、但会影响真实用户的边界;已在对应行留下可复现说明和最小修复方向。
| Ok(crate::asr::bailian::PROVIDER_ID.to_string()) | ||
| } else if model.starts_with("qwen3-asr-flash-realtime") { | ||
| Ok(crate::asr::qwen_realtime::PROVIDER_ID.to_string()) | ||
| } else if model.starts_with("fun-asr-flash") { |
There was a problem hiding this comment.
模型前缀会把实时模型误送到批量 HTTP。 官方模型表中 fun-asr-flash-8k-realtime / fun-asr-flash-8k-realtime-2026-01-28 是实时 WebSocket 模型,但它们同样满足这里的 starts_with("fun-asr-flash"),因此手填后会被路由到 multimodal-generation,协议必然不匹配。UI 明确允许手填 DashScope 模型,所以这条路径可达。建议先显式识别并拒绝(当前录音链是 16 kHz,而该系列要求 8 kHz),同时把批量 Flash 收紧为当前受支持模型的 allowlist,并加一个 fun-asr-flash-8k-realtime 不得进入 DashScopeMultimodal 的回归测试。官方模型矩阵:https://help.aliyun.com/en/model-studio/asr-model/
| DashScope ASR 模型),协议按模型名在后端自动路由,接口地址随协议自动推导, | ||
| 故不暴露 endpoint 字段。模型框下一行提示当前模型是「实时」还是「录音文件」, | ||
| 解决三种模型看不出区别的问题。 */} | ||
| {!unifiedBailian && ( |
There was a problem hiding this comment.
隐藏 endpoint 后,统一入口实际上只能使用中国区默认域名。 后端在 unified Bailian 下也会忽略已存 endpoint,固定改用 dashscope.aliyuncs.com;但北京与新加坡 API Key 分区,官方要求新加坡使用 dashscope-intl.aliyuncs.com 或 {WorkspaceId}.ap-southeast-1.maas.aliyuncs.com,Qwen Realtime 和 Fun-ASR-Flash 都如此。新用户又无法选择隐藏别名,因此新加坡用户没有任何可配置路径。建议保留 endpoint/区域选择,按所选模型只规范化 scheme/path、不要丢掉 host;至少补中国区和新加坡区 host 的路由测试。官方 Flash endpoint:https://help.aliyun.com/en/model-studio/fun-asr-recorded-speech-recognition-http-api ,Qwen Realtime endpoint:https://help.aliyun.com/en/model-studio/qwen-asr-realtime-interaction-process
| "format": "wav", | ||
| "sample_rate": "16000", | ||
| }); | ||
| if let Some(vocabulary_id) = vocabulary_id.filter(|value| !value.trim().is_empty()) { |
There was a problem hiding this comment.
fun-asr-flash-2026-06-15 的同步 HTTP 参数中没有 vocabulary_id。 官方文档只列出 format 和可选 sample_rate;该模型的准确率增强方式是把领域词作为 input.messages[].content[{type:"input_text"}] 上下文,而不是自定义热词 ID。当前统一入口会继承实时 Fun-ASR 用户已有的 asr.vocabulary_id 并注入这里,可能被服务端拒绝或静默忽略,同时 UI 会误导用户认为它生效。建议 Flash 路径不发送该字段并隐藏对应输入;若要复用词表,可把应用内短语按 400 字限制映射为 input_text 上下文。官方请求参数:https://help.aliyun.com/en/model-studio/fun-asr-recorded-speech-recognition-http-api
问题已收到,开始解决 |
|
Persistent review updated to latest commit 39eddf9 |
# Conflicts: # openless-all/app/src-tauri/src/coordinator/dictation.rs
|
Persistent review updated to latest commit fec5331 |
User description
摘要
让阿里云百炼(DashScope)三种 ASR 协议都能用、并收成一个用户入口。
百炼同一厂商、同一把 key 下有三种互不兼容的线协议:
fun-asr-realtimeqwen3-asr-flash-realtimefun-asr-flash此前只有前两个,且各是独立 provider、独立 key;
fun-asr-flash是唯一的 HTTP 批量协议,现有两条 WS 通道都接不了 → 用不了。本 PR 补齐第三条通道,并把三条收成一个「阿里云百炼」入口、按模型名自动路由协议。修复 / 新增 / 改进
asr/dashscope_multimodal.rs:multimodal-generation 批量 ASR 客户端(攒 PCM → WAV → base64 → POST → 多路径兜底解析响应),复用 mimo 的分片/CJK 拼接。ActiveAsrProviderKind单一来源,preflight_credential/configured_fields等改为穷尽match(去掉静默 else 兜底),新增通道时编译器强制补齐各分发点,消除「装完才发现某处漏了」。resolve_effective_asr_provider(model)按模型名把 build / 验证 路由到对应协议,endpoint 按协议自动推导;模型框下加实时 / 录音文件协议提示。兼容
bailian(fun-asr-realtime)用户无感,默认仍走经典实时;bailian-qwen3-realtime保留为隐藏别名,老配置照常工作(下拉仅对已在用者显示);bailian-fun-asr-flash为本 PR 新增(此前无用户);split_pcm_by_duration/join_transcript_chunks提为pub(crate)供复用(零行为改动);无新增依赖。测试计划
cargo test --lib→ 结果:610 passed(对beta基线);新增resolve_effective_asr_provider/preflight_credential/configured_fields/ dashscope 客户端等单测。cargo check(macOS native)+ 前端tsc(npm run build)→ 均通过(对beta基线);跨平台 Android/Win/Linux 未加 cfg 分支,交 CI 确认。fun-asr-flash-2026-06-15multimodal-generation(URL 与 base64 两种输入)→ HTTP 200、转写正确、~600ms。PR Type
Enhancement, Bug fix
Description
Add DashScopeMultimodalASR for fun-asr-flash batch ASR
Refactor provider classification into exhaustive ActiveAsrProviderKind enum
Unify three DashScope protocols into single UI entry with model-based routing
Consolidate credential preflight and configured fields checks using new enum
Update i18n and UI for unified Bailian provider with protocol hints
Diagram Walkthrough
File Walkthrough
7 files
New batch ASR client for fun-asr-flashUpdate validation for unified BailianRefactor preflight and build with effective providerRoute dictation sessions by effective providerHandle DashScopeMultimodal during QADerive ASR name keys from shared presetsUnified Bailian UI with model protocol hints4 files
Reuse split/join functions for multimodalUse ActiveAsrProviderKind for credential checksAdd enum routing and endpoint derivationMove ASR presets to single source of truth1 files
Register new dashscope_multimodal module1 files
Cancel for DashScopeMultimodal5 files
Add UI labels for unified BailianAdd UI labels for unified BailianAdd UI labels for unified BailianAdd UI labels for unified BailianAdd UI labels for unified Bailian