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
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 |
+
if limitation is True:
|
36 |
+
audio_mode = ["Upload audio", "TTS Audio"]
|
37 |
+
f0method_mode = ["pm", "crepe", "harvest"]
|
38 |
+
f0method_info = "PM is fast, Crepe is good but it was extremely slow (Default: PM)"
|
39 |
+
else:
|
40 |
+
audio_mode = ["Upload audio", "Youtube", "TTS Audio"]
|
41 |
+
f0method_mode = ["pm", "harvest", "crepe"]
|
42 |
+
f0method_info = "PM is fast, Harvest is good at lower frequency but extremely slow, Crepe is good for higher notes. (Default: PM)"
|
43 |
+
def create_vc_fn(model_title, tgt_sr, net_g, vc, if_f0, version, file_index):
|
44 |
+
def vc_fn(
|
45 |
+
vc_audio_mode,
|
46 |
+
vc_input,
|
47 |
+
vc_upload,
|
48 |
+
tts_text,
|
49 |
+
tts_voice,
|
50 |
+
f0_up_key,
|
51 |
+
f0_method,
|
52 |
+
index_rate,
|
53 |
+
filter_radius,
|
54 |
+
resample_sr,
|
55 |
+
rms_mix_rate,
|
56 |
+
protect,
|
57 |
+
):
|
58 |
+
try:
|
59 |
+
if vc_audio_mode == "Input path" or "Youtube" and vc_input != "":
|
60 |
+
audio, sr = librosa.load(vc_input, sr=16000, mono=True)
|
61 |
+
elif vc_audio_mode == "Upload audio":
|
62 |
+
if vc_upload is None:
|
63 |
+
return "You need to upload an audio", None
|
64 |
+
sampling_rate, audio = vc_upload
|
65 |
+
duration = audio.shape[0] / sampling_rate
|
66 |
+
if duration > 330 and limitation:
|
67 |
+
return "Please upload an audio file that is less than 1 minute.", None
|
68 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
69 |
+
if len(audio.shape) > 1:
|
70 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
71 |
+
if sampling_rate != 16000:
|
72 |
+
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
73 |
+
elif vc_audio_mode == "TTS Audio":
|
74 |
+
if len(tts_text) > 600 and limitation:
|
75 |
+
return "Text is too long", None
|
76 |
+
if tts_text is None or tts_voice is None:
|
77 |
+
return "You need to enter text and select a voice", None
|
78 |
+
asyncio.run(edge_tts.Communicate(tts_text, "-".join(tts_voice.split('-')[:-1])).save("tts.mp3"))
|
79 |
+
audio, sr = librosa.load("tts.mp3", sr=16000, mono=True)
|
80 |
+
vc_input = "tts.mp3"
|
81 |
+
times = [0, 0, 0]
|
82 |
+
f0_up_key = int(f0_up_key)
|
83 |
+
audio_opt = vc.pipeline(
|
84 |
+
hubert_model,
|
85 |
+
net_g,
|
86 |
+
0,
|
87 |
+
audio,
|
88 |
+
vc_input,
|
89 |
+
times,
|
90 |
+
f0_up_key,
|
91 |
+
f0_method,
|
92 |
+
file_index,
|
93 |
+
# file_big_npy,
|
94 |
+
index_rate,
|
95 |
+
if_f0,
|
96 |
+
filter_radius,
|
97 |
+
tgt_sr,
|
98 |
+
resample_sr,
|
99 |
+
rms_mix_rate,
|
100 |
+
version,
|
101 |
+
protect,
|
102 |
+
f0_file=None,
|
103 |
+
)
|
104 |
+
info = f"[{datetime.now().strftime('%Y-%m-%d %H:%M')}]: npy: {times[0]}, f0: {times[1]}s, infer: {times[2]}s"
|
105 |
+
print(f"{model_title} | {info}")
|
106 |
+
return info, (tgt_sr, audio_opt)
|
107 |
+
except:
|
108 |
+
info = traceback.format_exc()
|
109 |
+
print(info)
|
110 |
+
return info, (None, None)
|
111 |
+
return vc_fn
|
112 |
+
|
113 |
+
def load_model():
|
114 |
+
categories = []
|
115 |
+
with open("weights/folder_info.json", "r", encoding="utf-8") as f:
|
116 |
+
folder_info = json.load(f)
|
117 |
+
for category_name, category_info in folder_info.items():
|
118 |
+
if not category_info['enable']:
|
119 |
+
continue
|
120 |
+
category_title = category_info['title']
|
121 |
+
category_folder = category_info['folder_path']
|
122 |
+
models = []
|
123 |
+
with open(f"weights/{category_folder}/model_info.json", "r", encoding="utf-8") as f:
|
124 |
+
models_info = json.load(f)
|
125 |
+
for character_name, info in models_info.items():
|
126 |
+
if not info['enable']:
|
127 |
+
continue
|
128 |
+
model_title = info['title']
|
129 |
+
model_name = info['model_path']
|
130 |
+
model_author = info.get("author", None)
|
131 |
+
model_cover = f"weights/{category_folder}/{character_name}/{info['cover']}"
|
132 |
+
model_index = f"weights/{category_folder}/{character_name}/{info['feature_retrieval_library']}"
|
133 |
+
cpt = torch.load(f"weights/{category_folder}/{character_name}/{model_name}", map_location="cpu")
|
134 |
+
tgt_sr = cpt["config"][-1]
|
135 |
+
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
136 |
+
if_f0 = cpt.get("f0", 1)
|
137 |
+
version = cpt.get("version", "v1")
|
138 |
+
if version == "v1":
|
139 |
+
if if_f0 == 1:
|
140 |
+
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
|
141 |
+
else:
|
142 |
+
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
143 |
+
model_version = "V1"
|
144 |
+
elif version == "v2":
|
145 |
+
if if_f0 == 1:
|
146 |
+
net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
|
147 |
+
else:
|
148 |
+
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
149 |
+
model_version = "V2"
|
150 |
+
del net_g.enc_q
|
151 |
+
print(net_g.load_state_dict(cpt["weight"], strict=False))
|
152 |
+
net_g.eval().to(config.device)
|
153 |
+
if config.is_half:
|
154 |
+
net_g = net_g.half()
|
155 |
+
else:
|
156 |
+
net_g = net_g.float()
|
157 |
+
vc = VC(tgt_sr, config)
|
158 |
+
print(f"Model loaded: {character_name} / {info['feature_retrieval_library']} | ({model_version})")
|
159 |
+
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)))
|
160 |
+
categories.append([category_title, category_folder, models])
|
161 |
+
return categories
|
162 |
+
|
163 |
+
def cut_vocal_and_inst(url, audio_provider, split_model):
|
164 |
+
if url != "":
|
165 |
+
if not os.path.exists("dl_audio"):
|
166 |
+
os.mkdir("dl_audio")
|
167 |
+
if audio_provider == "Youtube":
|
168 |
+
ydl_opts = {
|
169 |
+
'format': 'bestaudio/best',
|
170 |
+
'postprocessors': [{
|
171 |
+
'key': 'FFmpegExtractAudio',
|
172 |
+
'preferredcodec': 'wav',
|
173 |
+
}],
|
174 |
+
"outtmpl": 'dl_audio/youtube_audio',
|
175 |
+
}
|
176 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
177 |
+
ydl.download([url])
|
178 |
+
audio_path = "dl_audio/youtube_audio.wav"
|
179 |
+
else:
|
180 |
+
# Spotify doesnt work.
|
181 |
+
# Need to find other solution soon.
|
182 |
+
'''
|
183 |
+
command = f"spotdl download {url} --output dl_audio/.wav"
|
184 |
+
result = subprocess.run(command.split(), stdout=subprocess.PIPE)
|
185 |
+
print(result.stdout.decode())
|
186 |
+
audio_path = "dl_audio/spotify_audio.wav"
|
187 |
+
'''
|
188 |
+
if split_model == "htdemucs":
|
189 |
+
command = f"demucs --two-stems=vocals {audio_path} -o output"
|
190 |
+
result = subprocess.run(command.split(), stdout=subprocess.PIPE)
|
191 |
+
print(result.stdout.decode())
|
192 |
+
return "output/htdemucs/youtube_audio/vocals.wav", "output/htdemucs/youtube_audio/no_vocals.wav", audio_path, "output/htdemucs/youtube_audio/vocals.wav"
|
193 |
+
else:
|
194 |
+
command = f"demucs --two-stems=vocals -n mdx_extra_q {audio_path} -o output"
|
195 |
+
result = subprocess.run(command.split(), stdout=subprocess.PIPE)
|
196 |
+
print(result.stdout.decode())
|
197 |
+
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"
|
198 |
+
else:
|
199 |
+
raise gr.Error("URL Required!")
|
200 |
+
return None, None, None, None
|
201 |
+
|
202 |
+
def combine_vocal_and_inst(audio_data, audio_volume, split_model):
|
203 |
+
if not os.path.exists("output/result"):
|
204 |
+
os.mkdir("output/result")
|
205 |
+
vocal_path = "output/result/output.wav"
|
206 |
+
output_path = "output/result/combine.mp3"
|
207 |
+
if split_model == "htdemucs":
|
208 |
+
inst_path = "output/htdemucs/youtube_audio/no_vocals.wav"
|
209 |
+
else:
|
210 |
+
inst_path = "output/mdx_extra_q/youtube_audio/no_vocals.wav"
|
211 |
+
with wave.open(vocal_path, "w") as wave_file:
|
212 |
+
wave_file.setnchannels(1)
|
213 |
+
wave_file.setsampwidth(2)
|
214 |
+
wave_file.setframerate(audio_data[0])
|
215 |
+
wave_file.writeframes(audio_data[1].tobytes())
|
216 |
+
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}'
|
217 |
+
result = subprocess.run(command.split(), stdout=subprocess.PIPE)
|
218 |
+
print(result.stdout.decode())
|
219 |
+
return output_path
|
220 |
+
|
221 |
+
def load_hubert():
|
222 |
+
global hubert_model
|
223 |
+
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
|
224 |
+
["hubert_base.pt"],
|
225 |
+
suffix="",
|
226 |
+
)
|
227 |
+
hubert_model = models[0]
|
228 |
+
hubert_model = hubert_model.to(config.device)
|
229 |
+
if config.is_half:
|
230 |
+
hubert_model = hubert_model.half()
|
231 |
+
else:
|
232 |
+
hubert_model = hubert_model.float()
|
233 |
+
hubert_model.eval()
|
234 |
+
|
235 |
+
def change_audio_mode(vc_audio_mode):
|
236 |
+
if vc_audio_mode == "Input path":
|
237 |
+
return (
|
238 |
+
# Input & Upload
|
239 |
+
gr.Textbox.update(visible=True),
|
240 |
+
gr.Audio.update(visible=False),
|
241 |
+
# Youtube
|
242 |
+
gr.Dropdown.update(visible=False),
|
243 |
+
gr.Textbox.update(visible=False),
|
244 |
+
gr.Dropdown.update(visible=False),
|
245 |
+
gr.Button.update(visible=False),
|
246 |
+
gr.Audio.update(visible=False),
|
247 |
+
gr.Audio.update(visible=False),
|
248 |
+
gr.Audio.update(visible=False),
|
249 |
+
gr.Slider.update(visible=False),
|
250 |
+
gr.Audio.update(visible=False),
|
251 |
+
gr.Button.update(visible=False),
|
252 |
+
# TTS
|
253 |
+
gr.Textbox.update(visible=False),
|
254 |
+
gr.Dropdown.update(visible=False)
|
255 |
+
)
|
256 |
+
elif vc_audio_mode == "Upload audio":
|
257 |
+
return (
|
258 |
+
# Input & Upload
|
259 |
+
gr.Textbox.update(visible=False),
|
260 |
+
gr.Audio.update(visible=True),
|
261 |
+
# Youtube
|
262 |
+
gr.Dropdown.update(visible=False),
|
263 |
+
gr.Textbox.update(visible=False),
|
264 |
+
gr.Dropdown.update(visible=False),
|
265 |
+
gr.Button.update(visible=False),
|
266 |
+
gr.Audio.update(visible=False),
|
267 |
+
gr.Audio.update(visible=False),
|
268 |
+
gr.Audio.update(visible=False),
|
269 |
+
gr.Slider.update(visible=False),
|
270 |
+
gr.Audio.update(visible=False),
|
271 |
+
gr.Button.update(visible=False),
|
272 |
+
# TTS
|
273 |
+
gr.Textbox.update(visible=False),
|
274 |
+
gr.Dropdown.update(visible=False)
|
275 |
+
)
|
276 |
+
elif vc_audio_mode == "Youtube":
|
277 |
+
return (
|
278 |
+
# Input & Upload
|
279 |
+
gr.Textbox.update(visible=False),
|
280 |
+
gr.Audio.update(visible=False),
|
281 |
+
# Youtube
|
282 |
+
gr.Dropdown.update(visible=True),
|
283 |
+
gr.Textbox.update(visible=True),
|
284 |
+
gr.Dropdown.update(visible=True),
|
285 |
+
gr.Button.update(visible=True),
|
286 |
+
gr.Audio.update(visible=True),
|
287 |
+
gr.Audio.update(visible=True),
|
288 |
+
gr.Audio.update(visible=True),
|
289 |
+
gr.Slider.update(visible=True),
|
290 |
+
gr.Audio.update(visible=True),
|
291 |
+
gr.Button.update(visible=True),
|
292 |
+
# TTS
|
293 |
+
gr.Textbox.update(visible=False),
|
294 |
+
gr.Dropdown.update(visible=False)
|
295 |
+
)
|
296 |
+
elif vc_audio_mode == "TTS Audio":
|
297 |
+
return (
|
298 |
+
# Input & Upload
|
299 |
+
gr.Textbox.update(visible=False),
|
300 |
+
gr.Audio.update(visible=False),
|
301 |
+
# Youtube
|
302 |
+
gr.Dropdown.update(visible=False),
|
303 |
+
gr.Textbox.update(visible=False),
|
304 |
+
gr.Dropdown.update(visible=False),
|
305 |
+
gr.Button.update(visible=False),
|
306 |
+
gr.Audio.update(visible=False),
|
307 |
+
gr.Audio.update(visible=False),
|
308 |
+
gr.Audio.update(visible=False),
|
309 |
+
gr.Slider.update(visible=False),
|
310 |
+
gr.Audio.update(visible=False),
|
311 |
+
gr.Button.update(visible=False),
|
312 |
+
# TTS
|
313 |
+
gr.Textbox.update(visible=True),
|
314 |
+
gr.Dropdown.update(visible=True)
|
315 |
+
)
|
316 |
+
else:
|
317 |
+
return (
|
318 |
+
# Input & Upload
|
319 |
+
gr.Textbox.update(visible=False),
|
320 |
+
gr.Audio.update(visible=True),
|
321 |
+
# Youtube
|
322 |
+
gr.Dropdown.update(visible=False),
|
323 |
+
gr.Textbox.update(visible=False),
|
324 |
+
gr.Dropdown.update(visible=False),
|
325 |
+
gr.Button.update(visible=False),
|
326 |
+
gr.Audio.update(visible=False),
|
327 |
+
gr.Audio.update(visible=False),
|
328 |
+
gr.Audio.update(visible=False),
|
329 |
+
gr.Slider.update(visible=False),
|
330 |
+
gr.Audio.update(visible=False),
|
331 |
+
gr.Button.update(visible=False),
|
332 |
+
# TTS
|
333 |
+
gr.Textbox.update(visible=False),
|
334 |
+
gr.Dropdown.update(visible=False)
|
335 |
+
)
|
336 |
+
|
337 |
+
if __name__ == '__main__':
|
338 |
+
load_hubert()
|
339 |
+
categories = load_model()
|
340 |
+
tts_voice_list = asyncio.get_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(theme=gr.themes.Base()) as app:
|
343 |
+
gr.Markdown(
|
344 |
+
"# <center> Hololive RVC Models\n"
|
345 |
+
"### <center> will update every hololive ai model that i can find or make.\n"
|
346 |
+
"[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/megaaziib)\n\n"
|
347 |
+
)
|
348 |
+
for (folder_title, folder, models) in categories:
|
349 |
+
with gr.TabItem(folder_title):
|
350 |
+
with gr.Tabs():
|
351 |
+
if not models:
|
352 |
+
gr.Markdown("# <center> No Model Loaded.")
|
353 |
+
gr.Markdown("## <center> Please add model or fix your model path.")
|
354 |
+
continue
|
355 |
+
for (name, title, author, cover, model_version, vc_fn) in models:
|
356 |
+
with gr.TabItem(name):
|
357 |
+
with gr.Row():
|
358 |
+
gr.Markdown(
|
359 |
+
'<div align="center">'
|
360 |
+
f'<div>{title}</div>\n'+
|
361 |
+
f'<div>RVC {model_version} Model</div>\n'+
|
362 |
+
(f'<div>Model author: {author}</div>' if author else "")+
|
363 |
+
(f'<img style="width:auto;height:300px;" src="file/{cover}">' if cover else "")+
|
364 |
+
'</div>'
|
365 |
+
)
|
366 |
+
with gr.Row():
|
367 |
+
with gr.Column():
|
368 |
+
vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")
|
369 |
+
# Input and Upload
|
370 |
+
vc_input = gr.Textbox(label="Input audio path", visible=False)
|
371 |
+
vc_upload = gr.Audio(label="Upload audio file", visible=True, interactive=True)
|
372 |
+
# Youtube
|
373 |
+
vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")
|
374 |
+
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=...")
|
375 |
+
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)")
|
376 |
+
vc_split = gr.Button("Split Audio", variant="primary", visible=False)
|
377 |
+
vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)
|
378 |
+
vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)
|
379 |
+
vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)
|
380 |
+
# TTS
|
381 |
+
tts_text = gr.Textbox(visible=False, label="TTS text", info="Text to speech input")
|
382 |
+
tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")
|
383 |
+
with gr.Column():
|
384 |
+
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')
|
385 |
+
f0method0 = gr.Radio(
|
386 |
+
label="Pitch extraction algorithm",
|
387 |
+
info=f0method_info,
|
388 |
+
choices=f0method_mode,
|
389 |
+
value="pm",
|
390 |
+
interactive=True
|
391 |
+
)
|
392 |
+
index_rate1 = gr.Slider(
|
393 |
+
minimum=0,
|
394 |
+
maximum=1,
|
395 |
+
label="Retrieval feature ratio",
|
396 |
+
info="Accents controling. Too high prob gonna sounds too robotic (Default: 0.4)",
|
397 |
+
value=0.4,
|
398 |
+
interactive=True,
|
399 |
+
)
|
400 |
+
filter_radius0 = gr.Slider(
|
401 |
+
minimum=0,
|
402 |
+
maximum=7,
|
403 |
+
label="Apply Median Filtering",
|
404 |
+
info="The value represents the filter radius and can reduce breathiness.",
|
405 |
+
value=1,
|
406 |
+
step=1,
|
407 |
+
interactive=True,
|
408 |
+
)
|
409 |
+
resample_sr0 = gr.Slider(
|
410 |
+
minimum=0,
|
411 |
+
maximum=48000,
|
412 |
+
label="Resample the output audio",
|
413 |
+
info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",
|
414 |
+
value=0,
|
415 |
+
step=1,
|
416 |
+
interactive=True,
|
417 |
+
)
|
418 |
+
rms_mix_rate0 = gr.Slider(
|
419 |
+
minimum=0,
|
420 |
+
maximum=1,
|
421 |
+
label="Volume Envelope",
|
422 |
+
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",
|
423 |
+
value=1,
|
424 |
+
interactive=True,
|
425 |
+
)
|
426 |
+
protect0 = gr.Slider(
|
427 |
+
minimum=0,
|
428 |
+
maximum=0.5,
|
429 |
+
label="Voice Protection",
|
430 |
+
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",
|
431 |
+
value=0.23,
|
432 |
+
step=0.01,
|
433 |
+
interactive=True,
|
434 |
+
)
|
435 |
+
with gr.Column():
|
436 |
+
vc_log = gr.Textbox(label="Output Information", interactive=False)
|
437 |
+
vc_output = gr.Audio(label="Output Audio", interactive=False)
|
438 |
+
vc_convert = gr.Button("Convert", variant="primary")
|
439 |
+
vc_volume = gr.Slider(
|
440 |
+
minimum=0,
|
441 |
+
maximum=10,
|
442 |
+
label="Vocal volume",
|
443 |
+
value=4,
|
444 |
+
interactive=True,
|
445 |
+
step=1,
|
446 |
+
info="Adjust vocal volume (Default: 4}",
|
447 |
+
visible=False
|
448 |
+
)
|
449 |
+
vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)
|
450 |
+
vc_combine = gr.Button("Combine",variant="primary", visible=False)
|
451 |
+
vc_convert.click(
|
452 |
+
fn=vc_fn,
|
453 |
+
inputs=[
|
454 |
+
vc_audio_mode,
|
455 |
+
vc_input,
|
456 |
+
vc_upload,
|
457 |
+
tts_text,
|
458 |
+
tts_voice,
|
459 |
+
vc_transform0,
|
460 |
+
f0method0,
|
461 |
+
index_rate1,
|
462 |
+
filter_radius0,
|
463 |
+
resample_sr0,
|
464 |
+
rms_mix_rate0,
|
465 |
+
protect0,
|
466 |
+
],
|
467 |
+
outputs=[vc_log ,vc_output]
|
468 |
+
)
|
469 |
+
vc_split.click(
|
470 |
+
fn=cut_vocal_and_inst,
|
471 |
+
inputs=[vc_link, vc_download_audio, vc_split_model],
|
472 |
+
outputs=[vc_vocal_preview, vc_inst_preview, vc_audio_preview, vc_input]
|
473 |
+
)
|
474 |
+
vc_combine.click(
|
475 |
+
fn=combine_vocal_and_inst,
|
476 |
+
inputs=[vc_output, vc_volume, vc_split_model],
|
477 |
+
outputs=[vc_combined_output]
|
478 |
+
)
|
479 |
+
vc_audio_mode.change(
|
480 |
+
fn=change_audio_mode,
|
481 |
+
inputs=[vc_audio_mode],
|
482 |
+
outputs=[
|
483 |
+
vc_input,
|
484 |
+
vc_upload,
|
485 |
+
vc_download_audio,
|
486 |
+
vc_link,
|
487 |
+
vc_split_model,
|
488 |
+
vc_split,
|
489 |
+
vc_vocal_preview,
|
490 |
+
vc_inst_preview,
|
491 |
+
vc_audio_preview,
|
492 |
+
vc_volume,
|
493 |
+
vc_combined_output,
|
494 |
+
vc_combine,
|
495 |
+
tts_text,
|
496 |
+
tts_voice
|
497 |
+
]
|
498 |
+
)
|
499 |
+
app.queue(concurrency_count=1, max_size=20, api_open=config.api).launch(share=config.colab)
|