-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemucs_utils.py
More file actions
43 lines (30 loc) · 1 KB
/
demucs_utils.py
File metadata and controls
43 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import subprocess
def separate_stems(audio_path, output_dir):
"""
Runs Demucs to separate stems into the given output directory.
Returns the folder containing separated stems.
"""
os.makedirs(output_dir, exist_ok=True)
command = [
"demucs",
"-n", "htdemucs",
"--two-stems=vocals",
"-o", output_dir,
audio_path
]
subprocess.run(command, check=True)
# Demucs creates:
# output_dir/htdemucs/<filename_without_ext>/
base_name = os.path.splitext(os.path.basename(audio_path))[0]
stems_path = os.path.join(output_dir, "htdemucs", base_name)
return stems_path
def separate_vocals(audio_path, output_dir):
"""
Returns path to isolated vocals file.
"""
stems_path = separate_stems(audio_path, output_dir)
vocals_path = os.path.join(stems_path, "vocals.wav")
if not os.path.exists(vocals_path):
raise FileNotFoundError("Vocals file not found after Demucs separation.")
return vocals_path