[Bug] QQ语音消息(AMR)因 convert_audio_format 后缀短路导致 STT 失败 (HTTP 400)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- python
- Domain
- audio-video-rtc
Research direction
Start in astrbot/core/utils/media_utils.py at convert_audio_format(), especially the output-extension shortcut around line 1130. Reproduce the mismatch using the AMR magic bytes and a .wav filename, then verify that audio sent through the STT path is converted correctly and that genuinely valid WAV files still avoid unnecessary conversion.
Written by the indexing model from the issue text.
Description
问题描述
通过 NapCat(aiocqhttp / OneBot v11)接入时,QQ 语音消息的语音转文字(STT)始终失败,上游 Whisper 兼容接口返回 HTTP 400。
原因
astrbot/core/utils/media_utils.py 的 convert_audio_format() 在判断是否需要转换时,仅依据文件名后缀,不校验文件实际内容:
# astrbot/core/utils/media_utils.py:1130
if audio_path.lower().endswith(f".{output_format}"):
return audio_path # 仅凭后缀即返回,跳过 ffmpeg 转换
而 NapCat 把 QQ 语音(实际编码为 AMR,magic bytes #!AMR)存为本地文件时统一使用 .wav 后缀。当目标格式为 wav 时后缀匹配成立,函数直接返回原文件、跳过 ffmpeg 转换,AMR 字节流顶着 .wav 名被传给 STT 接口,上游无法识别而返回 400。
如何复现?
- Docker 部署 AstrBot(
soulter/astrbot:latest),配置任意 OpenAI Whisper 兼容 STT provider(如硅基流动TeleAI/TeleSpeechASR) - 通过 NapCat 以 OneBot v11 接入(反向 WebSocket)
- 用 QQ 向机器人发送一条语音消息
- STT 失败,日志报
Speech-to-text failed: Error code: 400
AstrBot 版本
4.27.2
操作系统
Linux
部署方式
Docker (soulter/astrbot:4.27.2)
使用的消息平台适配器
OneBot v11 (NapCat,反向 WebSocket)
错误日志
[14:32:51.137] [Core] [INFO] [core.event_bus:74]: [default] [napcat(aiocqhttp)] /1378720352: [ComponentType.Record]
[14:32:51.413] [Core] [ERRO] [preprocess_stage.stage:206]: Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/preprocess_stage/stage.py", line 192, in _stt_record
result = await stt_provider.get_text(audio_url=path)
File "/AstrBot/astrbot/core/provider/sources/whisper_api_source.py", line 40, in get_text
result = await self.client.audio.transcriptions.create(...)
openai.BadRequestError: Error code: 400
[14:32:51.413] [Core] [ERRO] [preprocess_stage.stage:208]: Speech-to-text failed: Error code: 400
辅助信息
stage2_fix_works_clean.log
stage1_bug_repro_clean.log
检查清单
- Dominant language
- Python
- Stars
- 40.7k
- Forks
- 2.9k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 112
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AstrBotDevs/AstrBot
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AstrBotDevs/AstrBot#10033 · 3 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
AstrBotDevs/AstrBot#9999 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
AstrBotDevs/AstrBot#9945 · 2 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AstrBotDevs/AstrBot#9938 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
AstrBotDevs/AstrBot#9929 · 2 comments ·
All issues in AstrBotDevs/AstrBot
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100