Zen-4011/audio-separation-model
0
1import subprocess2import os3 4def separate_audio(file_path, output_dir = "separated"):5 """6 Runs Demucs htdemucs on the given audio file.7 Returns the path to the output stem folder, or None on failure.8 Called by app.py via run_demucs() — kept here as a standalone9 utility for testing separation independently.10 """11 print(f"Separating: {file_path}")12 13 command = [14 "python3", "-m", "demucs.separate",15 "-n", "htdemucs",16 "--out", output_dir,17 file_path18 ]19 20 result = subprocess.run(command, capture_output = True, text = True)21 22 if result.returncode == 0:23 base_name = os.path.splitext(os.path.basename(file_path))[0]24 output_path = os.path.join(output_dir, "htdemucs", base_name)25 print(f"Success — stems at: {output_path}")26 return output_path27 28 else:29 print(f"Demucs failed:\n{result.stderr}")30 return None31 32if __name__ == "__main__":33 target = "test-audio.mp3"34 if os.path.exists(target):35 separate_audio(target)36 else:37 print(f"File not found: {target}")