Spaces:
Sleeping
Sleeping
helloWorld199
commited on
Upload 2 files
Browse files- src/main.py +15 -11
- src/mdx.py +6 -6
src/main.py
CHANGED
@@ -181,7 +181,7 @@ def preprocess_song(song_input, mdx_model_params, song_id, is_webui, input_type,
|
|
181 |
orig_song_path = convert_to_stereo(orig_song_path)
|
182 |
|
183 |
display_progress('[~] Separating Vocals from Instrumental...', 0.1, is_webui, progress)
|
184 |
-
vocals_path, instrumentals_path = run_mdx(mdx_model_params, song_output_dir, os.path.join(mdxnet_models_dir, 'UVR-MDX-NET-Voc_FT.onnx'), orig_song_path, denoise=True, keep_orig=keep_orig
|
185 |
|
186 |
display_progress('[~] Separating Main Vocals from Backup Vocals...', 0.2, is_webui, progress)
|
187 |
backup_vocals_path, main_vocals_path = run_mdx(mdx_model_params, song_output_dir, os.path.join(mdxnet_models_dir, 'UVR_MDXNET_KARA_2.onnx'), vocals_path, suffix='Backup', invert_suffix='Main', denoise=True)
|
@@ -217,7 +217,7 @@ def voice_change(voice_model, vocals_path, output_path, pitch_change, f0_method,
|
|
217 |
|
218 |
|
219 |
def add_audio_effects(audio_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping):
|
220 |
-
output_path = f'{os.path.splitext(audio_path)[0]}
|
221 |
|
222 |
# Initialize audio effects plugins
|
223 |
board = Pedalboard(
|
@@ -336,7 +336,7 @@ def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
|
|
336 |
|
337 |
pitch_change = pitch_change * 12 + pitch_change_all
|
338 |
ai_vocals_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]}_{voice_model}_p{pitch_change}_i{index_rate}_fr{filter_radius}_rms{rms_mix_rate}_pro{protect}_{f0_method}{"" if f0_method != "mangio-crepe" else f"_{crepe_hop_length}"}.wav')
|
339 |
-
ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver)
|
340 |
|
341 |
if not os.path.exists(ai_vocals_path):
|
342 |
display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
|
@@ -363,14 +363,18 @@ def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
|
|
363 |
os.remove(file)
|
364 |
|
365 |
# Add _stemname to each stem
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
display_progress(f'[~]
|
371 |
-
time.sleep(5)
|
372 |
-
|
373 |
-
|
|
|
|
|
|
|
|
|
374 |
|
375 |
# Returning the stems: AI cover, original vocal, original instrumental, AI generated vocal
|
376 |
|
|
|
181 |
orig_song_path = convert_to_stereo(orig_song_path)
|
182 |
|
183 |
display_progress('[~] Separating Vocals from Instrumental...', 0.1, is_webui, progress)
|
184 |
+
vocals_path, instrumentals_path = run_mdx(mdx_model_params, song_output_dir, os.path.join(mdxnet_models_dir, 'UVR-MDX-NET-Voc_FT.onnx'), orig_song_path, denoise=True, keep_orig=keep_orig)
|
185 |
|
186 |
display_progress('[~] Separating Main Vocals from Backup Vocals...', 0.2, is_webui, progress)
|
187 |
backup_vocals_path, main_vocals_path = run_mdx(mdx_model_params, song_output_dir, os.path.join(mdxnet_models_dir, 'UVR_MDXNET_KARA_2.onnx'), vocals_path, suffix='Backup', invert_suffix='Main', denoise=True)
|
|
|
217 |
|
218 |
|
219 |
def add_audio_effects(audio_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping):
|
220 |
+
output_path = f'{os.path.splitext(audio_path)[0]}_mixed.wav'
|
221 |
|
222 |
# Initialize audio effects plugins
|
223 |
board = Pedalboard(
|
|
|
336 |
|
337 |
pitch_change = pitch_change * 12 + pitch_change_all
|
338 |
ai_vocals_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]}_{voice_model}_p{pitch_change}_i{index_rate}_fr{filter_radius}_rms{rms_mix_rate}_pro{protect}_{f0_method}{"" if f0_method != "mangio-crepe" else f"_{crepe_hop_length}"}.wav')
|
339 |
+
ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')
|
340 |
|
341 |
if not os.path.exists(ai_vocals_path):
|
342 |
display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
|
|
|
363 |
os.remove(file)
|
364 |
|
365 |
# Add _stemname to each stem
|
366 |
+
#ai_cover_path = add_stem_name(ai_cover_path, "_cover")
|
367 |
+
#display_progress(f'[~] ai_cover_path FINAL PATH {ai_cover_path}', 0.9, is_webui, progress)
|
368 |
+
#time.sleep(5)
|
369 |
+
#vocals_path = add_stem_name(vocals_path, "_origvocals")
|
370 |
+
#display_progress(f'[~] vocals_path FINAL PATH {vocals_path}', 0.9, is_webui, progress)
|
371 |
+
#time.sleep(5)
|
372 |
+
#instrumentals_path = add_stem_name(instrumentals_path, "_originstr")
|
373 |
+
#display_progress(f'[~] instrumentals_path FINAL PATH {instrumentals_path}', 0.9, is_webui, progress)
|
374 |
+
#time.sleep(5)
|
375 |
+
#ai_vocals_mixed_path = add_stem_name(ai_vocals_mixed_path, "_covervocals")
|
376 |
+
#display_progress(f'[~] ai_vocals_mixed_path FINAL PATH {ai_vocals_mixed_path}', 0.9, is_webui, progress)
|
377 |
+
#time.sleep(5)
|
378 |
|
379 |
# Returning the stems: AI cover, original vocal, original instrumental, AI generated vocal
|
380 |
|
src/mdx.py
CHANGED
@@ -239,11 +239,12 @@ class MDX:
|
|
239 |
return self.segment(processed_batches, True, chunk)
|
240 |
|
241 |
|
242 |
-
def run_mdx(model_params, output_dir, model_path, filename, exclude_main=False, exclude_inversion=False, suffix=None, invert_suffix=None, denoise=False, keep_orig=True, m_threads=2
|
243 |
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
|
244 |
|
245 |
-
device_properties = torch.cuda.get_device_properties(device)
|
246 |
-
|
|
|
247 |
m_threads = 1 if vram_gb < 8 else 2
|
248 |
|
249 |
model_hash = MDX.get_hash(model_path)
|
@@ -273,14 +274,14 @@ def run_mdx(model_params, output_dir, model_path, filename, exclude_main=False,
|
|
273 |
|
274 |
main_filepath = None
|
275 |
if not exclude_main:
|
276 |
-
main_filepath = os.path.join(output_dir, f"{os.path.basename(os.path.splitext(filename)[0])}_{stem_name}
|
277 |
sf.write(main_filepath, wave_processed.T, sr)
|
278 |
|
279 |
invert_filepath = None
|
280 |
if not exclude_inversion:
|
281 |
diff_stem_name = stem_naming.get(stem_name) if invert_suffix is None else invert_suffix
|
282 |
stem_name = f"{stem_name}_diff" if diff_stem_name is None else diff_stem_name
|
283 |
-
invert_filepath = os.path.join(output_dir, f"{os.path.basename(os.path.splitext(filename)[0])}_{stem_name}
|
284 |
sf.write(invert_filepath, (-wave_processed.T * model.compensation) + wave.T, sr)
|
285 |
|
286 |
if not keep_orig:
|
@@ -289,4 +290,3 @@ def run_mdx(model_params, output_dir, model_path, filename, exclude_main=False,
|
|
289 |
del mdx_sess, wave_processed, wave
|
290 |
gc.collect()
|
291 |
return main_filepath, invert_filepath
|
292 |
-
|
|
|
239 |
return self.segment(processed_batches, True, chunk)
|
240 |
|
241 |
|
242 |
+
def run_mdx(model_params, output_dir, model_path, filename, exclude_main=False, exclude_inversion=False, suffix=None, invert_suffix=None, denoise=False, keep_orig=True, m_threads=2):
|
243 |
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
|
244 |
|
245 |
+
#device_properties = torch.cuda.get_device_properties(device)
|
246 |
+
print("Device", device)
|
247 |
+
vram_gb = 12 #device_properties.total_memory / 1024**3
|
248 |
m_threads = 1 if vram_gb < 8 else 2
|
249 |
|
250 |
model_hash = MDX.get_hash(model_path)
|
|
|
274 |
|
275 |
main_filepath = None
|
276 |
if not exclude_main:
|
277 |
+
main_filepath = os.path.join(output_dir, f"{os.path.basename(os.path.splitext(filename)[0])}_{stem_name}.wav")
|
278 |
sf.write(main_filepath, wave_processed.T, sr)
|
279 |
|
280 |
invert_filepath = None
|
281 |
if not exclude_inversion:
|
282 |
diff_stem_name = stem_naming.get(stem_name) if invert_suffix is None else invert_suffix
|
283 |
stem_name = f"{stem_name}_diff" if diff_stem_name is None else diff_stem_name
|
284 |
+
invert_filepath = os.path.join(output_dir, f"{os.path.basename(os.path.splitext(filename)[0])}_{stem_name}.wav")
|
285 |
sf.write(invert_filepath, (-wave_processed.T * model.compensation) + wave.T, sr)
|
286 |
|
287 |
if not keep_orig:
|
|
|
290 |
del mdx_sess, wave_processed, wave
|
291 |
gc.collect()
|
292 |
return main_filepath, invert_filepath
|
|