Spaces:
Sleeping
Sleeping
helloWorld199
commited on
Update src/main.py
Browse files- src/main.py +15 -44
src/main.py
CHANGED
@@ -232,83 +232,54 @@ def combine_audio(audio_paths, output_path, main_gain, backup_gain, inst_gain, o
|
|
232 |
instrumental_audio = AudioSegment.from_wav(audio_paths[2]) - 7 + inst_gain
|
233 |
main_vocal_audio.overlay(backup_vocal_audio).overlay(instrumental_audio).export(output_path, format=output_format)
|
234 |
|
235 |
-
|
236 |
-
|
|
|
237 |
is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
|
238 |
rms_mix_rate=0.25, f0_method='rmvpe', crepe_hop_length=128, protect=0.33, pitch_change_all=0,
|
239 |
reverb_rm_size=0.15, reverb_wet=0.2, reverb_dry=0.8, reverb_damping=0.7, output_format='mp3',
|
240 |
progress=gr.Progress()):
|
241 |
try:
|
242 |
-
|
|
|
243 |
raise_exception('Ensure that the song input field and voice model field is filled.', is_webui)
|
244 |
|
245 |
-
display_progress('[~] Starting AI Cover Generation Pipeline...', 0, is_webui, progress)
|
246 |
|
247 |
with open(os.path.join(mdxnet_models_dir, 'model_data.json')) as infile:
|
248 |
mdx_model_params = json.load(infile)
|
249 |
|
250 |
-
# if youtube url
|
251 |
-
if urlparse(song_input).scheme == 'https':
|
252 |
-
input_type = 'yt'
|
253 |
-
song_id = get_youtube_video_id(song_input)
|
254 |
-
if song_id is None:
|
255 |
-
error_msg = 'Invalid YouTube url.'
|
256 |
-
raise_exception(error_msg, is_webui)
|
257 |
-
|
258 |
# local audio file
|
259 |
else:
|
260 |
input_type = 'local'
|
261 |
-
|
262 |
-
if os.path.exists(
|
263 |
-
song_id = get_hash(
|
264 |
else:
|
265 |
-
error_msg = f'{
|
266 |
song_id = None
|
267 |
raise_exception(error_msg, is_webui)
|
268 |
|
269 |
song_dir = os.path.join(output_dir, song_id)
|
270 |
-
|
271 |
-
if not os.path.exists(song_dir):
|
272 |
-
os.makedirs(song_dir)
|
273 |
-
orig_song_path, vocals_path, instrumentals_path, main_vocals_path, backup_vocals_path, main_vocals_dereverb_path = preprocess_song(song_input, mdx_model_params, song_id, is_webui, input_type, progress)
|
274 |
-
|
275 |
-
else:
|
276 |
-
vocals_path, main_vocals_path = None, None
|
277 |
-
paths = get_audio_paths(song_dir)
|
278 |
-
|
279 |
-
# if any of the audio files aren't available or keep intermediate files, rerun preprocess
|
280 |
-
if any(path is None for path in paths) or keep_files:
|
281 |
-
orig_song_path, vocals_path, instrumentals_path, main_vocals_path, backup_vocals_path, main_vocals_dereverb_path = preprocess_song(song_input, mdx_model_params, song_id, is_webui, input_type, progress)
|
282 |
-
else:
|
283 |
-
orig_song_path, instrumentals_path, main_vocals_dereverb_path, backup_vocals_path = paths
|
284 |
|
285 |
pitch_change = pitch_change * 12 + pitch_change_all
|
286 |
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')
|
287 |
-
ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')
|
288 |
|
289 |
if not os.path.exists(ai_vocals_path):
|
290 |
display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
|
291 |
-
voice_change(voice_model,
|
292 |
|
293 |
display_progress('[~] Applying audio effects to Vocals...', 0.8, is_webui, progress)
|
294 |
ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)
|
295 |
|
296 |
if pitch_change_all != 0:
|
297 |
display_progress('[~] Applying overall pitch change', 0.85, is_webui, progress)
|
298 |
-
|
299 |
-
backup_vocals_path = pitch_shift(backup_vocals_path, pitch_change_all)
|
300 |
|
301 |
display_progress('[~] Combining AI Vocals and Instrumentals...', 0.9, is_webui, progress)
|
302 |
-
combine_audio([ai_vocals_mixed_path,
|
303 |
-
|
304 |
-
if not keep_files:
|
305 |
-
display_progress('[~] Removing intermediate audio files...', 0.95, is_webui, progress)
|
306 |
-
intermediate_files = [vocals_path, main_vocals_path, ai_vocals_mixed_path]
|
307 |
-
if pitch_change_all != 0:
|
308 |
-
intermediate_files += [instrumentals_path, backup_vocals_path]
|
309 |
-
for file in intermediate_files:
|
310 |
-
if file and os.path.exists(file):
|
311 |
-
os.remove(file)
|
312 |
|
313 |
return ai_cover_path
|
314 |
|
|
|
232 |
instrumental_audio = AudioSegment.from_wav(audio_paths[2]) - 7 + inst_gain
|
233 |
main_vocal_audio.overlay(backup_vocal_audio).overlay(instrumental_audio).export(output_path, format=output_format)
|
234 |
|
235 |
+
# song_input is the main vocals that is going through the rvc processs
|
236 |
+
# backup vocals are the backup vocals to be added at the end
|
237 |
+
def song_cover_pipeline(main_vocals, backup_vocals, voice_model, pitch_change, keep_files,
|
238 |
is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
|
239 |
rms_mix_rate=0.25, f0_method='rmvpe', crepe_hop_length=128, protect=0.33, pitch_change_all=0,
|
240 |
reverb_rm_size=0.15, reverb_wet=0.2, reverb_dry=0.8, reverb_damping=0.7, output_format='mp3',
|
241 |
progress=gr.Progress()):
|
242 |
try:
|
243 |
+
print(f"DEBUG PRINT: main_vocals: {main_vocals}, backup_vocals: {backup_vocals}")
|
244 |
+
if not main_vocals or not voice_model:
|
245 |
raise_exception('Ensure that the song input field and voice model field is filled.', is_webui)
|
246 |
|
247 |
+
display_progress('[~] Starting AI vocals Cover Generation Pipeline...', 0, is_webui, progress)
|
248 |
|
249 |
with open(os.path.join(mdxnet_models_dir, 'model_data.json')) as infile:
|
250 |
mdx_model_params = json.load(infile)
|
251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
# local audio file
|
253 |
else:
|
254 |
input_type = 'local'
|
255 |
+
main_vocals = main_vocals.strip('\"')
|
256 |
+
if os.path.exists(main_vocals):
|
257 |
+
song_id = get_hash(main_vocals)
|
258 |
else:
|
259 |
+
error_msg = f'{main_vocals} does not exist.'
|
260 |
song_id = None
|
261 |
raise_exception(error_msg, is_webui)
|
262 |
|
263 |
song_dir = os.path.join(output_dir, song_id)
|
264 |
+
print(f"DEBUG PRINT: song_dir {song_dir}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
pitch_change = pitch_change * 12 + pitch_change_all
|
267 |
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')
|
268 |
+
ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver)_cover.{output_format}')
|
269 |
|
270 |
if not os.path.exists(ai_vocals_path):
|
271 |
display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
|
272 |
+
voice_change(voice_model, main_vocals, ai_vocals_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui)
|
273 |
|
274 |
display_progress('[~] Applying audio effects to Vocals...', 0.8, is_webui, progress)
|
275 |
ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)
|
276 |
|
277 |
if pitch_change_all != 0:
|
278 |
display_progress('[~] Applying overall pitch change', 0.85, is_webui, progress)
|
279 |
+
backup_vocals = pitch_shift(backup_vocals, pitch_change_all)
|
|
|
280 |
|
281 |
display_progress('[~] Combining AI Vocals and Instrumentals...', 0.9, is_webui, progress)
|
282 |
+
combine_audio([ai_vocals_mixed_path, backup_vocals], ai_cover_path, main_gain, backup_gain, inst_gain, output_format)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
return ai_cover_path
|
285 |
|