helloWorld199 commited on
Commit
75afec6
1 Parent(s): 9cab93c

handle whatever zip model structure given in input

Browse files
Files changed (1) hide show
  1. src/main.py +24 -15
src/main.py CHANGED
@@ -90,12 +90,20 @@ def raise_exception(error_msg, is_webui):
90
  def get_rvc_model(voice_model, is_webui):
91
  rvc_model_filename, rvc_index_filename = None, None
92
  model_dir = os.path.join(rvc_models_dir, voice_model)
93
- for file in os.listdir(model_dir):
94
- ext = os.path.splitext(file)[1]
95
- if ext == '.pth':
96
- rvc_model_filename = file
97
- if ext == '.index':
98
- rvc_index_filename = file
 
 
 
 
 
 
 
 
99
 
100
  if rvc_model_filename is None:
101
  error_msg = f'No model file exists in {model_dir}.'
@@ -259,7 +267,7 @@ def combine_audio(audio_paths, output_path, main_gain, backup_gain, inst_gain, o
259
 
260
  # song_input is the main vocals that is going through the rvc processs
261
  # backup vocals are the backup vocals to be added at the end
262
- def song_cover_pipeline(main_vocals, backup_vocals, voice_model, pitch_change, keep_files,
263
  is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
264
  rms_mix_rate=1, f0_method='rmvpe', crepe_hop_length=128, protect=0.33, pitch_change_all=0,
265
  reverb_rm_size=0.15, reverb_wet=0.2, reverb_dry=0.8, reverb_damping=0.7, output_format='mp3',
@@ -293,8 +301,8 @@ def song_cover_pipeline(main_vocals, backup_vocals, voice_model, pitch_change, k
293
  os.makedirs(song_dir)
294
 
295
  pitch_change = pitch_change * 12 + pitch_change_all
296
- ai_vocals_path = os.path.join(song_dir, f'{os.path.basename(os.path.splitext(main_vocals)[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')
297
- ai_cover_path = os.path.join(song_dir, f'{os.path.basename(os.path.splitext(main_vocals)[0])}({voice_model} Ver)_cover.{output_format}')
298
 
299
  print(f"DEBUG PRINT: ai_vocals_path: {ai_vocals_path}, ai_cover_path: {ai_cover_path}")
300
 
@@ -330,13 +338,14 @@ def song_cover_pipeline(main_vocals, backup_vocals, voice_model, pitch_change, k
330
 
331
  if __name__ == '__main__':
332
  parser = argparse.ArgumentParser(description='Generate a AI cover song in the song_output/id directory.', add_help=True)
333
- parser.add_argument('-i', '--song-input', type=str, required=True, help='Link to a YouTube video or the filepath to a local mp3/wav file to create an AI cover of')
334
- parser.add_argument('-dir', '--rvc-dirname', type=str, required=True, help='Name of the folder in the rvc_models directory containing the RVC model file and optional index file to use')
335
- parser.add_argument('-p', '--pitch-change', type=int, required=True, help='Change the pitch of AI Vocals only. Generally, use 1 for male to female and -1 for vice-versa. (Octaves)')
336
- parser.add_argument('-k', '--keep-files', action=argparse.BooleanOptionalAction, help='Whether to keep all intermediate audio files generated in the song_output/id directory, e.g. Isolated Vocals/Instrumentals')
 
337
  parser.add_argument('-ir', '--index-rate', type=float, default=0.5, help='A decimal number e.g. 0.5, used to reduce/resolve the timbre leakage problem. If set to 1, more biased towards the timbre quality of the training dataset')
338
  parser.add_argument('-fr', '--filter-radius', type=int, default=3, help='A number between 0 and 7. If >=3: apply median filtering to the harvested pitch results. The value represents the filter radius and can reduce breathiness.')
339
- parser.add_argument('-rms', '--rms-mix-rate', type=float, default=0.25, help="A decimal number e.g. 0.25. Control how much to use the original vocal's loudness (0) or a fixed loudness (1).")
340
  parser.add_argument('-palgo', '--pitch-detection-algo', type=str, default='rmvpe', help='Best option is rmvpe (clarity in vocals), then mangio-crepe (smoother vocals).')
341
  parser.add_argument('-hop', '--crepe-hop-length', type=int, default=128, help='If pitch detection algo is mangio-crepe, controls how often it checks for pitch changes in milliseconds. The higher the value, the faster the conversion and less risk of voice cracks, but there is less pitch accuracy. Recommended: 128.')
342
  parser.add_argument('-pro', '--protect', type=float, default=0.33, help='A decimal number e.g. 0.33. Protect voiceless consonants and breath sounds to prevent artifacts such as tearing in electronic music. Set to 0.5 to disable. Decrease the value to increase protection, but it may reduce indexing accuracy.')
@@ -355,7 +364,7 @@ if __name__ == '__main__':
355
  if not os.path.exists(os.path.join(rvc_models_dir, rvc_dirname)):
356
  raise Exception(f'The folder {os.path.join(rvc_models_dir, rvc_dirname)} does not exist.')
357
 
358
- cover_path = song_cover_pipeline(args.song_input, rvc_dirname, args.pitch_change, args.keep_files,
359
  main_gain=args.main_vol, backup_gain=args.backup_vol, inst_gain=args.inst_vol,
360
  index_rate=args.index_rate, filter_radius=args.filter_radius,
361
  rms_mix_rate=args.rms_mix_rate, f0_method=args.pitch_detection_algo,
 
90
  def get_rvc_model(voice_model, is_webui):
91
  rvc_model_filename, rvc_index_filename = None, None
92
  model_dir = os.path.join(rvc_models_dir, voice_model)
93
+ #for file in os.listdir(model_dir):
94
+ # ext = os.path.splitext(file)[1]
95
+ # if ext == '.pth':
96
+ # rvc_model_filename = file
97
+ # if ext == '.index':
98
+ # rvc_index_filename = file
99
+
100
+ for root, dirs, files in os.walk(model_dir):
101
+ # Iterate over the files in the current directory
102
+ for file in files:
103
+ # Check if the file has a .pth extension
104
+ if file.endswith('.pth'):
105
+ # Append the full path of the file to the list
106
+ rvc_model_filename = os.path.join(root, file)
107
 
108
  if rvc_model_filename is None:
109
  error_msg = f'No model file exists in {model_dir}.'
 
267
 
268
  # song_input is the main vocals that is going through the rvc processs
269
  # backup vocals are the backup vocals to be added at the end
270
+ def song_cover_pipeline(main_vocals, backup_vocals, voice_model, pitch_change,
271
  is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
272
  rms_mix_rate=1, f0_method='rmvpe', crepe_hop_length=128, protect=0.33, pitch_change_all=0,
273
  reverb_rm_size=0.15, reverb_wet=0.2, reverb_dry=0.8, reverb_damping=0.7, output_format='mp3',
 
301
  os.makedirs(song_dir)
302
 
303
  pitch_change = pitch_change * 12 + pitch_change_all
304
+ ai_vocals_path = os.path.join(song_dir, f'{os.path.basename(os.path.splitext(main_vocals)[0])}_{os.path.basename(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')
305
+ ai_cover_path = os.path.join(song_dir, f'{os.path.basename(os.path.splitext(main_vocals)[0])}({os.path.basename(voice_model)} Ver)_cover.{output_format}')
306
 
307
  print(f"DEBUG PRINT: ai_vocals_path: {ai_vocals_path}, ai_cover_path: {ai_cover_path}")
308
 
 
338
 
339
  if __name__ == '__main__':
340
  parser = argparse.ArgumentParser(description='Generate a AI cover song in the song_output/id directory.', add_help=True)
341
+ parser.add_argument('-main_v', '--main-v', type=str, default= "spongebob.wav", required=False, help='Link to a YouTube video or the filepath to a local mp3/wav file to create an AI cover of')
342
+ parser.add_argument('-backup_v', '--backup-v', type=str, default="", required=False,
343
+ help='Link to a YouTube video or the filepath to a local mp3/wav file to create an AI cover of')
344
+ parser.add_argument('-dir', '--rvc-dirname', type=str, default = "plankton", required=False, help='Name of the folder in the rvc_models directory containing the RVC model file and optional index file to use')
345
+ parser.add_argument('-p', '--pitch-change', type=int, required=False, default=0, help='Change the pitch of AI Vocals only. Generally, use 1 for male to female and -1 for vice-versa. (Octaves)')
346
  parser.add_argument('-ir', '--index-rate', type=float, default=0.5, help='A decimal number e.g. 0.5, used to reduce/resolve the timbre leakage problem. If set to 1, more biased towards the timbre quality of the training dataset')
347
  parser.add_argument('-fr', '--filter-radius', type=int, default=3, help='A number between 0 and 7. If >=3: apply median filtering to the harvested pitch results. The value represents the filter radius and can reduce breathiness.')
348
+ parser.add_argument('-rms', '--rms-mix-rate', type=float, default=0, help="A decimal number e.g. 0.25. Control how much to use the original vocal's loudness (0) or a fixed loudness (1).")
349
  parser.add_argument('-palgo', '--pitch-detection-algo', type=str, default='rmvpe', help='Best option is rmvpe (clarity in vocals), then mangio-crepe (smoother vocals).')
350
  parser.add_argument('-hop', '--crepe-hop-length', type=int, default=128, help='If pitch detection algo is mangio-crepe, controls how often it checks for pitch changes in milliseconds. The higher the value, the faster the conversion and less risk of voice cracks, but there is less pitch accuracy. Recommended: 128.')
351
  parser.add_argument('-pro', '--protect', type=float, default=0.33, help='A decimal number e.g. 0.33. Protect voiceless consonants and breath sounds to prevent artifacts such as tearing in electronic music. Set to 0.5 to disable. Decrease the value to increase protection, but it may reduce indexing accuracy.')
 
364
  if not os.path.exists(os.path.join(rvc_models_dir, rvc_dirname)):
365
  raise Exception(f'The folder {os.path.join(rvc_models_dir, rvc_dirname)} does not exist.')
366
 
367
+ cover_path = song_cover_pipeline(main_vocals = "spongebob.wav", backup_vocals=args.backup_v, voice_model = "plankton", pitch_change = args.pitch_change,
368
  main_gain=args.main_vol, backup_gain=args.backup_vol, inst_gain=args.inst_vol,
369
  index_rate=args.index_rate, filter_radius=args.filter_radius,
370
  rms_mix_rate=args.rms_mix_rate, f0_method=args.pitch_detection_algo,