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