r3gm commited on
Commit
5235eee
·
verified ·
1 Parent(s): 23d65ab

Update src/main.py

Browse files
Files changed (1) hide show
  1. src/main.py +24 -20
src/main.py CHANGED
@@ -298,7 +298,7 @@ def combine_audio(audio_paths, output_path, main_gain, backup_gain, inst_gain, o
298
 
299
 
300
  # @spaces.GPU(enable_queue=True, duration=130)
301
- @spaces.GPU(duration=59)
302
  def process_song(
303
  song_dir, song_input, mdx_model_params, song_id, is_webui, input_type, progress,
304
  keep_files, pitch_change, pitch_change_all, voice_model, index_rate, filter_radius,
@@ -318,6 +318,24 @@ def process_song(
318
  else:
319
  orig_song_path, instrumentals_path, main_vocals_dereverb_path, backup_vocals_path = paths
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  pitch_change = pitch_change * 12 + pitch_change_all
322
  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}"}_s{steps}.wav')
323
  ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')
@@ -326,7 +344,7 @@ def process_song(
326
  display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
327
  voice_change(voice_model, main_vocals_dereverb_path, ai_vocals_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui, steps)
328
 
329
- return ai_vocals_path, ai_cover_path, instrumentals_path, backup_vocals_path, vocals_path, main_vocals_path
330
 
331
 
332
  def apply_noisereduce(audio_list, type_output="wav"):
@@ -420,7 +438,8 @@ def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
420
  instrumentals_path,
421
  backup_vocals_path,
422
  vocals_path,
423
- main_vocals_path
 
424
  ) = process_song(
425
  song_dir,
426
  song_input,
@@ -458,21 +477,6 @@ def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
458
  ai_vocals_path = apply_noisereduce([ai_vocals_path])[0]
459
 
460
  ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)
461
-
462
- ins_path = get_audio_with_suffix(song_dir, "_Voiceless.wav")
463
- if not ins_path:
464
- instrumentals_path, _ = run_mdx(
465
- mdx_model_params,
466
- os.path.join(output_dir, song_id),
467
- os.path.join(mdxnet_models_dir, "UVR-MDX-NET-Inst_HQ_4.onnx"),
468
- instrumentals_path,
469
- # exclude_main=False,
470
- exclude_inversion=True,
471
- suffix="Voiceless",
472
- denoise=False,
473
- keep_orig=True,
474
- base_device=("" if IS_ZERO_GPU else "cuda")
475
- )
476
 
477
  if pitch_change_all != 0:
478
  display_progress('[~] Applying overall pitch change', 0.85, is_webui, progress)
@@ -484,11 +488,11 @@ def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
484
 
485
  if not keep_files:
486
  display_progress('[~] Removing intermediate audio files...', 0.95, is_webui, progress)
487
- intermediate_files = [vocals_path, main_vocals_path, ai_vocals_mixed_path, ins_path, nr_path]
488
  if pitch_change_all != 0:
489
  intermediate_files += [instrumentals_path, backup_vocals_path]
490
  for file in intermediate_files:
491
- if file and os.path.exists(file):
492
  os.remove(file)
493
 
494
  return ai_cover_path
 
298
 
299
 
300
  # @spaces.GPU(enable_queue=True, duration=130)
301
+ @spaces.GPU(duration=65)
302
  def process_song(
303
  song_dir, song_input, mdx_model_params, song_id, is_webui, input_type, progress,
304
  keep_files, pitch_change, pitch_change_all, voice_model, index_rate, filter_radius,
 
318
  else:
319
  orig_song_path, instrumentals_path, main_vocals_dereverb_path, backup_vocals_path = paths
320
 
321
+ ins_path = get_audio_with_suffix(song_dir, "_Voiceless.wav")
322
+ if not ins_path:
323
+ display_progress('[~] Extracting voiceless track...', 0.4, is_webui, progress)
324
+ instrumentals_path, _ = run_mdx(
325
+ mdx_model_params,
326
+ song_dir,
327
+ os.path.join(mdxnet_models_dir, "UVR-MDX-NET-Inst_HQ_4.onnx"),
328
+ instrumentals_path,
329
+ exclude_inversion=True,
330
+ suffix="Voiceless",
331
+ denoise=False,
332
+ keep_orig=True,
333
+ base_device=("cuda" if IS_ZERO_GPU else "")
334
+ )
335
+ ins_path = get_audio_with_suffix(song_dir, "_Voiceless.wav")
336
+ else:
337
+ instrumentals_path = ins_path
338
+
339
  pitch_change = pitch_change * 12 + pitch_change_all
340
  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}"}_s{steps}.wav')
341
  ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')
 
344
  display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
345
  voice_change(voice_model, main_vocals_dereverb_path, ai_vocals_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui, steps)
346
 
347
+ return ai_vocals_path, ai_cover_path, instrumentals_path, backup_vocals_path, vocals_path, main_vocals_path, ins_path
348
 
349
 
350
  def apply_noisereduce(audio_list, type_output="wav"):
 
438
  instrumentals_path,
439
  backup_vocals_path,
440
  vocals_path,
441
+ main_vocals_path,
442
+ ins_path
443
  ) = process_song(
444
  song_dir,
445
  song_input,
 
477
  ai_vocals_path = apply_noisereduce([ai_vocals_path])[0]
478
 
479
  ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
 
481
  if pitch_change_all != 0:
482
  display_progress('[~] Applying overall pitch change', 0.85, is_webui, progress)
 
488
 
489
  if not keep_files:
490
  display_progress('[~] Removing intermediate audio files...', 0.95, is_webui, progress)
491
+ intermediate_files = [vocals_path, main_vocals_path, ai_vocals_mixed_path, nr_path]
492
  if pitch_change_all != 0:
493
  intermediate_files += [instrumentals_path, backup_vocals_path]
494
  for file in intermediate_files:
495
+ if file and os.path.exists(file) and file != ins_path:
496
  os.remove(file)
497
 
498
  return ai_cover_path