feat(asr): 降级兜底——分离路由全挂时退到无分离路由,只交付逐字稿

回退链从「一条主路由 + 一串替补」改成两级:先把同能力(有说话人分离)的路由
试完,全挂才降级到不分离的路由。降级是**本次事实**而不是配置事实,写进第 2 步
产物(capability_degraded / capability_zh),第 3 步与第 5/6 步据此判为不可用。

- transcribe.go:Result 加 CapabilityDegraded,判据 chain[0] 能分离而实际这条
  不能;与 HasSpeakers 分开记(后者可能是「配了却没输出」那种异常)
- audio_handlers.go:闸门从「读路由声明的能力」改成「读稿子里实际有没有标签」
  (audioTranscriptSpeakerKeys),与第 3 步共用同一句 SpeakerKeysOf;本次没分离
  → 哨兵错误 errAudioSpeakersUnavailableThisRun,不再放行去写一份看不出残缺的纪要
- 闸门**不看** capability_degraded:改动前落库的老产物没有这个字段,看它就 fail-open
- 第 1 步「转写要求」提前把降级的后果说清;第 2 步产物带完整措辞与「⚠」日志
- 前端两处(SpecialistPanel.vue / audioSkill.js)判断顺序改为先读实际结果
  has_speakers、再退回声明 speakers —— 顺序反了会在降级那一次照旧显示第 3 步
- ai_config.json:补 3 条云端无分离路由与各自的回退链

验证:三处变异(产物 key 拼错、标记写死 true、闸门 fail-closed)都验过会红;
新增两个用例文件走真实 gin 路由 + 真实鉴权中间件,断言拦下来的**理由**而不只是
「拦下来了」;go test ./... 全绿、gofmt 干净、前端构建通过。

同期把本地 ASR 装成 systemd 常驻服务(deploy/install_asr_local.sh 七步全过,
开机自启,实测 26.7 分钟录音 → 3.1 分钟)。装的过程挖出两个只在服务化时才暴露的坑:

- E12 转写堵住事件循环 → 探活超时 → 本地被判不健康 → auto 静默退云端、音频出网,
  全程没有任何报错。修法 run_in_threadpool(deploy/asr/serve.py)
- E13 服务账号的 ~ 不可写,pyannote 写不了 ~/.pyannote/database.yml,每次转写 500。
  修法 asr.env 加 HOME=<cache 目录>(该目录在 unit 的 ReadWritePaths 里)

顺带收口一处交付缺口:服务源码原先只有 ~/asr-poc 一份,而 DELIVERY.md 的清理计划
要 rm -rf 它 —— 那会让唯一副本变成 /opt 下 root 所有、不在任何版本库里的文件。
现在 deploy/asr/ 是唯一事实源,装机脚本与文档同步改。

已知偏离 / 未做(记在案):
- 界面那句「本次没有说话人分离,后续步骤不可用」只验到后端接口层,没有造出真实
  降级场景渲染出来看过
- deploy/asr/ 的引入改变了装机来源:原型目录 $SRC_DIR 从此只提供 venv 与模型,
  服务代码一律从仓库取

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
eaiadmin
2026-09-26 23:36:00 +08:00
co-authored by Claude Code
parent bc30bfce28
commit b4c8ea38d1
19 changed files with 2002 additions and 151 deletions
@@ -11,7 +11,7 @@
"audio_routes": {
"audio_route_local_whisper": {
"base_url": "http://127.0.0.1:8090/v1",
"description": "语音转写 · 本机 faster-whisper large-v3 + pyannote 3.1(音频不出本机)。由 deploy/eai_agentplatform-asr.service 常驻在 127.0.0.1:8090;服务不在时 audio_route_auto 会改走 fallback_routes 里的云端路由,并在转写产物里标注「音频已出本机」。timeout 定在 840s 而不是一小时:前端 api/audioSkill.js 给这一步的上限是 15 分钟,后端必须在它之前自己收手(否则用户看到的是 axios 超时,而后端还在跑),同时 840s 里还留得下云端那 600s 的回退预算",
"description": "语音转写 · 本机 faster-whisper large-v3 + pyannote 3.1(音频不出本机)。由 deploy/eai_agentplatform-asr.service 常驻在 127.0.0.1:8090;服务不在时 audio_route_auto 会改走 fallback_routes 里的云端路由,并在转写产物里标注「音频已出本机」。timeout 定在 840s 而不是一小时:前端 api/audioSkill.js 给这一步的上限是 15 分钟,后端必须在它之前自己收手(否则用户看到的是 axios 超时,而后端还在跑),同时 840s 里还留得下云端那 600s 的回退预算。回退链分两级:先把同能力(有说话人分离)的路由试完,最后才降级到不分离的路由;一旦降级,转写产物里 capability_degraded=true,第 3 步「识别说话人身份」与第 5/6 步「整理/纪要」判为不可用,只交付逐字稿",
"endpoint": "/audio/transcriptions",
"model": "large-v3",
"provider": "local_asr",
@@ -21,7 +21,7 @@
"timeout_seconds": 840
},
"audio_route_siliconflow_diarize": {
"description": "语音转写 · SiliconFlow / XingChen ASR Diarize(云端,音频会出本机;本地服务不可用时的回退,也可由管理员手动指定)",
"description": "语音转写 · SiliconFlow / XingChen ASR Diarize(云端,音频会出本机;本地服务不可用时的回退,也可由管理员手动指定)。回退链分两级:先把同能力(有说话人分离)的路由试完,最后才降级到不分离的路由;一旦降级,转写产物里 capability_degraded=true,第 3 步「识别说话人身份」与第 5/6 步「整理/纪要」判为不可用,只交付逐字稿",
"endpoint": "/audio/transcriptions",
"model": "XingChenAGI/XingChenASR-Diarize-V3.0",
"provider": "siliconflow",
@@ -31,7 +31,7 @@
"timeout_seconds": 600
},
"audio_route_siliconflow_qwen3": {
"description": "语音转写 · SiliconFlow / Qwen3-ASR(云端,音频会出公网;无说话人分离)",
"description": "语音转写 · SiliconFlow / Qwen3-ASR(云端,音频会出公网;无说话人分离)。实测最快(45 秒片段约 1.4 秒),是降级兜底的首选",
"endpoint": "/audio/transcriptions",
"model": "Qwen/Qwen3-ASR-1.7B",
"provider": "siliconflow",
@@ -39,6 +39,38 @@
"short_route_name": "SiliconFlow",
"supports_speakers": false,
"timeout_seconds": 600
},
"audio_route_openrouter_whisper": {
"description": "语音转写 · OpenRouter / OpenAI whisper-1(云端,音频会出公网;无说话人分离)。实测是几条云端路线里最慢的(45 秒片段约 9 秒),排在同能力链的末位",
"endpoint": "/audio/transcriptions",
"model": "openai/whisper-1",
"provider": "openrouter",
"base_url": "https://openrouter.ai/api/v1",
"short_model_name": "whisper-1",
"short_route_name": "OpenRouter",
"supports_speakers": false,
"timeout_seconds": 600
},
"audio_route_openrouter_gpt4o_transcribe": {
"description": "语音转写 · OpenRouter / OpenAI gpt-4o-transcribe(云端,音频会出公网;无说话人分离)。实测比 whisper-1 快一倍且断句更整,无分离路由里的首选",
"endpoint": "/audio/transcriptions",
"model": "openai/gpt-4o-transcribe",
"provider": "openrouter",
"base_url": "https://openrouter.ai/api/v1",
"short_model_name": "gpt-4o-transcribe",
"short_route_name": "OpenRouter",
"supports_speakers": false,
"timeout_seconds": 600
},
"audio_route_siliconflow_asr_ultra": {
"description": "语音转写 · SiliconFlow / XingChen ASR V3.2 Ultra(云端,音频会出公网;无说话人分离)。同门的 V3.2(非 Ultra)实测同样可用、约快一倍,但效果略差,没有单独建路由",
"endpoint": "/audio/transcriptions",
"model": "XingChenAGI/XingChenASR-V3.2-Ultra",
"provider": "siliconflow",
"short_model_name": "XingChen V3.2 Ultra",
"short_route_name": "SiliconFlow",
"supports_speakers": false,
"timeout_seconds": 600
}
},
"chat_routes": {
@@ -188,7 +220,11 @@
"chat_route_ollama_qwen"
],
"audio_route_local_whisper": [
"audio_route_siliconflow_diarize"
"audio_route_siliconflow_diarize",
"audio_route_siliconflow_qwen3",
"audio_route_siliconflow_asr_ultra",
"audio_route_openrouter_gpt4o_transcribe",
"audio_route_openrouter_whisper"
],
"embed_route_llamacpp_nomic": [
"embed_route_openrouter_text_v3"
@@ -198,6 +234,33 @@
],
"embed_route_openrouter_text_v3": [
"embed_route_ollama_bge_m3"
],
"audio_route_openrouter_gpt4o_transcribe": [
"audio_route_siliconflow_asr_ultra",
"audio_route_openrouter_whisper",
"audio_route_siliconflow_qwen3"
],
"audio_route_siliconflow_asr_ultra": [
"audio_route_openrouter_gpt4o_transcribe",
"audio_route_openrouter_whisper",
"audio_route_siliconflow_qwen3"
],
"audio_route_openrouter_whisper": [
"audio_route_openrouter_gpt4o_transcribe",
"audio_route_siliconflow_asr_ultra",
"audio_route_siliconflow_qwen3"
],
"audio_route_siliconflow_qwen3": [
"audio_route_openrouter_gpt4o_transcribe",
"audio_route_siliconflow_asr_ultra",
"audio_route_openrouter_whisper"
],
"audio_route_siliconflow_diarize": [
"audio_route_local_whisper",
"audio_route_siliconflow_qwen3",
"audio_route_siliconflow_asr_ultra",
"audio_route_openrouter_gpt4o_transcribe",
"audio_route_openrouter_whisper"
]
},
"image_routes": {