Bruna1221 commited on
Commit
a60205d
1 Parent(s): 47886bc

Upload 2 files

Browse files
Files changed (2) hide show
  1. app-full.py +503 -0
  2. app.py +504 -0
app-full.py ADDED
@@ -0,0 +1,503 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import json
4
+ import traceback
5
+ import logging
6
+ import gradio as gr
7
+ import numpy as np
8
+ import librosa
9
+ import torch
10
+ import asyncio
11
+ import edge_tts
12
+ import yt_dlp
13
+ import ffmpeg
14
+ import subprocess
15
+ import sys
16
+ import io
17
+ import wave
18
+ from datetime import datetime
19
+ from fairseq import checkpoint_utils
20
+ from lib.infer_pack.models import (
21
+ SynthesizerTrnMs256NSFsid,
22
+ SynthesizerTrnMs256NSFsid_nono,
23
+ SynthesizerTrnMs768NSFsid,
24
+ SynthesizerTrnMs768NSFsid_nono,
25
+ )
26
+ from vc_infer_pipeline import VC
27
+ from config import Config
28
+ config = Config()
29
+ logging.getLogger("numba").setLevel(logging.WARNING)
30
+ limitation = os.getenv("SYSTEM") == "spaces"
31
+
32
+ audio_mode = []
33
+ f0method_mode = []
34
+ f0method_info = ""
35
+
36
+ if limitation is True:
37
+ audio_mode = ["Upload audio", "TTS Audio"]
38
+ f0method_mode = ["pm", "harvest"]
39
+ f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better). (Default: PM)"
40
+ else:
41
+ audio_mode = ["Input path", "Upload audio", "Youtube", "TTS Audio"]
42
+ f0method_mode = ["pm", "harvest", "crepe"]
43
+ f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"
44
+
45
+ if os.path.isfile("rmvpe.pt"):
46
+ f0method_mode.insert(2, "rmvpe")
47
+
48
+ def create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, file_index):
49
+ def vc_fn(
50
+ vc_audio_mode,
51
+ vc_input,
52
+ vc_upload,
53
+ tts_text,
54
+ tts_voice,
55
+ f0_up_key,
56
+ f0_method,
57
+ index_rate,
58
+ filter_radius,
59
+ resample_sr,
60
+ rms_mix_rate,
61
+ protect,
62
+ ):
63
+ try:
64
+ print(f"Converting using {model_name}...")
65
+ if vc_audio_mode == "Input path" or "Youtube" and vc_input != "":
66
+ audio, sr = librosa.load(vc_input, sr=16000, mono=True)
67
+ elif vc_audio_mode == "Upload audio":
68
+ if vc_upload is None:
69
+ return "You need to upload an audio", None
70
+ sampling_rate, audio = vc_upload
71
+ duration = audio.shape[0] / sampling_rate
72
+ if duration > 20 and limitation:
73
+ return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None
74
+ audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
75
+ if len(audio.shape) > 1:
76
+ audio = librosa.to_mono(audio.transpose(1, 0))
77
+ if sampling_rate != 16000:
78
+ audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
79
+ elif vc_audio_mode == "TTS Audio":
80
+ if len(tts_text) > 100 and limitation:
81
+ return "Text is too long", None
82
+ if tts_text is None or tts_voice is None:
83
+ return "You need to enter text and select a voice", None
84
+ asyncio.run(edge_tts.Communicate(tts_text, "-".join(tts_voice.split('-')[:-1])).save("tts.mp3"))
85
+ audio, sr = librosa.load("tts.mp3", sr=16000, mono=True)
86
+ vc_input = "tts.mp3"
87
+ times = [0, 0, 0]
88
+ f0_up_key = int(f0_up_key)
89
+ audio_opt = vc.pipeline(
90
+ hubert_model,
91
+ net_g,
92
+ 0,
93
+ audio,
94
+ vc_input,
95
+ times,
96
+ f0_up_key,
97
+ f0_method,
98
+ file_index,
99
+ # file_big_npy,
100
+ index_rate,
101
+ if_f0,
102
+ filter_radius,
103
+ tgt_sr,
104
+ resample_sr,
105
+ rms_mix_rate,
106
+ version,
107
+ protect,
108
+ f0_file=None,
109
+ )
110
+ info = f"[{datetime.now().strftime('%Y-%m-%d %H:%M')}]: npy: {times[0]}, f0: {times[1]}s, infer: {times[2]}s"
111
+ print(f"{model_name} | {info}")
112
+ return info, (tgt_sr, audio_opt)
113
+ except:
114
+ info = traceback.format_exc()
115
+ print(info)
116
+ return info, None
117
+ return vc_fn
118
+
119
+ def load_model():
120
+ models = []
121
+ with open(f"weights/model_info.json", "r", encoding="utf-8") as f:
122
+ models_info = json.load(f)
123
+ for character_name, info in models_info.items():
124
+ if not info['enable']:
125
+ continue
126
+ model_title = info['title']
127
+ model_name = info['model_path']
128
+ model_author = info.get("author", None)
129
+ model_cover = f"weights/{character_name}/{info['cover']}"
130
+ model_index = f"weights/{character_name}/{info['feature_retrieval_library']}"
131
+ cpt = torch.load(f"weights/{character_name}/{model_name}", map_location="cpu")
132
+ tgt_sr = cpt["config"][-1]
133
+ cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
134
+ if_f0 = cpt.get("f0", 1)
135
+ version = cpt.get("version", "v1")
136
+ if version == "v1":
137
+ if if_f0 == 1:
138
+ net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
139
+ else:
140
+ net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
141
+ model_version = "V1"
142
+ elif version == "v2":
143
+ if if_f0 == 1:
144
+ net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
145
+ else:
146
+ net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
147
+ model_version = "V2"
148
+ del net_g.enc_q
149
+ print(net_g.load_state_dict(cpt["weight"], strict=False))
150
+ net_g.eval().to(config.device)
151
+ if config.is_half:
152
+ net_g = net_g.half()
153
+ else:
154
+ net_g = net_g.float()
155
+ vc = VC(tgt_sr, config)
156
+ print(f"Model loaded: {character_name} / {info['feature_retrieval_library']} | ({model_version})")
157
+ models.append((character_name, model_title, model_author, model_cover, model_version, create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, model_index)))
158
+ return models
159
+
160
+ def cut_vocal_and_inst(url, audio_provider, split_model):
161
+ if url != "":
162
+ if not os.path.exists("dl_audio"):
163
+ os.mkdir("dl_audio")
164
+ if audio_provider == "Youtube":
165
+ ydl_opts = {
166
+ 'noplaylist': True,
167
+ 'format': 'bestaudio/best',
168
+ 'postprocessors': [{
169
+ 'key': 'FFmpegExtractAudio',
170
+ 'preferredcodec': 'wav',
171
+ }],
172
+ "outtmpl": 'dl_audio/youtube_audio',
173
+ }
174
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
175
+ ydl.download([url])
176
+ audio_path = "dl_audio/youtube_audio.wav"
177
+ if split_model == "htdemucs":
178
+ command = f"demucs --two-stems=vocals {audio_path} -o output"
179
+ result = subprocess.run(command.split(), stdout=subprocess.PIPE)
180
+ print(result.stdout.decode())
181
+ return "output/htdemucs/youtube_audio/vocals.wav", "output/htdemucs/youtube_audio/no_vocals.wav", audio_path, "output/htdemucs/youtube_audio/vocals.wav"
182
+ else:
183
+ command = f"demucs --two-stems=vocals -n mdx_extra_q {audio_path} -o output"
184
+ result = subprocess.run(command.split(), stdout=subprocess.PIPE)
185
+ print(result.stdout.decode())
186
+ return "output/mdx_extra_q/youtube_audio/vocals.wav", "output/mdx_extra_q/youtube_audio/no_vocals.wav", audio_path, "output/mdx_extra_q/youtube_audio/vocals.wav"
187
+ else:
188
+ raise gr.Error("URL Required!")
189
+ return None, None, None, None
190
+
191
+ def combine_vocal_and_inst(audio_data, audio_volume, split_model):
192
+ if not os.path.exists("output/result"):
193
+ os.mkdir("output/result")
194
+ vocal_path = "output/result/output.wav"
195
+ output_path = "output/result/combine.mp3"
196
+ if split_model == "htdemucs":
197
+ inst_path = "output/htdemucs/youtube_audio/no_vocals.wav"
198
+ else:
199
+ inst_path = "output/mdx_extra_q/youtube_audio/no_vocals.wav"
200
+ with wave.open(vocal_path, "w") as wave_file:
201
+ wave_file.setnchannels(1)
202
+ wave_file.setsampwidth(2)
203
+ wave_file.setframerate(audio_data[0])
204
+ wave_file.writeframes(audio_data[1].tobytes())
205
+ command = f'ffmpeg -y -i {inst_path} -i {vocal_path} -filter_complex [1:a]volume={audio_volume}dB[v];[0:a][v]amix=inputs=2:duration=longest -b:a 320k -c:a libmp3lame {output_path}'
206
+ result = subprocess.run(command.split(), stdout=subprocess.PIPE)
207
+ print(result.stdout.decode())
208
+ return output_path
209
+
210
+ def load_hubert():
211
+ global hubert_model
212
+ models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
213
+ ["hubert_base.pt"],
214
+ suffix="",
215
+ )
216
+ hubert_model = models[0]
217
+ hubert_model = hubert_model.to(config.device)
218
+ if config.is_half:
219
+ hubert_model = hubert_model.half()
220
+ else:
221
+ hubert_model = hubert_model.float()
222
+ hubert_model.eval()
223
+
224
+ def change_audio_mode(vc_audio_mode):
225
+ if vc_audio_mode == "Input path":
226
+ return (
227
+ # Input & Upload
228
+ gr.Textbox.update(visible=True),
229
+ gr.Checkbox.update(visible=False),
230
+ gr.Audio.update(visible=False),
231
+ # Youtube
232
+ gr.Dropdown.update(visible=False),
233
+ gr.Textbox.update(visible=False),
234
+ gr.Dropdown.update(visible=False),
235
+ gr.Button.update(visible=False),
236
+ gr.Audio.update(visible=False),
237
+ gr.Audio.update(visible=False),
238
+ gr.Audio.update(visible=False),
239
+ gr.Slider.update(visible=False),
240
+ gr.Audio.update(visible=False),
241
+ gr.Button.update(visible=False),
242
+ # TTS
243
+ gr.Textbox.update(visible=False),
244
+ gr.Dropdown.update(visible=False)
245
+ )
246
+ elif vc_audio_mode == "Upload audio":
247
+ return (
248
+ # Input & Upload
249
+ gr.Textbox.update(visible=False),
250
+ gr.Checkbox.update(visible=True),
251
+ gr.Audio.update(visible=True),
252
+ # Youtube
253
+ gr.Dropdown.update(visible=False),
254
+ gr.Textbox.update(visible=False),
255
+ gr.Dropdown.update(visible=False),
256
+ gr.Button.update(visible=False),
257
+ gr.Audio.update(visible=False),
258
+ gr.Audio.update(visible=False),
259
+ gr.Audio.update(visible=False),
260
+ gr.Slider.update(visible=False),
261
+ gr.Audio.update(visible=False),
262
+ gr.Button.update(visible=False),
263
+ # TTS
264
+ gr.Textbox.update(visible=False),
265
+ gr.Dropdown.update(visible=False)
266
+ )
267
+ elif vc_audio_mode == "Youtube":
268
+ return (
269
+ # Input & Upload
270
+ gr.Textbox.update(visible=False),
271
+ gr.Checkbox.update(visible=False),
272
+ gr.Audio.update(visible=False),
273
+ # Youtube
274
+ gr.Dropdown.update(visible=True),
275
+ gr.Textbox.update(visible=True),
276
+ gr.Dropdown.update(visible=True),
277
+ gr.Button.update(visible=True),
278
+ gr.Audio.update(visible=True),
279
+ gr.Audio.update(visible=True),
280
+ gr.Audio.update(visible=True),
281
+ gr.Slider.update(visible=True),
282
+ gr.Audio.update(visible=True),
283
+ gr.Button.update(visible=True),
284
+ # TTS
285
+ gr.Textbox.update(visible=False),
286
+ gr.Dropdown.update(visible=False)
287
+ )
288
+ elif vc_audio_mode == "TTS Audio":
289
+ return (
290
+ # Input & Upload
291
+ gr.Textbox.update(visible=False),
292
+ gr.Checkbox.update(visible=False),
293
+ gr.Audio.update(visible=False),
294
+ # Youtube
295
+ gr.Dropdown.update(visible=False),
296
+ gr.Textbox.update(visible=False),
297
+ gr.Dropdown.update(visible=False),
298
+ gr.Button.update(visible=False),
299
+ gr.Audio.update(visible=False),
300
+ gr.Audio.update(visible=False),
301
+ gr.Audio.update(visible=False),
302
+ gr.Slider.update(visible=False),
303
+ gr.Audio.update(visible=False),
304
+ gr.Button.update(visible=False),
305
+ # TTS
306
+ gr.Textbox.update(visible=True),
307
+ gr.Dropdown.update(visible=True)
308
+ )
309
+ else:
310
+ return (
311
+ # Input & Upload
312
+ gr.Textbox.update(visible=False),
313
+ gr.Checkbox.update(visible=True),
314
+ gr.Audio.update(visible=True),
315
+ # Youtube
316
+ gr.Dropdown.update(visible=False),
317
+ gr.Textbox.update(visible=False),
318
+ gr.Dropdown.update(visible=False),
319
+ gr.Button.update(visible=False),
320
+ gr.Audio.update(visible=False),
321
+ gr.Audio.update(visible=False),
322
+ gr.Audio.update(visible=False),
323
+ gr.Slider.update(visible=False),
324
+ gr.Audio.update(visible=False),
325
+ gr.Button.update(visible=False),
326
+ # TTS
327
+ gr.Textbox.update(visible=False),
328
+ gr.Dropdown.update(visible=False)
329
+ )
330
+
331
+ def use_microphone(microphone):
332
+ if microphone == True:
333
+ return gr.Audio.update(source="microphone")
334
+ else:
335
+ return gr.Audio.update(source="upload")
336
+
337
+ if __name__ == '__main__':
338
+ load_hubert()
339
+ models = load_model()
340
+ tts_voice_list = asyncio.new_event_loop().run_until_complete(edge_tts.list_voices())
341
+ voices = [f"{v['ShortName']}-{v['Gender']}" for v in tts_voice_list]
342
+ with gr.Blocks() as app:
343
+ gr.Markdown(
344
+ "# <center> Combined Genshin Impact RVC Models\n"
345
+ "## <center> The input audio should be clean and pure voice without background music.\n"
346
+ "### <center> It is recommended to use google colab for more features. \n"
347
+ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1Tgr6q9kKiB5P37rUitrB3CsNl8JP9iQZ?usp=sharing)\n\n"
348
+ "[![Original Repo](https://badgen.net/badge/icon/github?icon=github&label=Original%20Repo)](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI)"
349
+ )
350
+ with gr.Tabs():
351
+ for (name, title, author, cover, model_version, vc_fn) in models:
352
+ with gr.TabItem(name):
353
+ with gr.Row():
354
+ gr.Markdown(
355
+ '<div align="center">'
356
+ f'<div>{title}</div>\n'+
357
+ f'<div>RVC {model_version} Model</div>\n'+
358
+ (f'<div>Model author: {author}</div>' if author else "")+
359
+ (f'<img style="width:auto;height:300px;" src="file/{cover}">' if cover else "")+
360
+ '</div>'
361
+ )
362
+ with gr.Row():
363
+ with gr.Column():
364
+ vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")
365
+ # Input
366
+ vc_input = gr.Textbox(label="Input audio path", visible=False)
367
+ # Upload
368
+ vc_microphone_mode = gr.Checkbox(label="Use Microphone", value=False, visible=True, interactive=True)
369
+ vc_upload = gr.Audio(label="Upload audio file", source="upload", visible=True, interactive=True)
370
+ # Youtube
371
+ vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")
372
+ vc_link = gr.Textbox(label="Youtube URL", visible=False, info="Example: https://www.youtube.com/watch?v=Nc0sB1Bmf-A", placeholder="https://www.youtube.com/watch?v=...")
373
+ vc_split_model = gr.Dropdown(label="Splitter Model", choices=["htdemucs", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", info="Select the splitter model (Default: htdemucs)")
374
+ vc_split = gr.Button("Split Audio", variant="primary", visible=False)
375
+ vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)
376
+ vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)
377
+ vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)
378
+ # TTS
379
+ tts_text = gr.Textbox(visible=False, label="TTS text", info="Text to speech input")
380
+ tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")
381
+ with gr.Column():
382
+ vc_transform0 = gr.Number(label="Transpose", value=0, info='Type "12" to change from male to female voice. Type "-12" to change female to male voice')
383
+ f0method0 = gr.Radio(
384
+ label="Pitch extraction algorithm",
385
+ info=f0method_info,
386
+ choices=f0method_mode,
387
+ value="pm",
388
+ interactive=True
389
+ )
390
+ index_rate1 = gr.Slider(
391
+ minimum=0,
392
+ maximum=1,
393
+ label="Retrieval feature ratio",
394
+ info="(Default: 0.7)",
395
+ value=0.7,
396
+ interactive=True,
397
+ )
398
+ filter_radius0 = gr.Slider(
399
+ minimum=0,
400
+ maximum=7,
401
+ label="Apply Median Filtering",
402
+ info="The value represents the filter radius and can reduce breathiness.",
403
+ value=3,
404
+ step=1,
405
+ interactive=True,
406
+ )
407
+ resample_sr0 = gr.Slider(
408
+ minimum=0,
409
+ maximum=48000,
410
+ label="Resample the output audio",
411
+ info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",
412
+ value=0,
413
+ step=1,
414
+ interactive=True,
415
+ )
416
+ rms_mix_rate0 = gr.Slider(
417
+ minimum=0,
418
+ maximum=1,
419
+ label="Volume Envelope",
420
+ info="Use the volume envelope of the input to replace or mix with the volume envelope of the output. The closer the ratio is to 1, the more the output envelope is used",
421
+ value=1,
422
+ interactive=True,
423
+ )
424
+ protect0 = gr.Slider(
425
+ minimum=0,
426
+ maximum=0.5,
427
+ label="Voice Protection",
428
+ info="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",
429
+ value=0.5,
430
+ step=0.01,
431
+ interactive=True,
432
+ )
433
+ with gr.Column():
434
+ vc_log = gr.Textbox(label="Output Information", interactive=False)
435
+ vc_output = gr.Audio(label="Output Audio", interactive=False)
436
+ vc_convert = gr.Button("Convert", variant="primary")
437
+ vc_volume = gr.Slider(
438
+ minimum=0,
439
+ maximum=10,
440
+ label="Vocal volume",
441
+ value=4,
442
+ interactive=True,
443
+ step=1,
444
+ info="Adjust vocal volume (Default: 4}",
445
+ visible=False
446
+ )
447
+ vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)
448
+ vc_combine = gr.Button("Combine",variant="primary", visible=False)
449
+ vc_convert.click(
450
+ fn=vc_fn,
451
+ inputs=[
452
+ vc_audio_mode,
453
+ vc_input,
454
+ vc_upload,
455
+ tts_text,
456
+ tts_voice,
457
+ vc_transform0,
458
+ f0method0,
459
+ index_rate1,
460
+ filter_radius0,
461
+ resample_sr0,
462
+ rms_mix_rate0,
463
+ protect0,
464
+ ],
465
+ outputs=[vc_log ,vc_output]
466
+ )
467
+ vc_split.click(
468
+ fn=cut_vocal_and_inst,
469
+ inputs=[vc_link, vc_download_audio, vc_split_model],
470
+ outputs=[vc_vocal_preview, vc_inst_preview, vc_audio_preview, vc_input]
471
+ )
472
+ vc_combine.click(
473
+ fn=combine_vocal_and_inst,
474
+ inputs=[vc_output, vc_volume, vc_split_model],
475
+ outputs=[vc_combined_output]
476
+ )
477
+ vc_microphone_mode.change(
478
+ fn=use_microphone,
479
+ inputs=vc_microphone_mode,
480
+ outputs=vc_upload
481
+ )
482
+ vc_audio_mode.change(
483
+ fn=change_audio_mode,
484
+ inputs=[vc_audio_mode],
485
+ outputs=[
486
+ vc_input,
487
+ vc_microphone_mode,
488
+ vc_upload,
489
+ vc_download_audio,
490
+ vc_link,
491
+ vc_split_model,
492
+ vc_split,
493
+ vc_vocal_preview,
494
+ vc_inst_preview,
495
+ vc_audio_preview,
496
+ vc_volume,
497
+ vc_combined_output,
498
+ vc_combine,
499
+ tts_text,
500
+ tts_voice
501
+ ]
502
+ )
503
+ app.queue(concurrency_count=1, max_size=20, api_open=config.api).launch(share=config.colab)
app.py ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import json
4
+ import argparse
5
+ import traceback
6
+ import logging
7
+ import gradio as gr
8
+ import numpy as np
9
+ import librosa
10
+ import torch
11
+ import asyncio
12
+ import edge_tts
13
+ import yt_dlp
14
+ import ffmpeg
15
+ import subprocess
16
+ import sys
17
+ import io
18
+ import wave
19
+ from datetime import datetime
20
+ from fairseq import checkpoint_utils
21
+ from lib.infer_pack.models import (
22
+ SynthesizerTrnMs256NSFsid,
23
+ SynthesizerTrnMs256NSFsid_nono,
24
+ SynthesizerTrnMs768NSFsid,
25
+ SynthesizerTrnMs768NSFsid_nono,
26
+ )
27
+ from vc_infer_pipeline import VC
28
+ from config import Config
29
+ config = Config()
30
+ logging.getLogger("numba").setLevel(logging.WARNING)
31
+ limitation = os.getenv("SYSTEM") == "spaces" # limit audio length in huggingface spaces
32
+
33
+ audio_mode = []
34
+ f0method_mode = []
35
+ f0method_info = ""
36
+
37
+ if limitation is True:
38
+ audio_mode = ["Upload audio", "TTS Audio"]
39
+ f0method_mode = ["pm", "harvest"]
40
+ f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better). (Default: PM)"
41
+ else:
42
+ audio_mode = ["Input path", "Upload audio", "Youtube", "TTS Audio"]
43
+ f0method_mode = ["pm", "harvest", "crepe"]
44
+ f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"
45
+
46
+ if os.path.isfile("rmvpe.pt"):
47
+ f0method_mode.insert(2, "rmvpe")
48
+
49
+ def create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, file_index):
50
+ def vc_fn(
51
+ vc_audio_mode,
52
+ vc_input,
53
+ vc_upload,
54
+ tts_text,
55
+ tts_voice,
56
+ f0_up_key,
57
+ f0_method,
58
+ index_rate,
59
+ filter_radius,
60
+ resample_sr,
61
+ rms_mix_rate,
62
+ protect
63
+ ):
64
+ try:
65
+ print(f"Converting using {model_name}...")
66
+ if vc_audio_mode == "Input path" or "Youtube" and vc_input != "":
67
+ audio, sr = librosa.load(vc_input, sr=16000, mono=True)
68
+ elif vc_audio_mode == "Upload audio":
69
+ if vc_upload is None:
70
+ return "You need to upload an audio", None
71
+ sampling_rate, audio = vc_upload
72
+ duration = audio.shape[0] / sampling_rate
73
+ if duration > 20 and limitation:
74
+ return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None
75
+ audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
76
+ if len(audio.shape) > 1:
77
+ audio = librosa.to_mono(audio.transpose(1, 0))
78
+ if sampling_rate != 16000:
79
+ audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
80
+ elif vc_audio_mode == "TTS Audio":
81
+ if len(tts_text) > 100 and limitation:
82
+ return "Text is too long", None
83
+ if tts_text is None or tts_voice is None:
84
+ return "You need to enter text and select a voice", None
85
+ asyncio.run(edge_tts.Communicate(tts_text, "-".join(tts_voice.split('-')[:-1])).save("tts.mp3"))
86
+ audio, sr = librosa.load("tts.mp3", sr=16000, mono=True)
87
+ vc_input = "tts.mp3"
88
+ times = [0, 0, 0]
89
+ f0_up_key = int(f0_up_key)
90
+ audio_opt = vc.pipeline(
91
+ hubert_model,
92
+ net_g,
93
+ 0,
94
+ audio,
95
+ vc_input,
96
+ times,
97
+ f0_up_key,
98
+ f0_method,
99
+ file_index,
100
+ # file_big_npy,
101
+ index_rate,
102
+ if_f0,
103
+ filter_radius,
104
+ tgt_sr,
105
+ resample_sr,
106
+ rms_mix_rate,
107
+ version,
108
+ protect,
109
+ f0_file=None,
110
+ )
111
+ info = f"[{datetime.now().strftime('%Y-%m-%d %H:%M')}]: npy: {times[0]}, f0: {times[1]}s, infer: {times[2]}s"
112
+ print(info)
113
+ return info, (tgt_sr, audio_opt)
114
+ except:
115
+ info = traceback.format_exc()
116
+ print(f"{model_name} | {info}")
117
+ return info, (tgt_sr, audio_opt)
118
+ return vc_fn
119
+
120
+ def load_model():
121
+ models = []
122
+ with open(f"weights/model_info.json", "r", encoding="utf-8") as f:
123
+ models_info = json.load(f)
124
+ for character_name, info in models_info.items():
125
+ if not info['enable']:
126
+ continue
127
+ model_title = info['title']
128
+ model_name = info['model_path']
129
+ model_author = info.get("author", None)
130
+ model_cover = f"weights/{character_name}/{info['cover']}"
131
+ model_index = f"weights/{character_name}/{info['feature_retrieval_library']}"
132
+ cpt = torch.load(f"weights/{character_name}/{model_name}", map_location="cpu")
133
+ tgt_sr = cpt["config"][-1]
134
+ cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
135
+ if_f0 = cpt.get("f0", 1)
136
+ version = cpt.get("version", "v1")
137
+ if version == "v1":
138
+ if if_f0 == 1:
139
+ net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
140
+ else:
141
+ net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
142
+ model_version = "V1"
143
+ elif version == "v2":
144
+ if if_f0 == 1:
145
+ net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
146
+ else:
147
+ net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
148
+ model_version = "V2"
149
+ del net_g.enc_q
150
+ print(net_g.load_state_dict(cpt["weight"], strict=False))
151
+ net_g.eval().to(config.device)
152
+ if config.is_half:
153
+ net_g = net_g.half()
154
+ else:
155
+ net_g = net_g.float()
156
+ vc = VC(tgt_sr, config)
157
+ print(f"Model loaded: {character_name} / {info['feature_retrieval_library']} | ({model_version})")
158
+ models.append((character_name, model_title, model_author, model_cover, model_version, create_vc_fn(model_title, tgt_sr, net_g, vc, if_f0, version, model_index)))
159
+ return models
160
+
161
+ def cut_vocal_and_inst(url, audio_provider, split_model):
162
+ if url != "":
163
+ if not os.path.exists("dl_audio"):
164
+ os.mkdir("dl_audio")
165
+ if audio_provider == "Youtube":
166
+ ydl_opts = {
167
+ 'noplaylist': True,
168
+ 'format': 'bestaudio/best',
169
+ 'postprocessors': [{
170
+ 'key': 'FFmpegExtractAudio',
171
+ 'preferredcodec': 'wav',
172
+ }],
173
+ "outtmpl": 'dl_audio/youtube_audio',
174
+ }
175
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
176
+ ydl.download([url])
177
+ audio_path = "dl_audio/youtube_audio.wav"
178
+ if split_model == "htdemucs":
179
+ command = f"demucs --two-stems=vocals {audio_path} -o output"
180
+ result = subprocess.run(command.split(), stdout=subprocess.PIPE)
181
+ print(result.stdout.decode())
182
+ return "output/htdemucs/youtube_audio/vocals.wav", "output/htdemucs/youtube_audio/no_vocals.wav", audio_path, "output/htdemucs/youtube_audio/vocals.wav"
183
+ else:
184
+ command = f"demucs --two-stems=vocals -n mdx_extra_q {audio_path} -o output"
185
+ result = subprocess.run(command.split(), stdout=subprocess.PIPE)
186
+ print(result.stdout.decode())
187
+ return "output/mdx_extra_q/youtube_audio/vocals.wav", "output/mdx_extra_q/youtube_audio/no_vocals.wav", audio_path, "output/mdx_extra_q/youtube_audio/vocals.wav"
188
+ else:
189
+ raise gr.Error("URL Required!")
190
+ return None, None, None, None
191
+
192
+ def combine_vocal_and_inst(audio_data, audio_volume, split_model):
193
+ if not os.path.exists("output/result"):
194
+ os.mkdir("output/result")
195
+ vocal_path = "output/result/output.wav"
196
+ output_path = "output/result/combine.mp3"
197
+ if split_model == "htdemucs":
198
+ inst_path = "output/htdemucs/youtube_audio/no_vocals.wav"
199
+ else:
200
+ inst_path = "output/mdx_extra_q/youtube_audio/no_vocals.wav"
201
+ with wave.open(vocal_path, "w") as wave_file:
202
+ wave_file.setnchannels(1)
203
+ wave_file.setsampwidth(2)
204
+ wave_file.setframerate(audio_data[0])
205
+ wave_file.writeframes(audio_data[1].tobytes())
206
+ command = f'ffmpeg -y -i {inst_path} -i {vocal_path} -filter_complex [1:a]volume={audio_volume}dB[v];[0:a][v]amix=inputs=2:duration=longest -b:a 320k -c:a libmp3lame {output_path}'
207
+ result = subprocess.run(command.split(), stdout=subprocess.PIPE)
208
+ print(result.stdout.decode())
209
+ return output_path
210
+
211
+ def load_hubert():
212
+ global hubert_model
213
+ models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
214
+ ["hubert_base.pt"],
215
+ suffix="",
216
+ )
217
+ hubert_model = models[0]
218
+ hubert_model = hubert_model.to(config.device)
219
+ if config.is_half:
220
+ hubert_model = hubert_model.half()
221
+ else:
222
+ hubert_model = hubert_model.float()
223
+ hubert_model.eval()
224
+
225
+ def change_audio_mode(vc_audio_mode):
226
+ if vc_audio_mode == "Input path":
227
+ return (
228
+ # Input & Upload
229
+ gr.Textbox.update(visible=True),
230
+ gr.Checkbox.update(visible=False),
231
+ gr.Audio.update(visible=False),
232
+ # Youtube
233
+ gr.Dropdown.update(visible=False),
234
+ gr.Textbox.update(visible=False),
235
+ gr.Dropdown.update(visible=False),
236
+ gr.Button.update(visible=False),
237
+ gr.Audio.update(visible=False),
238
+ gr.Audio.update(visible=False),
239
+ gr.Audio.update(visible=False),
240
+ gr.Slider.update(visible=False),
241
+ gr.Audio.update(visible=False),
242
+ gr.Button.update(visible=False),
243
+ # TTS
244
+ gr.Textbox.update(visible=False),
245
+ gr.Dropdown.update(visible=False)
246
+ )
247
+ elif vc_audio_mode == "Upload audio":
248
+ return (
249
+ # Input & Upload
250
+ gr.Textbox.update(visible=False),
251
+ gr.Checkbox.update(visible=True),
252
+ gr.Audio.update(visible=True),
253
+ # Youtube
254
+ gr.Dropdown.update(visible=False),
255
+ gr.Textbox.update(visible=False),
256
+ gr.Dropdown.update(visible=False),
257
+ gr.Button.update(visible=False),
258
+ gr.Audio.update(visible=False),
259
+ gr.Audio.update(visible=False),
260
+ gr.Audio.update(visible=False),
261
+ gr.Slider.update(visible=False),
262
+ gr.Audio.update(visible=False),
263
+ gr.Button.update(visible=False),
264
+ # TTS
265
+ gr.Textbox.update(visible=False),
266
+ gr.Dropdown.update(visible=False)
267
+ )
268
+ elif vc_audio_mode == "Youtube":
269
+ return (
270
+ # Input & Upload
271
+ gr.Textbox.update(visible=False),
272
+ gr.Checkbox.update(visible=False),
273
+ gr.Audio.update(visible=False),
274
+ # Youtube
275
+ gr.Dropdown.update(visible=True),
276
+ gr.Textbox.update(visible=True),
277
+ gr.Dropdown.update(visible=True),
278
+ gr.Button.update(visible=True),
279
+ gr.Audio.update(visible=True),
280
+ gr.Audio.update(visible=True),
281
+ gr.Audio.update(visible=True),
282
+ gr.Slider.update(visible=True),
283
+ gr.Audio.update(visible=True),
284
+ gr.Button.update(visible=True),
285
+ # TTS
286
+ gr.Textbox.update(visible=False),
287
+ gr.Dropdown.update(visible=False)
288
+ )
289
+ elif vc_audio_mode == "TTS Audio":
290
+ return (
291
+ # Input & Upload
292
+ gr.Textbox.update(visible=False),
293
+ gr.Checkbox.update(visible=False),
294
+ gr.Audio.update(visible=False),
295
+ # Youtube
296
+ gr.Dropdown.update(visible=False),
297
+ gr.Textbox.update(visible=False),
298
+ gr.Dropdown.update(visible=False),
299
+ gr.Button.update(visible=False),
300
+ gr.Audio.update(visible=False),
301
+ gr.Audio.update(visible=False),
302
+ gr.Audio.update(visible=False),
303
+ gr.Slider.update(visible=False),
304
+ gr.Audio.update(visible=False),
305
+ gr.Button.update(visible=False),
306
+ # TTS
307
+ gr.Textbox.update(visible=True),
308
+ gr.Dropdown.update(visible=True)
309
+ )
310
+ else:
311
+ return (
312
+ # Input & Upload
313
+ gr.Textbox.update(visible=False),
314
+ gr.Checkbox.update(visible=True),
315
+ gr.Audio.update(visible=True),
316
+ # Youtube
317
+ gr.Dropdown.update(visible=False),
318
+ gr.Textbox.update(visible=False),
319
+ gr.Dropdown.update(visible=False),
320
+ gr.Button.update(visible=False),
321
+ gr.Audio.update(visible=False),
322
+ gr.Audio.update(visible=False),
323
+ gr.Audio.update(visible=False),
324
+ gr.Slider.update(visible=False),
325
+ gr.Audio.update(visible=False),
326
+ gr.Button.update(visible=False),
327
+ # TTS
328
+ gr.Textbox.update(visible=False),
329
+ gr.Dropdown.update(visible=False)
330
+ )
331
+
332
+ def use_microphone(microphone):
333
+ if microphone == True:
334
+ return gr.Audio.update(source="microphone")
335
+ else:
336
+ return gr.Audio.update(source="upload")
337
+
338
+ if __name__ == '__main__':
339
+ load_hubert()
340
+ models = load_model()
341
+ tts_voice_list = asyncio.new_event_loop().run_until_complete(edge_tts.list_voices())
342
+ voices = [f"{v['ShortName']}-{v['Gender']}" for v in tts_voice_list]
343
+ with gr.Blocks() as app:
344
+ gr.Markdown(
345
+ "# <center> Combined Genshin Impact RVC Models\n"
346
+ "## <center> The input audio should be clean and pure voice without background music.\n"
347
+ "### <center> It is recommended to use google colab for more features. \n"
348
+ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1Tgr6q9kKiB5P37rUitrB3CsNl8JP9iQZ?usp=sharing)\n\n"
349
+ "[![Original Repo](https://badgen.net/badge/icon/github?icon=github&label=Original%20Repo)](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI)"
350
+ )
351
+ with gr.Tabs():
352
+ for (name, title, author, cover, model_version, vc_fn) in models:
353
+ with gr.TabItem(name):
354
+ with gr.Row():
355
+ gr.Markdown(
356
+ '<div align="center">'
357
+ f'<div>{title}</div>\n'+
358
+ f'<div>RVC {model_version} Model</div>\n'+
359
+ (f'<div>Model author: {author}</div>' if author else "")+
360
+ (f'<img style="width:auto;height:300px;" src="file/{cover}">' if cover else "")+
361
+ '</div>'
362
+ )
363
+ with gr.Row():
364
+ with gr.Column():
365
+ vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")
366
+ # Input
367
+ vc_input = gr.Textbox(label="Input audio path", visible=False)
368
+ # Upload
369
+ vc_microphone_mode = gr.Checkbox(label="Use Microphone", value=False, visible=True, interactive=True)
370
+ vc_upload = gr.Audio(label="Upload audio file", source="upload", visible=True, interactive=True)
371
+ # Youtube
372
+ vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")
373
+ vc_link = gr.Textbox(label="Youtube URL", visible=False, info="Example: https://www.youtube.com/watch?v=Nc0sB1Bmf-A", placeholder="https://www.youtube.com/watch?v=...")
374
+ vc_split_model = gr.Dropdown(label="Splitter Model", choices=["htdemucs", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", info="Select the splitter model (Default: htdemucs)")
375
+ vc_split = gr.Button("Split Audio", variant="primary", visible=False)
376
+ vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)
377
+ vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)
378
+ vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)
379
+ # TTS
380
+ tts_text = gr.Textbox(visible=False, label="TTS text", info="Text to speech input")
381
+ tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")
382
+ with gr.Column():
383
+ vc_transform0 = gr.Number(label="Transpose", value=0, info='Type "12" to change from male to female voice. Type "-12" to change female to male voice')
384
+ f0method0 = gr.Radio(
385
+ label="Pitch extraction algorithm",
386
+ info=f0method_info,
387
+ choices=f0method_mode,
388
+ value="pm",
389
+ interactive=True
390
+ )
391
+ index_rate1 = gr.Slider(
392
+ minimum=0,
393
+ maximum=1,
394
+ label="Retrieval feature ratio",
395
+ info="(Default: 0.7)",
396
+ value=0.7,
397
+ interactive=True,
398
+ )
399
+ filter_radius0 = gr.Slider(
400
+ minimum=0,
401
+ maximum=7,
402
+ label="Apply Median Filtering",
403
+ info="The value represents the filter radius and can reduce breathiness.",
404
+ value=3,
405
+ step=1,
406
+ interactive=True,
407
+ )
408
+ resample_sr0 = gr.Slider(
409
+ minimum=0,
410
+ maximum=48000,
411
+ label="Resample the output audio",
412
+ info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",
413
+ value=0,
414
+ step=1,
415
+ interactive=True,
416
+ )
417
+ rms_mix_rate0 = gr.Slider(
418
+ minimum=0,
419
+ maximum=1,
420
+ label="Volume Envelope",
421
+ info="Use the volume envelope of the input to replace or mix with the volume envelope of the output. The closer the ratio is to 1, the more the output envelope is used",
422
+ value=1,
423
+ interactive=True,
424
+ )
425
+ protect0 = gr.Slider(
426
+ minimum=0,
427
+ maximum=0.5,
428
+ label="Voice Protection",
429
+ info="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",
430
+ value=0.5,
431
+ step=0.01,
432
+ interactive=True,
433
+ )
434
+ with gr.Column():
435
+ vc_log = gr.Textbox(label="Output Information", interactive=False)
436
+ vc_output = gr.Audio(label="Output Audio", interactive=False)
437
+ vc_convert = gr.Button("Convert", variant="primary")
438
+ vc_volume = gr.Slider(
439
+ minimum=0,
440
+ maximum=10,
441
+ label="Vocal volume",
442
+ value=4,
443
+ interactive=True,
444
+ step=1,
445
+ info="Adjust vocal volume (Default: 4}",
446
+ visible=False
447
+ )
448
+ vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)
449
+ vc_combine = gr.Button("Combine",variant="primary", visible=False)
450
+ vc_convert.click(
451
+ fn=vc_fn,
452
+ inputs=[
453
+ vc_audio_mode,
454
+ vc_input,
455
+ vc_upload,
456
+ tts_text,
457
+ tts_voice,
458
+ vc_transform0,
459
+ f0method0,
460
+ index_rate1,
461
+ filter_radius0,
462
+ resample_sr0,
463
+ rms_mix_rate0,
464
+ protect0,
465
+ ],
466
+ outputs=[vc_log ,vc_output]
467
+ )
468
+ vc_split.click(
469
+ fn=cut_vocal_and_inst,
470
+ inputs=[vc_link, vc_download_audio, vc_split_model],
471
+ outputs=[vc_vocal_preview, vc_inst_preview, vc_audio_preview, vc_input]
472
+ )
473
+ vc_combine.click(
474
+ fn=combine_vocal_and_inst,
475
+ inputs=[vc_output, vc_volume, vc_split_model],
476
+ outputs=[vc_combined_output]
477
+ )
478
+ vc_microphone_mode.change(
479
+ fn=use_microphone,
480
+ inputs=vc_microphone_mode,
481
+ outputs=vc_upload
482
+ )
483
+ vc_audio_mode.change(
484
+ fn=change_audio_mode,
485
+ inputs=[vc_audio_mode],
486
+ outputs=[
487
+ vc_input,
488
+ vc_microphone_mode,
489
+ vc_upload,
490
+ vc_download_audio,
491
+ vc_link,
492
+ vc_split_model,
493
+ vc_split,
494
+ vc_vocal_preview,
495
+ vc_inst_preview,
496
+ vc_audio_preview,
497
+ vc_volume,
498
+ vc_combined_output,
499
+ vc_combine,
500
+ tts_text,
501
+ tts_voice
502
+ ]
503
+ )
504
+ app.queue(concurrency_count=1, max_size=20, api_open=config.api).launch(share=config.colab)