demix 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- demix/__init__.py +47 -0
- demix/cli.py +388 -0
- demix/py.typed +0 -0
- demix-1.0.1.dist-info/LICENSE +201 -0
- demix-1.0.1.dist-info/METADATA +145 -0
- demix-1.0.1.dist-info/RECORD +9 -0
- demix-1.0.1.dist-info/WHEEL +5 -0
- demix-1.0.1.dist-info/entry_points.txt +2 -0
- demix-1.0.1.dist-info/top_level.txt +1 -0
demix/__init__.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
demix - Separate audio into stems (vocals, instruments) using AI.
|
|
3
|
+
|
|
4
|
+
A CLI tool that separates audio from songs into individual stems using
|
|
5
|
+
Spleeter. Supports YouTube downloads or local audio files, with options
|
|
6
|
+
for tempo/pitch adjustments and audio cutting.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "1.0.1"
|
|
10
|
+
__author__ = "Piotr Wittchen"
|
|
11
|
+
|
|
12
|
+
from demix.cli import (
|
|
13
|
+
main,
|
|
14
|
+
STEM_MODES,
|
|
15
|
+
DEFAULT_VIDEO_RESOLUTION,
|
|
16
|
+
Spinner,
|
|
17
|
+
parse_args,
|
|
18
|
+
parse_time,
|
|
19
|
+
format_time,
|
|
20
|
+
remove_dir,
|
|
21
|
+
clean,
|
|
22
|
+
convert_wav_to_mp3,
|
|
23
|
+
convert_to_mp3,
|
|
24
|
+
separate_audio,
|
|
25
|
+
download_video,
|
|
26
|
+
create_empty_mkv_with_audio,
|
|
27
|
+
check_ffmpeg,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"__version__",
|
|
32
|
+
"main",
|
|
33
|
+
"STEM_MODES",
|
|
34
|
+
"DEFAULT_VIDEO_RESOLUTION",
|
|
35
|
+
"Spinner",
|
|
36
|
+
"parse_args",
|
|
37
|
+
"parse_time",
|
|
38
|
+
"format_time",
|
|
39
|
+
"remove_dir",
|
|
40
|
+
"clean",
|
|
41
|
+
"convert_wav_to_mp3",
|
|
42
|
+
"convert_to_mp3",
|
|
43
|
+
"separate_audio",
|
|
44
|
+
"download_video",
|
|
45
|
+
"create_empty_mkv_with_audio",
|
|
46
|
+
"check_ffmpeg",
|
|
47
|
+
]
|
demix/cli.py
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
"""Command-line interface for demix."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import subprocess
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import sys
|
|
8
|
+
import threading
|
|
9
|
+
import itertools
|
|
10
|
+
import time
|
|
11
|
+
from pytubefix import YouTube
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_version():
|
|
15
|
+
"""Get version from package metadata or fallback."""
|
|
16
|
+
try:
|
|
17
|
+
from demix import __version__
|
|
18
|
+
return __version__
|
|
19
|
+
except ImportError:
|
|
20
|
+
return "1.0.0"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
DEFAULT_VIDEO_RESOLUTION = "1280x720"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_time(time_str):
|
|
27
|
+
"""Parse time string in MM:SS or HH:MM:SS format to seconds."""
|
|
28
|
+
if time_str is None:
|
|
29
|
+
return None
|
|
30
|
+
parts = time_str.split(":")
|
|
31
|
+
if len(parts) == 2:
|
|
32
|
+
minutes, seconds = parts
|
|
33
|
+
return int(minutes) * 60 + float(seconds)
|
|
34
|
+
elif len(parts) == 3:
|
|
35
|
+
hours, minutes, seconds = parts
|
|
36
|
+
return int(hours) * 3600 + int(minutes) * 60 + float(seconds)
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError(f"Invalid time format: {time_str}. Use MM:SS or HH:MM:SS")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def format_time(seconds):
|
|
42
|
+
"""Format seconds to MM:SS or HH:MM:SS string."""
|
|
43
|
+
if seconds is None:
|
|
44
|
+
return None
|
|
45
|
+
hours = int(seconds // 3600)
|
|
46
|
+
minutes = int((seconds % 3600) // 60)
|
|
47
|
+
secs = seconds % 60
|
|
48
|
+
if hours > 0:
|
|
49
|
+
return f"{hours}:{minutes:02d}:{secs:05.2f}"
|
|
50
|
+
return f"{minutes}:{secs:05.2f}"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Spinner:
|
|
54
|
+
def __init__(self, message="Loading..."):
|
|
55
|
+
self.message = message
|
|
56
|
+
self.spinning = False
|
|
57
|
+
self.thread = None
|
|
58
|
+
self.spinner_chars = itertools.cycle(["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"])
|
|
59
|
+
|
|
60
|
+
def _spin(self):
|
|
61
|
+
while self.spinning:
|
|
62
|
+
char = next(self.spinner_chars)
|
|
63
|
+
sys.stdout.write(f"\r{char} {self.message}")
|
|
64
|
+
sys.stdout.flush()
|
|
65
|
+
time.sleep(0.1)
|
|
66
|
+
|
|
67
|
+
def start(self):
|
|
68
|
+
self.spinning = True
|
|
69
|
+
self.thread = threading.Thread(target=self._spin)
|
|
70
|
+
self.thread.start()
|
|
71
|
+
|
|
72
|
+
def stop(self, success=True):
|
|
73
|
+
self.spinning = False
|
|
74
|
+
if self.thread:
|
|
75
|
+
self.thread.join()
|
|
76
|
+
symbol = "\033[32m✓\033[0m" if success else "\033[31m✗\033[0m"
|
|
77
|
+
sys.stdout.write(f"\r{symbol} {self.message}\n")
|
|
78
|
+
sys.stdout.flush()
|
|
79
|
+
|
|
80
|
+
def __enter__(self):
|
|
81
|
+
self.start()
|
|
82
|
+
return self
|
|
83
|
+
|
|
84
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
85
|
+
self.stop(success=exc_type is None)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def check_ffmpeg():
|
|
89
|
+
"""Check if ffmpeg and ffprobe are installed and accessible."""
|
|
90
|
+
if shutil.which("ffmpeg") is None:
|
|
91
|
+
print("Error: ffmpeg is not installed or not found in PATH.")
|
|
92
|
+
print("Please install ffmpeg:")
|
|
93
|
+
print(" macOS: brew install ffmpeg")
|
|
94
|
+
print(" Ubuntu: sudo apt install ffmpeg")
|
|
95
|
+
print(" Windows: https://ffmpeg.org/download.html")
|
|
96
|
+
return False
|
|
97
|
+
if shutil.which("ffprobe") is None:
|
|
98
|
+
print("Error: ffprobe is not installed or not found in PATH.")
|
|
99
|
+
print("ffprobe is usually included with ffmpeg. Please reinstall ffmpeg.")
|
|
100
|
+
return False
|
|
101
|
+
return True
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def download_video(url, output_path):
|
|
105
|
+
os.makedirs(output_path, exist_ok=True)
|
|
106
|
+
yt = YouTube(url)
|
|
107
|
+
stream = yt.streams.filter(only_audio=True).order_by("abr").desc().first()
|
|
108
|
+
ext = stream.mime_type.split("/")[-1]
|
|
109
|
+
filename = f"video.{ext}"
|
|
110
|
+
stream.download(output_path=output_path, filename=filename)
|
|
111
|
+
return os.path.join(output_path, filename)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def convert_to_mp3(input_file, output_file, start_time=None, end_time=None):
|
|
115
|
+
cmd = ["ffmpeg"]
|
|
116
|
+
if start_time is not None:
|
|
117
|
+
cmd.extend(["-ss", str(start_time)])
|
|
118
|
+
if end_time is not None:
|
|
119
|
+
cmd.extend(["-to", str(end_time)])
|
|
120
|
+
cmd.extend(["-i", input_file, "-vn", "-ar", "44100", "-ac", "2", "-b:a", "192k", output_file])
|
|
121
|
+
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def convert_wav_to_mp3(input_file, output_file, tempo=1.0, transpose=0):
|
|
125
|
+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
|
126
|
+
cmd = ["ffmpeg", "-i", input_file]
|
|
127
|
+
filters = []
|
|
128
|
+
# Apply transpose (pitch shift) using rubberband filter
|
|
129
|
+
# Formula: pitch_ratio = 2^(semitones/12)
|
|
130
|
+
if transpose != 0:
|
|
131
|
+
pitch_ratio = 2 ** (transpose / 12)
|
|
132
|
+
filters.append(f"rubberband=pitch={pitch_ratio}")
|
|
133
|
+
# Apply tempo adjustment using atempo filter
|
|
134
|
+
if tempo != 1.0:
|
|
135
|
+
# atempo filter only accepts values between 0.5 and 2.0
|
|
136
|
+
# chain multiple filters for values outside this range
|
|
137
|
+
tempo_value = tempo
|
|
138
|
+
while tempo_value < 0.5:
|
|
139
|
+
filters.append("atempo=0.5")
|
|
140
|
+
tempo_value /= 0.5
|
|
141
|
+
while tempo_value > 2.0:
|
|
142
|
+
filters.append("atempo=2.0")
|
|
143
|
+
tempo_value /= 2.0
|
|
144
|
+
filters.append(f"atempo={tempo_value}")
|
|
145
|
+
if filters:
|
|
146
|
+
cmd.extend(["-af", ",".join(filters)])
|
|
147
|
+
cmd.extend(["-b:a", "192k", output_file])
|
|
148
|
+
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
STEM_MODES = {
|
|
152
|
+
"2stems": ["vocals", "accompaniment"],
|
|
153
|
+
"4stems": ["vocals", "drums", "bass", "other"],
|
|
154
|
+
"5stems": ["vocals", "drums", "bass", "piano", "other"],
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def separate_audio(mp3_file, output_folder, mode="2stems"):
|
|
159
|
+
subprocess.run([
|
|
160
|
+
"spleeter", "separate", "-p", f"spleeter:{mode}", "-o", output_folder, mp3_file
|
|
161
|
+
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def create_empty_mkv_with_audio(mp3_file, output_file):
|
|
165
|
+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
|
166
|
+
duration_cmd = [
|
|
167
|
+
"ffprobe", "-i", mp3_file, "-show_entries", "format=duration",
|
|
168
|
+
"-v", "quiet", "-of", "csv=p=0"
|
|
169
|
+
]
|
|
170
|
+
duration = subprocess.check_output(duration_cmd).decode().strip()
|
|
171
|
+
ffmpeg_cmd = [
|
|
172
|
+
"ffmpeg", "-f", "lavfi", "-i", f"color=c=black:s={DEFAULT_VIDEO_RESOLUTION}:d={duration}",
|
|
173
|
+
"-i", mp3_file, "-c:v", "libx264", "-c:a", "aac", "-strict", "experimental",
|
|
174
|
+
"-shortest", output_file
|
|
175
|
+
]
|
|
176
|
+
subprocess.run(ffmpeg_cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def remove_dir(path):
|
|
180
|
+
if os.path.exists(path):
|
|
181
|
+
shutil.rmtree(path)
|
|
182
|
+
print(f"Removed: {path}")
|
|
183
|
+
else:
|
|
184
|
+
print(f"Directory does not exist: {path}")
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def clean(target, output_dir="output"):
|
|
188
|
+
if target == "output":
|
|
189
|
+
remove_dir(output_dir)
|
|
190
|
+
elif target == "models":
|
|
191
|
+
remove_dir("pretrained_models")
|
|
192
|
+
elif target == "all":
|
|
193
|
+
remove_dir(output_dir)
|
|
194
|
+
remove_dir("pretrained_models")
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def parse_args():
|
|
198
|
+
# Custom formatter with wider help position for better readability
|
|
199
|
+
class WideHelpFormatter(argparse.RawDescriptionHelpFormatter):
|
|
200
|
+
def __init__(self, prog):
|
|
201
|
+
super().__init__(prog, max_help_position=40)
|
|
202
|
+
|
|
203
|
+
parser = argparse.ArgumentParser(
|
|
204
|
+
prog="demix",
|
|
205
|
+
description="Separate audio into stems (vocals, instruments) from a YouTube video or local audio file.",
|
|
206
|
+
epilog="Examples:\n"
|
|
207
|
+
" demix -u 'https://www.youtube.com/watch?v=VIDEO_ID' -m 4stems\n"
|
|
208
|
+
" demix -f /path/to/song.mp3 -m 2stems\n"
|
|
209
|
+
" demix -f song.mp3 -ss 1:30 -to 3:45 # cut from 1:30 to 3:45\n"
|
|
210
|
+
" demix -f song.mp3 -ss 0:30 # start from 0:30\n"
|
|
211
|
+
" demix -f song.mp3 -to 2:00 # cut first 2 minutes",
|
|
212
|
+
formatter_class=WideHelpFormatter
|
|
213
|
+
)
|
|
214
|
+
parser.add_argument(
|
|
215
|
+
"-u", "--url",
|
|
216
|
+
metavar="URL",
|
|
217
|
+
help="YouTube video URL to process"
|
|
218
|
+
)
|
|
219
|
+
parser.add_argument(
|
|
220
|
+
"-f", "--file",
|
|
221
|
+
metavar="FILE",
|
|
222
|
+
help="local audio file to process (mp3, wav, flac, etc.)"
|
|
223
|
+
)
|
|
224
|
+
parser.add_argument(
|
|
225
|
+
"-o", "--output",
|
|
226
|
+
default="output",
|
|
227
|
+
metavar="DIR",
|
|
228
|
+
help="output directory (default: output)"
|
|
229
|
+
)
|
|
230
|
+
parser.add_argument(
|
|
231
|
+
"-c", "--clean",
|
|
232
|
+
choices=["output", "models", "all"],
|
|
233
|
+
metavar="TARGET",
|
|
234
|
+
help="clean up files: output, models, or all"
|
|
235
|
+
)
|
|
236
|
+
parser.add_argument(
|
|
237
|
+
"-t", "--tempo",
|
|
238
|
+
type=float,
|
|
239
|
+
default=1.0,
|
|
240
|
+
metavar="FACTOR",
|
|
241
|
+
help="tempo factor for output audio (default: 1.0, use < 1.0 to slow down, e.g., 0.8 for 80%% tempo)"
|
|
242
|
+
)
|
|
243
|
+
parser.add_argument(
|
|
244
|
+
"-p", "--transpose",
|
|
245
|
+
type=int,
|
|
246
|
+
default=0,
|
|
247
|
+
metavar="SEMITONES",
|
|
248
|
+
help="transpose pitch by semitones (default: 0, range: -12 to +12, e.g., -5 for 5 semitones down)"
|
|
249
|
+
)
|
|
250
|
+
parser.add_argument(
|
|
251
|
+
"-ss", "--start",
|
|
252
|
+
metavar="TIME",
|
|
253
|
+
help="start time for cutting (format: MM:SS or HH:MM:SS, e.g., 1:30 for 1 min 30 sec)"
|
|
254
|
+
)
|
|
255
|
+
parser.add_argument(
|
|
256
|
+
"-to", "--end",
|
|
257
|
+
metavar="TIME",
|
|
258
|
+
help="end time for cutting (format: MM:SS or HH:MM:SS, e.g., 3:45 for 3 min 45 sec)"
|
|
259
|
+
)
|
|
260
|
+
parser.add_argument(
|
|
261
|
+
"-m", "--mode",
|
|
262
|
+
choices=["2stems", "4stems", "5stems"],
|
|
263
|
+
default="2stems",
|
|
264
|
+
metavar="MODE",
|
|
265
|
+
help="separation mode: 2stems (vocals/accompaniment), "
|
|
266
|
+
"4stems (vocals/drums/bass/other), "
|
|
267
|
+
"5stems (vocals/drums/bass/piano/other). "
|
|
268
|
+
"Default: 2stems"
|
|
269
|
+
)
|
|
270
|
+
parser.add_argument(
|
|
271
|
+
"-v", "--version",
|
|
272
|
+
action="version",
|
|
273
|
+
version=f"%(prog)s {get_version()}"
|
|
274
|
+
)
|
|
275
|
+
return parser.parse_args()
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def main():
|
|
279
|
+
args = parse_args()
|
|
280
|
+
|
|
281
|
+
if args.clean:
|
|
282
|
+
clean(args.clean, args.output)
|
|
283
|
+
return
|
|
284
|
+
|
|
285
|
+
if not check_ffmpeg():
|
|
286
|
+
return
|
|
287
|
+
|
|
288
|
+
if not args.url and not args.file:
|
|
289
|
+
print("Error: --url or --file is required when not using --clean")
|
|
290
|
+
print("Run with --help for usage information")
|
|
291
|
+
return
|
|
292
|
+
|
|
293
|
+
if args.url and args.file:
|
|
294
|
+
print("Error: --url and --file cannot be used together")
|
|
295
|
+
print("Run with --help for usage information")
|
|
296
|
+
return
|
|
297
|
+
|
|
298
|
+
if args.file and not os.path.isfile(args.file):
|
|
299
|
+
print(f"Error: File not found: {args.file}")
|
|
300
|
+
return
|
|
301
|
+
|
|
302
|
+
# Parse time cutting parameters
|
|
303
|
+
try:
|
|
304
|
+
start_time = parse_time(args.start)
|
|
305
|
+
end_time = parse_time(args.end)
|
|
306
|
+
except ValueError as e:
|
|
307
|
+
print(f"Error: {e}")
|
|
308
|
+
return
|
|
309
|
+
|
|
310
|
+
output_dir = args.output
|
|
311
|
+
tmp_dir = os.path.join(output_dir, "tmp")
|
|
312
|
+
music_dir = os.path.join(output_dir, "music")
|
|
313
|
+
mp3_dir = os.path.join(music_dir, "mp3")
|
|
314
|
+
video_dir = os.path.join(output_dir, "video")
|
|
315
|
+
|
|
316
|
+
mode = args.mode
|
|
317
|
+
stems = STEM_MODES[mode]
|
|
318
|
+
|
|
319
|
+
source = args.url if args.url else args.file
|
|
320
|
+
print(f"Processing: {source}")
|
|
321
|
+
print(f"Output directory: {output_dir}")
|
|
322
|
+
print(f"Separation mode: {mode} ({', '.join(stems)})")
|
|
323
|
+
if start_time is not None or end_time is not None:
|
|
324
|
+
cut_info = "Cutting: "
|
|
325
|
+
if start_time is not None:
|
|
326
|
+
cut_info += f"from {args.start}"
|
|
327
|
+
if end_time is not None:
|
|
328
|
+
cut_info += f" to {args.end}" if start_time else f"to {args.end}"
|
|
329
|
+
print(cut_info)
|
|
330
|
+
print()
|
|
331
|
+
|
|
332
|
+
remove_dir(output_dir)
|
|
333
|
+
|
|
334
|
+
mp3_file = os.path.join(tmp_dir, "music.mp3")
|
|
335
|
+
|
|
336
|
+
cut_msg = " and cutting" if start_time is not None or end_time is not None else ""
|
|
337
|
+
if args.url:
|
|
338
|
+
with Spinner("Downloading video..."):
|
|
339
|
+
video_file = download_video(args.url, tmp_dir)
|
|
340
|
+
|
|
341
|
+
with Spinner(f"Converting to MP3{cut_msg}..."):
|
|
342
|
+
convert_to_mp3(video_file, mp3_file, start_time, end_time)
|
|
343
|
+
else:
|
|
344
|
+
with Spinner(f"Converting audio file to MP3{cut_msg}..."):
|
|
345
|
+
os.makedirs(tmp_dir, exist_ok=True)
|
|
346
|
+
convert_to_mp3(args.file, mp3_file, start_time, end_time)
|
|
347
|
+
|
|
348
|
+
first_run = not os.path.exists("pretrained_models")
|
|
349
|
+
if first_run:
|
|
350
|
+
print("\033[33mℹ\033[0m First run detected - Spleeter models will be downloaded (~300MB).")
|
|
351
|
+
print(" This is a one-time operation (unless you delete models with --clean models).")
|
|
352
|
+
print(" Subsequent operations will be faster.\n")
|
|
353
|
+
|
|
354
|
+
with Spinner(f"Separating audio ({mode})..."):
|
|
355
|
+
separate_audio(mp3_file, output_dir, mode)
|
|
356
|
+
|
|
357
|
+
convert_msg = "Converting separated tracks to MP3..."
|
|
358
|
+
effects = []
|
|
359
|
+
if args.tempo != 1.0:
|
|
360
|
+
effects.append(f"tempo: {args.tempo}x")
|
|
361
|
+
if args.transpose != 0:
|
|
362
|
+
sign = "+" if args.transpose > 0 else ""
|
|
363
|
+
effects.append(f"transpose: {sign}{args.transpose} semitones")
|
|
364
|
+
if effects:
|
|
365
|
+
convert_msg = f"Converting separated tracks to MP3 ({', '.join(effects)})..."
|
|
366
|
+
with Spinner(convert_msg):
|
|
367
|
+
for stem in stems:
|
|
368
|
+
convert_wav_to_mp3(
|
|
369
|
+
os.path.join(music_dir, f"{stem}.wav"),
|
|
370
|
+
os.path.join(mp3_dir, f"{stem}.mp3"),
|
|
371
|
+
args.tempo,
|
|
372
|
+
args.transpose
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
# Create video only for 2stems mode (accompaniment = complete music without vocals)
|
|
376
|
+
if mode == "2stems":
|
|
377
|
+
with Spinner("Creating video for accompaniment track..."):
|
|
378
|
+
create_empty_mkv_with_audio(
|
|
379
|
+
os.path.join(mp3_dir, "accompaniment.mp3"),
|
|
380
|
+
os.path.join(video_dir, "accompaniment.mkv"),
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
print(f"\n\033[32m✓\033[0m Done! Check the '{output_dir}/' directory for results.")
|
|
384
|
+
print(f" Separated stems: {', '.join(stems)}")
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
if __name__ == "__main__":
|
|
388
|
+
main()
|
demix/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: demix
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Separate audio into stems (vocals, instruments) using AI-powered Spleeter
|
|
5
|
+
Author: pwittchen
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/pwittchen/demix
|
|
8
|
+
Project-URL: Repository, https://github.com/pwittchen/demix
|
|
9
|
+
Project-URL: Issues, https://github.com/pwittchen/demix/issues
|
|
10
|
+
Keywords: audio,music,stem-separation,vocals,spleeter,youtube,ffmpeg
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
|
|
21
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Conversion
|
|
22
|
+
Requires-Python: <3.9,>=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: pytubefix>=9.3.0
|
|
26
|
+
Requires-Dist: ffmpeg>=1.4
|
|
27
|
+
Requires-Dist: spleeter>=2.3.2
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Requires-Dist: flake8>=5.0; extra == "dev"
|
|
31
|
+
|
|
32
|
+
# demix
|
|
33
|
+
|
|
34
|
+
separates audio from songs into stems (vocals, instruments)
|
|
35
|
+
|
|
36
|
+
## installation
|
|
37
|
+
|
|
38
|
+
I suggest to create virtualenv for this project to not break system-wide packages installations (replace python path below with your own python3.8 path):
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
brew install virtualenvwrapper
|
|
42
|
+
brew install ffmpeg
|
|
43
|
+
mkvirtualenv -p /Users/pw/.pyenv/versions/3.8.16/bin/python demix
|
|
44
|
+
workon demix
|
|
45
|
+
pip install demix
|
|
46
|
+
demix -v
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Please note: I'm using homebrew for installing `virtualenvwrapper` and `ffmpeg`.
|
|
50
|
+
If you're using another package manager or different operating system than macOS (e.g. Linux), you need to install it differently.
|
|
51
|
+
|
|
52
|
+
## development
|
|
53
|
+
|
|
54
|
+
prepare environment (replace python path below with your own python3.8 path):
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
brew install virtualenvwrapper
|
|
58
|
+
brew install ffmpeg
|
|
59
|
+
mkvirtualenv -p /Users/pw/.pyenv/versions/3.8.16/bin/python demix
|
|
60
|
+
workon demix
|
|
61
|
+
pip install -r requirements.txt
|
|
62
|
+
python demix.py -v
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Please note: I'm using homebrew for installing `virtualenvwrapper` and `ffmpeg`.
|
|
66
|
+
If you're using another package manager or different operating system than macOS (e.g. Linux), you need to install it differently.
|
|
67
|
+
|
|
68
|
+
exit virtualenv, when you're done:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
deactivate
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
to activate env again:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
workon demix
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## testing
|
|
81
|
+
|
|
82
|
+
install pytest:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
pip install pytest
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
run all tests (`-v` param for verbose):
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
pytest -v
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## usage
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
python demix.py -u <youtube-url> [options]
|
|
98
|
+
python demix.py -f <audio-file> [options]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### options
|
|
102
|
+
|
|
103
|
+
| Option | Description |
|
|
104
|
+
|--------|-------------|
|
|
105
|
+
| `-u`, `--url` | YouTube video URL to process |
|
|
106
|
+
| `-f`, `--file` | Local audio file to process (mp3, wav, flac, etc.) |
|
|
107
|
+
| `-o`, `--output` | Output directory (default: `output`) |
|
|
108
|
+
| `-t`, `--tempo` | Tempo factor for output audio (default: `1.0`, use `< 1.0` to slow down) |
|
|
109
|
+
| `-p`, `--transpose` | Transpose pitch by semitones (default: `0`, range: `-12` to `+12`) |
|
|
110
|
+
| `-ss`, `--start` | Start time for cutting (format: `MM:SS` or `HH:MM:SS`) |
|
|
111
|
+
| `-to`, `--end` | End time for cutting (format: `MM:SS` or `HH:MM:SS`) |
|
|
112
|
+
| `-m`, `--mode` | Separation mode: `2stems`, `4stems`, or `5stems` (default: `2stems`) |
|
|
113
|
+
| `-c`, `--clean` | Clean up files: `output`, `models`, or `all` |
|
|
114
|
+
| `-v`, `--version` | Show version number |
|
|
115
|
+
| `-h`, `--help` | Show help message |
|
|
116
|
+
|
|
117
|
+
### separation modes
|
|
118
|
+
|
|
119
|
+
| Mode | Stems |
|
|
120
|
+
|------|-------|
|
|
121
|
+
| `2stems` | vocals, accompaniment |
|
|
122
|
+
| `4stems` | vocals, drums, bass, other |
|
|
123
|
+
| `5stems` | vocals, drums, bass, piano, other |
|
|
124
|
+
|
|
125
|
+
### examples
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# separate a YouTube video into vocals and accompaniment
|
|
129
|
+
demix -u 'https://www.youtube.com/watch?v=VIDEO_ID'
|
|
130
|
+
|
|
131
|
+
# separate a local file with 4 stems
|
|
132
|
+
demix -f /path/to/song.mp3 -m 4stems
|
|
133
|
+
|
|
134
|
+
# cut audio from 1:30 to 3:45 before separation
|
|
135
|
+
demix -f song.mp3 -ss 1:30 -to 3:45
|
|
136
|
+
|
|
137
|
+
# start from 0:30 (skip intro)
|
|
138
|
+
demix -f song.mp3 -ss 0:30
|
|
139
|
+
|
|
140
|
+
# keep only the first 2 minutes
|
|
141
|
+
demix -f song.mp3 -to 2:00
|
|
142
|
+
|
|
143
|
+
# combine cutting with tempo and transpose
|
|
144
|
+
demix -f song.mp3 -ss 1:00 -to 4:00 -t 0.8 -p -2
|
|
145
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
demix/__init__.py,sha256=L8aIfLMABC6x4xIuyI7KUu6pl9HqMnVvKnb08tcJVK0,969
|
|
2
|
+
demix/cli.py,sha256=Sbd_z7DPsnWfvZ-VAXQxF_6Vqddep3N0VDCH0ndHBXQ,13064
|
|
3
|
+
demix/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
demix-1.0.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
demix-1.0.1.dist-info/METADATA,sha256=pqztUYbZpGCn2ZBcXtRHM1213JOnCKXQbHTJGeAt5QE,4214
|
|
6
|
+
demix-1.0.1.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
7
|
+
demix-1.0.1.dist-info/entry_points.txt,sha256=O-hFakFnVvSVELrJZVRUoQuBF7JhXPUyo6Dpv07AxL8,41
|
|
8
|
+
demix-1.0.1.dist-info/top_level.txt,sha256=HmMaqKfpvWDr8l9g9G3go6ULBhOcvfhh4lzKfVAxTM8,6
|
|
9
|
+
demix-1.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
demix
|