Spaces:
Running on Zero
Running on Zero
Update src/main.py
Browse files297 unmodified lines29829930030130230330413 unmodified lines3183193203213223232 unmodified lines32632732832933033133287 unmodified lines42042142242342442542631 unmodified lines4584594604614624634644654664674684694704714724734744754764774785 unmodified lines484485486487488489490491492493494297 unmodified lines# @spaces.GPU(enable_queue=True, duration=130)@spaces.GPU(duration=59)def process_song(song_dir, song_input, mdx_model_params, song_id, is_webui, input_type, progress,keep_files, pitch_change, pitch_change_all, voice_model, index_rate, filter_radius,13 unmodified lineselse:orig_song_path, instrumentals_path, main_vocals_dereverb_path, backup_vocals_path = pathspitch_change = pitch_change * 12 + pitch_change_allai_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')ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')2 unmodified linesdisplay_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)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)return ai_vocals_path, ai_cover_path, instrumentals_path, backup_vocals_path, vocals_path, main_vocals_pathdef apply_noisereduce(audio_list, type_output="wav"):87 unmodified linesinstrumentals_path,backup_vocals_path,vocals_path,main_vocals_path) = process_song(song_dir,song_input,31 unmodified linesai_vocals_path = apply_noisereduce([ai_vocals_path])[0]ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)ins_path = get_audio_with_suffix(song_dir, "_Voiceless.wav")if not ins_path:instrumentals_path, _ = run_mdx(mdx_model_params,os.path.join(output_dir, song_id),os.path.join(mdxnet_models_dir, "UVR-MDX-NET-Inst_HQ_4.onnx"),instrumentals_path,# exclude_main=False,exclude_inversion=True,suffix="Voiceless",denoise=False,keep_orig=True,base_device=("" if IS_ZERO_GPU else "cuda"))if pitch_change_all != 0:display_progress('[~] Applying overall pitch change', 0.85, is_webui, progress)5 unmodified linesif not keep_files:display_progress('[~] Removing intermediate audio files...', 0.95, is_webui, progress)intermediate_files = [vocals_path, main_vocals_path, ai_vocals_mixed_path, ins_path, nr_path]if pitch_change_all != 0:intermediate_files += [instrumentals_path, backup_vocals_path]for file in intermediate_files:if file and os.path.exists(file):os.remove(file)return ai_cover_path297 unmodified lines29829930030130230330413 unmodified lines3183193203213223233243253263273283293303313323333343353363373383393403412 unmodified lines34434534634734834935087 unmodified lines43843944044144244344444531 unmodified lines4774784794804814825 unmodified lines488489490491492493494495496497498297 unmodified lines# @spaces.GPU(enable_queue=True, duration=130)@spaces.GPU(duration=65)def process_song(song_dir, song_input, mdx_model_params, song_id, is_webui, input_type, progress,keep_files, pitch_change, pitch_change_all, voice_model, index_rate, filter_radius,13 unmodified lineselse:orig_song_path, instrumentals_path, main_vocals_dereverb_path, backup_vocals_path = pathsins_path = get_audio_with_suffix(song_dir, "_Voiceless.wav")if not ins_path:display_progress('[~] Extracting voiceless track...', 0.4, is_webui, progress)instrumentals_path, _ = run_mdx(mdx_model_params,song_dir,os.path.join(mdxnet_models_dir, "UVR-MDX-NET-Inst_HQ_4.onnx"),instrumentals_path,exclude_inversion=True,suffix="Voiceless",denoise=False,keep_orig=True,base_device=("cuda" if IS_ZERO_GPU else ""))ins_path = get_audio_with_suffix(song_dir, "_Voiceless.wav")else:instrumentals_path = ins_pathpitch_change = pitch_change * 12 + pitch_change_allai_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')ai_cover_path = os.path.join(song_dir, f'{os.path.splitext(os.path.basename(orig_song_path))[0]} ({voice_model} Ver).{output_format}')2 unmodified linesdisplay_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)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)return ai_vocals_path, ai_cover_path, instrumentals_path, backup_vocals_path, vocals_path, main_vocals_path, ins_pathdef apply_noisereduce(audio_list, type_output="wav"):87 unmodified linesinstrumentals_path,backup_vocals_path,vocals_path,main_vocals_path,ins_path) = process_song(song_dir,song_input,31 unmodified linesai_vocals_path = apply_noisereduce([ai_vocals_path])[0]ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)if pitch_change_all != 0:display_progress('[~] Applying overall pitch change', 0.85, is_webui, progress)5 unmodified linesif not keep_files:display_progress('[~] Removing intermediate audio files...', 0.95, is_webui, progress)intermediate_files = [vocals_path, main_vocals_path, ai_vocals_mixed_path, nr_path]if pitch_change_all != 0:intermediate_files += [instrumentals_path, backup_vocals_path]for file in intermediate_files:if file and os.path.exists(file) and file != ins_path:os.remove(file)return ai_cover_path
src/main.py+24-20