From 6b9adf08165d0e9051ced9d4e88478c76503e9fe Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sun, 5 Apr 2026 22:03:57 +0200 Subject: [PATCH] fix: fall back to soundfile when torchcodec FFmpeg libs are missing Recent torchaudio defaults to torchcodec as the audio backend, which requires FFmpeg shared libraries. Falls back to soundfile for envs where torchcodec can't load (e.g. containerised ComfyUI without system FFmpeg). Co-Authored-By: Claude Sonnet 4.6 --- nodes/selva_lora_trainer.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nodes/selva_lora_trainer.py b/nodes/selva_lora_trainer.py index 9da3277..f2cd95b 100644 --- a/nodes/selva_lora_trainer.py +++ b/nodes/selva_lora_trainer.py @@ -51,7 +51,15 @@ def _find_audio(npz_path: Path) -> Path | None: def _load_audio(path: Path, target_sr: int, duration: float) -> torch.Tensor: - waveform, sr = torchaudio.load(str(path)) + try: + waveform, sr = torchaudio.load(str(path)) + except RuntimeError as e: + if "torchcodec" not in str(e).lower() and "libtorchcodec" not in str(e).lower(): + raise + # torchcodec unavailable (FFmpeg shared libs missing) — fall back to soundfile + import soundfile as sf + data, sr = sf.read(str(path), always_2d=True) # [frames, channels] + waveform = torch.from_numpy(data.T).float() # [channels, frames] if waveform.shape[0] > 1: waveform = waveform.mean(0, keepdim=True) waveform = waveform.squeeze(0).float()