File size: 1,943 Bytes
c9c6048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4d96a11
c9c6048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
from pathlib import Path
import subprocess

class AudioProcessor:
    def __init__(self, input_audio, output_dir):
        self.input_audio = Path(input_audio)
        self.output_dir = Path(output_dir)
        self.output_dir.mkdir(parents=True, exist_ok=True)

    def run_demucs(self):
        """Process audio using Demucs to separate vocals"""
        try:
            # Use default model (htdemucs) without MP3 output to avoid diffq dependency
            subprocess.run([
                "demucs",
                "--two-stems=vocals",
               # "-n", "mdx_extra_q",
                "-o", str(self.output_dir),
                str(self.input_audio)
            ], check=True)
            print("Demucs processing completed successfully")
            return True
        except subprocess.CalledProcessError as e:
            print(f"Error during Demucs execution: {e}")
            return False

    def get_vocals_path(self):
        """Get path to the separated vocals file"""
        # Path for htdemucs model output
        vocals_path = self.output_dir / "htdemucs" / Path(self.input_audio.stem) / "vocals.wav"
        if vocals_path.exists():
            print(f"Vocals found at: {vocals_path}")
            return str(vocals_path)
        print("Vocals file not found")
        return None

    def get_no_vocals_path(self):
        """Get path to the no-vocals (instrumental) file"""
        # Path for htdemucs model output
        no_vocals_path = self.output_dir / "htdemucs" / Path(self.input_audio.stem) / "no_vocals.wav"
        if no_vocals_path.exists():
            print(f"No-vocals track found at: {no_vocals_path}")
            return str(no_vocals_path)
        print("No-vocals file not found")
        return None

    def cleanup(self):
        """Remove temporary audio files"""
        if self.input_audio.exists():
            self.input_audio.unlink()
        print("Temporary audio files cleaned up")