From 0c52feada63a7aea461e2ae2c2c006a7030a49df Mon Sep 17 00:00:00 2001 From: Meisoftcoltd <38667978+Meisoftcoltd@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:57:14 +0000 Subject: [PATCH] Fix Demucs crash on multi-channel audio by clipping to stereo --- demucs_nodes.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/demucs_nodes.py b/demucs_nodes.py index f8a0373..b9c7614 100644 --- a/demucs_nodes.py +++ b/demucs_nodes.py @@ -97,11 +97,16 @@ class DemucsAudioSeparator: if waveform.dim() == 2: waveform = waveform.unsqueeze(0) - # --- FIX 1: MONO TO STEREO --- - # If audio has 1 channel, duplicate it to 2 (Demucs requires stereo input) - if waveform.shape[1] == 1: + # --- FIX 1: CHANNEL MANAGEMENT (MONO/STEREO/SURROUND) --- + # Demucs strictly requires 2 channels (stereo) + channels = waveform.shape[1] + + if channels == 1: print("⚡ Detected mono audio, converting to stereo for Demucs...") waveform = waveform.repeat(1, 2, 1) + elif channels > 2: + print(f"⚡ Detected {channels} channels, clipping to stereo for Demucs...") + waveform = waveform[:, :2, :] # --- FIX 2: PRECISION SAFETY --- # Move to device BUT keep in float32 for resampling