Skip to content

fix(asr): 修复 ASR 能力探测将空转录误判为格式不兼容的问题#81

Merged
fqscfqj merged 3 commits into
mainfrom
fix/asr-format-capability-probe
Jul 14, 2026
Merged

fix(asr): 修复 ASR 能力探测将空转录误判为格式不兼容的问题#81
fqscfqj merged 3 commits into
mainfrom
fix/asr-format-capability-probe

Conversation

@fqscfqj

@fqscfqj fqscfqj commented Jul 14, 2026

Copy link
Copy Markdown
Owner

问题

Docker 运行 whisper-1 时频繁出现:

ASR API 不兼容:无法协商出支持的转录格式。

根因

能力探测阶段把合法的 empty transcription 当成格式不支持;同时错误分类过宽,把鉴权/限流/模型不存在等错误也吞并成通用格式不兼容。

修复

  • 合法空转录现在会被识别为格式受支持。
  • 收紧 _is_format_error(),只有 400/422 参数拒绝才进入格式降级。
  • raw HTTP 与 SDK 均失败时保留双方错误信息。
  • 拒绝 HTTP 200 但返回 {"error": ...} 的异常 payload。
  • 原子发布能力缓存,避免并发重复探测。
  • 补充回归测试。

测试

pytest tests/test_asr_api_client.py tests/test_speech_recognition_config.py -q
16 passed

fqscfqj added 2 commits July 14, 2026 22:02
Treat valid empty transcription responses as supported formats, preserve request failures, tighten format-error detection, and add regression coverage.

@fqscfqj fqscfqj left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已完成审查并直接修复发现的问题。

修复内容:

  • 新增 AsrHttpError,让 raw Whisper/Voxtral HTTP 请求保留结构化的 status_code
  • _is_format_error() 现在能可靠排除 401、429、500 等非参数校验错误,避免再次误报为“无法协商出支持的转录格式”。
  • 增加 401/429/500 不降级、400 正常识别为格式错误的回归测试。

验证:

  • python -m unittest tests.test_asr_api_client tests.test_speech_recognition_config -v:17 tests passed。
  • python -m compileallgit diff --check 通过。

修复提交:1c18a3d。除该问题外,本 PR 的空转录能力探测、异常 payload 校验及能力缓存原子发布改动均合理。

@fqscfqj

fqscfqj commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

已在 192.168.2.3 的 Docker 部署上完成真实 ASR 联调测试。

环境:

  • Y2A-Auto 容器:y2a-auto,对外端口 10008
  • 当前线上镜像:4.6.3 / revision 13d6df8(未包含本 PR)
  • ASR:whisper-1,时间戳粒度 segment,word

复现结果:线上旧代码的任务日志可稳定复现 AsrFormatIncompatibleError: ASR API 不兼容:无法协商出支持的转录格式

验证方式:未替换或重启线上容器,仅将 PR 最新版 asr_api_client.py 复制到容器 /tmp,使用容器现有 ASR 配置和实时生成的 1 秒 WAV 直接执行能力探测。

结果:

PROBE_OK
format= verbose_json
granularities= (segment, word)
result_present= True
result_ok= True

结论:本 PR 最新提交 1c18a3d 已在实际 Docker 部署及真实远端 ASR API 上验证通过,原有“无法协商格式”问题已消失。测试过程没有修改持久化配置、运行代码或重启容器。

@fqscfqj

fqscfqj commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

继续真实任务联调时发现并修复了第二个问题:ASR 语言检测返回 english,但 Whisper 兼容接口要求 ISO-639-1 代码 en

新增提交 22770a1

  • 将常见语言名称规范化为 ISO-639-1 代码,例如 english → enchinese → zhjapanese → ja
  • set_language_hint()、SDK 请求和 raw HTTP 请求统一使用规范化后的语言代码。
  • 无法识别的语言提示会被忽略,而不是向 API 发送非法值。
  • 增加语言名称、区域代码和未知值的回归测试。

实际任务 e0604163-7536-4367-af25-b27cf3dc7672 已重新生成字幕成功:

RESULT=/app/downloads/e0604163-7536-4367-af25-b27cf3dc7672/asr_e0604163-7536-4367-af25-b27cf3dc7672.srt
ELAPSED_SECONDS=27.05
SIZE=2223
24 cues
WARNING=
ERROR=

字幕覆盖约 00:00:00.600 → 00:01:37.100,内容和时间轴均正常。单元测试更新为 19 tests passed。

@fqscfqj

fqscfqj commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

补充 LocalAI 实际兼容性验证:

测试端点:用户提供的 LocalAI OpenAI-compatible API(凭据不记录在评论中)
模型:parakeet-crispasr

验证结果:

  1. /v1/models 可正常发现 parakeet-crispasr
  2. 1 秒无语音 WAV 的能力探测成功:verbose_json + segment,word 被正确识别为支持;空转录不会再误判为格式不兼容。
  3. 使用任务 e0604163-7536-4367-af25-b27cf3dc7672 的完整 97 秒视频,在 Docker 版 Y2A-Auto 中通过 PR 最新代码生成字幕成功:
RESULT=/app/downloads/e0604163-7536-4367-af25-b27cf3dc7672/localai_parakeet_e0604163-7536-4367-af25-b27cf3dc7672.srt
ELAPSED_SECONDS=21.98
SIZE=1925
15 cues
WARNING=
ERROR=

字幕覆盖 00:00:00.600 → 00:01:36.980,内容及时间轴正常。

结论:PR 当前版本已分别通过 Aihubmix whisper-1 和 LocalAI parakeet-crispasr 两种实际后端验证。GitHub CI / CodeQL 均通过。

@fqscfqj
fqscfqj merged commit 9fd69f2 into main Jul 14, 2026
5 checks passed
@fqscfqj
fqscfqj deleted the fix/asr-format-capability-probe branch July 14, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant