Bug: model.generate(input=bytes) hangs for minutes on raw PCM chunks that trigger audio container false-positive
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Active
- Domain
- audio-video-rtc, machine-learning
Research direction
Read funasr/utils/load_utils.py, especially load_bytes(), _is_audio_container(), and _has_consecutive_mp3_frames(), then trace the input path from funasr/auto/auto_model.py. Build a focused test with 6400-byte raw int16 PCM chunks, verify whether they are misclassified as container audio, and confirm that generate() returns promptly without the reported decode failure.
Written by the indexing model from the issue text.
Description
🐛 Bug Report: model.generate(input=bytes) 在处理流式原始 PCM 时长时间 hang
版本
- FunASR: 1.4.0
- Python: 3.10.12
- PyTorch: 1.12.0
- OS: Centos7.9
场景
FSMN VAD 模型做流式推理:每 200ms 收到一个 int16 PCM chunk(6400 字节,16kHz mono),调用 AutoModel.generate()。
调用方式
from funasr import AutoModel
model = AutoModel(model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch", disable_update=True)
# 每 200ms 一帧,pcm_chunk 是原始 int16 PCM bytes,6400 字节(16kHz x 0.2s x 2)
cache = {}
for pcm_chunk in pcm_chunks:
result = model.generate(
input=pcm_chunk, # bytes, 原始 int16 PCM, 6400 字节
cache=cache,
chunk_size=200,
disable_pbar=True,
)
现象
服务稳定运行数周后,某次处理中 generate() 调用hang 约三分钟不返回。期间该路会话的所有后续音频帧无法处理。三分钟后抛出异常:
Failed to decode container-formatted audio bytes.
Verify that the input is a complete supported audio file and that torchaudio,
soundfile, or ffmpeg is available.
通常 generate() 对一个 200ms chunk 的推理只需 10-20ms。hang 的持续时间远超正常推理时间。
补充信息
- FunASR 版本 1.4.0(
pip show funasr输出) - 输入是原始 int16 PCM bytes,不是 WAV/MP3 等容器格式文件
- 该错误低频出现(数周一次),未找到稳定复现方式
以下是 AI(Claude)辅助分析的推测,供参考:
AI 推测的可能原因
-
_is_audio_container误判:load_utils.py中load_bytes()对所有bytes输入调用_is_audio_container()进行容器格式检测。200ms int16 PCM chunk(6400 字节)有一定概率命中 MPEG 帧头假阳性(data[0] == 0xFF and (data[1] & 0xE0) == 0xE0),随后_has_consecutive_mp3_frames()在随机 PCM 数据中有非零概率通过三层帧头校验。 -
误判后 torchaudio 陷入长时间错误恢复:一旦判定为容器格式,
load_bytes()调用load_audio_text_image_video(BytesIO(input), fs=16000),torchaudio 被喂入一个 6400 字节的"假 MP3 文件",内部错误恢复路径反复尝试重新同步,持续数分钟后才放弃。
(以上推测基于对 FunASR 1.4.1 funasr/utils/load_utils.py 和 funasr/auto/auto_model.py 源码的阅读,尚未通过构造特定 PCM 数据复现验证。)
- Dominant language
- Python
- Stars
- 20.5k
- Forks
- 2.1k
- Avg merge
- 17h 27m
- Merged PRs (30d)
- 91
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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 modelscope/FunASR
-
Bug: blank lines in wav.scp / jsonl file lists crash prepare_data_iterator (IndexError / JSONDecodeError)Possibly taken @Lesereingrape claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelscope/FunASR#3757 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
modelscope/FunASR#3730 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
modelscope/FunASR#3704 · 1 comment ·
Maintainers usually reply within 1 day
-
没有vllm时使用fun-asr-nano每次都重新加载模型Possibly taken A pull request linked to this issue is open or already merged. Openbug needs feedback
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelscope/FunASR#3401 · 2 comments ·
Maintainers usually reply within 1 day
-
Bug: cmvn readers raise IndexError on blank lines and return empty statistics without errorPossibly taken @Lesereingrape claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
modelscope/FunASR#3759 ·
Maintainers usually reply within 1 day
All issues in modelscope/FunASR
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
FuRongJun-1999/dsh-memory#56 ·
Maintainers usually reply within 1 day
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
pgadmin-org/pgadmin4#10503 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
521xueweihan/HelloGitHub#3857 ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
rai-opensource/spatialmath-python#235 ·
Maintainers usually reply within 1 day
-
needs-ac
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Ikalus1988/MisakaNet#2845 ·
Maintainers usually reply within 1 day