diff --git a/python/sglang/srt/utils/common.py b/python/sglang/srt/utils/common.py index 61b6baca6..b21d32db7 100644 --- a/python/sglang/srt/utils/common.py +++ b/python/sglang/srt/utils/common.py @@ -782,17 +782,24 @@ def load_audio( if _BACKEND == "torchcodec": from torchcodec.decoders import AudioDecoder - decoder = AudioDecoder( - source, - sample_rate=sr, - num_channels=1 if mono else None, - ) - samples = decoder.get_all_samples() - if mono: - return samples.data.squeeze(0).numpy() - return samples.data.T.numpy() + try: + decoder = AudioDecoder( + source, + sample_rate=sr, + num_channels=1 if mono else None, + ) + samples = decoder.get_all_samples() + if mono: + return samples.data.squeeze(0).numpy() + return samples.data.T.numpy() + except Exception as e: + # torchcodec's bytes-buffer IO can fail on WAV files that carry + # large trailing metadata chunks. Fall back to soundfile, which reads the PCM payload directly. + logger.warning( + f"torchcodec AudioDecoder failed ({e}); falling back to soundfile + torchaudio." + ) - # Fallback: soundfile + torchaudio (ARM / no FFmpeg) + # Fallback: soundfile + torchaudio (ARM / no FFmpeg / torchcodec failure) import soundfile as sf import torch import torchaudio