Spaces:
Sleeping
Sleeping
helloWorld199
commited on
Commit
•
21d8e7a
1
Parent(s):
6548956
vocal_pipiline
Browse files- src/main.py +62 -1
- src/webui.py +29 -1
src/main.py
CHANGED
@@ -189,6 +189,22 @@ def preprocess_song(song_input, mdx_model_params, song_id, is_webui, input_type,
|
|
189 |
|
190 |
return orig_song_path, vocals_path, instrumentals_path, main_vocals_path, backup_vocals_path, main_vocals_dereverb_path
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
def voice_change(voice_model, vocals_path, output_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui):
|
194 |
rvc_model_path, rvc_index_path = get_rvc_model(voice_model, is_webui)
|
@@ -232,6 +248,49 @@ 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 |
def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
|
237 |
is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
|
@@ -355,8 +414,10 @@ if __name__ == '__main__':
|
|
355 |
pitch_change_all=args.pitch_change_all,
|
356 |
reverb_rm_size=args.reverb_size, reverb_wet=args.reverb_wetness,
|
357 |
reverb_dry=args.reverb_dryness, reverb_damping=args.reverb_damping,
|
358 |
-
output_format=args.output_format)
|
359 |
|
|
|
|
|
360 |
print(f'[+] Cover generated at {cover_path}')
|
361 |
print(f'[+] Original vocals at {original_vocals}')
|
362 |
print(f'[+] Original instrumentals at {original_instrumentals}')
|
|
|
189 |
|
190 |
return orig_song_path, vocals_path, instrumentals_path, main_vocals_path, backup_vocals_path, main_vocals_dereverb_path
|
191 |
|
192 |
+
def preprocess_vocals_only(song_input, mdx_model_params, song_id, is_webui, input_type, progress=None):
|
193 |
+
keep_orig = False
|
194 |
+
if input_type == 'local':
|
195 |
+
orig_song_path = song_input
|
196 |
+
keep_orig = True
|
197 |
+
else:
|
198 |
+
orig_song_path = None
|
199 |
+
|
200 |
+
song_output_dir = os.path.join(output_dir, song_id)
|
201 |
+
orig_song_path = convert_to_stereo(orig_song_path)
|
202 |
+
|
203 |
+
display_progress('[~] Applying DeReverb to Vocals...', 0.3, is_webui, progress)
|
204 |
+
_, vocals_path = run_mdx(mdx_model_params, song_output_dir, os.path.join(mdxnet_models_dir, 'Reverb_HQ_By_FoxJoy.onnx'), orig_song_path, invert_suffix='DeReverb', exclude_main=True, denoise=True)
|
205 |
+
|
206 |
+
return vocals_path
|
207 |
+
|
208 |
|
209 |
def voice_change(voice_model, vocals_path, output_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui):
|
210 |
rvc_model_path, rvc_index_path = get_rvc_model(voice_model, is_webui)
|
|
|
248 |
instrumental_audio = AudioSegment.from_wav(audio_paths[2]) - 7 + inst_gain
|
249 |
main_vocal_audio.overlay(backup_vocal_audio).overlay(instrumental_audio).export(output_path, format=output_format)
|
250 |
|
251 |
+
def vocal_only_pipeline(song_input, voice_model, pitch_change, is_webui=0,index_rate=0.5, filter_radius=3,
|
252 |
+
rms_mix_rate=0.25, f0_method='rmvpe', crepe_hop_length=128, protect=0.33, pitch_change_all=0,
|
253 |
+
reverb_rm_size=0.15, reverb_wet=0.2, reverb_dry=0.8, reverb_damping=0.7, output_format='mp3',progress=gr.Progress()):
|
254 |
+
#Load mdx parameters
|
255 |
+
with open(os.path.join(mdxnet_models_dir, 'model_data.json')) as infile:
|
256 |
+
mdx_model_params = json.load(infile)
|
257 |
+
|
258 |
+
# Get path of loaded vocal file
|
259 |
+
input_type = 'local'
|
260 |
+
song_input = song_input.strip('\"')
|
261 |
+
if os.path.exists(song_input):
|
262 |
+
song_id = get_hash(song_input)
|
263 |
+
else:
|
264 |
+
error_msg = f'{song_input} does not exist.'
|
265 |
+
song_id = None
|
266 |
+
raise_exception(error_msg, is_webui)
|
267 |
+
|
268 |
+
song_dir = os.path.join(output_dir, song_id)
|
269 |
+
|
270 |
+
if not os.path.exists(song_dir):
|
271 |
+
os.makedirs(song_dir)
|
272 |
+
vocals_path = preprocess_vocals_only(song_input, mdx_model_params, song_id, is_webui, input_type, progress)
|
273 |
+
else:
|
274 |
+
vocals_path = None
|
275 |
+
paths = get_audio_paths(song_dir)
|
276 |
+
|
277 |
+
# if any of the audio files aren't available or keep intermediate files, rerun preprocess
|
278 |
+
if any(path is None for path in paths):
|
279 |
+
vocals_path = preprocess_vocals_only(song_input, mdx_model_params, song_id, is_webui, input_type, progress)
|
280 |
+
else:
|
281 |
+
vocals_path = paths
|
282 |
+
|
283 |
+
pitch_change = pitch_change * 12 + pitch_change_all
|
284 |
+
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')
|
285 |
+
if not os.path.exists(ai_vocals_path):
|
286 |
+
display_progress('[~] Converting voice using RVC...', 0.5, is_webui, progress)
|
287 |
+
voice_change(voice_model, vocals_path, ai_vocals_path, pitch_change, f0_method, index_rate, filter_radius, rms_mix_rate, protect, crepe_hop_length, is_webui)
|
288 |
+
display_progress('[~] Applying audio effects to Vocals...', 0.8, is_webui, progress)
|
289 |
+
ai_vocals_mixed_path = add_audio_effects(ai_vocals_path, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping)
|
290 |
+
|
291 |
+
return ai_vocals_mixed_path
|
292 |
+
|
293 |
+
|
294 |
|
295 |
def song_cover_pipeline(song_input, voice_model, pitch_change, keep_files,
|
296 |
is_webui=0, main_gain=0, backup_gain=0, inst_gain=0, index_rate=0.5, filter_radius=3,
|
|
|
414 |
pitch_change_all=args.pitch_change_all,
|
415 |
reverb_rm_size=args.reverb_size, reverb_wet=args.reverb_wetness,
|
416 |
reverb_dry=args.reverb_dryness, reverb_damping=args.reverb_damping,
|
417 |
+
output_format=args.output_format, vocal_only=False)
|
418 |
|
419 |
+
|
420 |
+
|
421 |
print(f'[+] Cover generated at {cover_path}')
|
422 |
print(f'[+] Original vocals at {original_vocals}')
|
423 |
print(f'[+] Original instrumentals at {original_instrumentals}')
|
src/webui.py
CHANGED
@@ -7,7 +7,7 @@ from argparse import ArgumentParser
|
|
7 |
|
8 |
import gradio as gr
|
9 |
|
10 |
-
from main import song_cover_pipeline
|
11 |
|
12 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
13 |
|
@@ -181,6 +181,7 @@ if __name__ == '__main__':
|
|
181 |
|
182 |
with gr.Column() as yt_link_col:
|
183 |
song_input = gr.Text(label='Song input', info='Link to a song on YouTube or full path to a local file. For file upload, click the button below.')
|
|
|
184 |
show_file_upload_button = gr.Button('Upload file instead')
|
185 |
|
186 |
with gr.Column(visible=False) as file_upload_col:
|
@@ -243,6 +244,33 @@ if __name__ == '__main__':
|
|
243 |
outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
|
244 |
protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
|
245 |
reverb_dry, reverb_damping, output_format, ai_cover])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
# Download tab
|
248 |
with gr.Tab('Download model'):
|
|
|
7 |
|
8 |
import gradio as gr
|
9 |
|
10 |
+
from main import song_cover_pipeline, vocal_only_pipeline
|
11 |
|
12 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
13 |
|
|
|
181 |
|
182 |
with gr.Column() as yt_link_col:
|
183 |
song_input = gr.Text(label='Song input', info='Link to a song on YouTube or full path to a local file. For file upload, click the button below.')
|
184 |
+
|
185 |
show_file_upload_button = gr.Button('Upload file instead')
|
186 |
|
187 |
with gr.Column(visible=False) as file_upload_col:
|
|
|
244 |
outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
|
245 |
protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
|
246 |
reverb_dry, reverb_damping, output_format, ai_cover])
|
247 |
+
|
248 |
+
with gr.Row():
|
249 |
+
with gr.Column():
|
250 |
+
rvc_model = gr.Dropdown(voice_models, label='Voice Models', info='Models folder "AICoverGen --> rvc_models". After new models are added into this folder, click the refresh button')
|
251 |
+
ref_btn = gr.Button('Refresh Models 🔁', variant='primary')
|
252 |
+
|
253 |
+
with gr.Column() as file_upload_col:
|
254 |
+
local_file = gr.File(label='Audio file')
|
255 |
+
song_input_file = gr.UploadButton('Upload 📂', file_types=['audio'], variant='primary')
|
256 |
+
song_input_file.upload(process_file_upload, inputs=[song_input_file], outputs=[local_file, song_input])
|
257 |
+
|
258 |
+
with gr.Column():
|
259 |
+
pitch = gr.Slider(-3, 3, value=0, step=1, label='Pitch Change (Vocals ONLY)', info='Generally, use 1 for male to female conversions and -1 for vice-versa. (Octaves)')
|
260 |
+
pitch_all = gr.Slider(-12, 12, value=0, step=1, label='Overall Pitch Change', info='Changes pitch/key of vocals and instrumentals together. Altering this slightly reduces sound quality. (Semitones)')
|
261 |
+
|
262 |
+
with gr.Row():
|
263 |
+
ai_vocals =gr.Audio(label='ai_vocals', show_share_button=False)
|
264 |
+
ref_btn.click(update_models_list, None, outputs=rvc_model)
|
265 |
+
is_webui = gr.Number(value=1, visible=False)
|
266 |
+
generate_btn.click(vocal_only_pipeline,
|
267 |
+
inputs=[song_input, rvc_model, pitch, is_webui, index_rate, filter_radius, rms_mix_rate, f0_method, crepe_hop_length,
|
268 |
+
protect, pitch_all, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping],
|
269 |
+
outputs=[ai_vocals])
|
270 |
+
#clear_btn.click(lambda: [0, 0, 0, 0, 0.5, 3, 0.25, 0.33, 'rmvpe', 128, 0, 0.15, 0.2, 0.8, 0.7, 'mp3', None],
|
271 |
+
# outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
|
272 |
+
# protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
|
273 |
+
# reverb_dry, reverb_damping, output_format, ai_cover])
|
274 |
|
275 |
# Download tab
|
276 |
with gr.Tab('Download model'):
|