skyboundtrailer/RVC-models-mega-collections-v2
0
1from __future__ import unicode_literals2 3import os4import glob5import json6import traceback7import logging8import gradio as gr9import numpy as np10import librosa11import torch12import asyncio13import edge_tts14import yt_dlp15import ffmpeg16import subprocess17import sys18import io19import wave20from datetime import datetime21from fairseq import checkpoint_utils22from lib.infer_pack.models import (23 SynthesizerTrnMs256NSFsid,24 SynthesizerTrnMs256NSFsid_nono,25 SynthesizerTrnMs768NSFsid,26 SynthesizerTrnMs768NSFsid_nono,27)28from vc_infer_pipeline import VC29from config import Config30config = Config()31logging.getLogger("numba").setLevel(logging.WARNING)32spaces = os.getenv("SYSTEM") == "spaces"33force_support = None34if config.unsupported is False:35 if config.device == "mps" or config.device == "cpu":36 force_support = False37else:38 force_support = True39 40audio_mode = []41f0method_mode = []42f0method_info = ""43 44if force_support is False or spaces is True:45 if spaces is True:46 audio_mode = ["Upload audio", "TTS Audio"]47 else:48 audio_mode = ["Input path", "Upload audio", "TTS Audio"]49 f0method_mode = ["pm", "harvest"]50 f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better). (Default: PM)"51else:52 audio_mode = ["Input path", "Upload audio", "Youtube", "TTS Audio"]53 f0method_mode = ["pm", "harvest", "crepe"]54 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)"55 56if os.path.isfile("rmvpe.pt"):57 f0method_mode.insert(2, "rmvpe")58 59def create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, file_index):60 def vc_fn(61 vc_audio_mode,62 vc_input, 63 vc_upload,64 tts_text,65 tts_voice,66 tts_rate,67 f0_up_key,68 f0_method,69 index_rate,70 filter_radius,71 resample_sr,72 rms_mix_rate,73 protect,74 ):75 try:76 logs = []77 print(f"Converting using {model_name}...")78 logs.append(f"Converting using {model_name}...")79 yield "\n".join(logs), None80 if vc_audio_mode == "Input path" or "Youtube" and vc_input != "":81 audio, sr = librosa.load(vc_input, sr=16000, mono=True)82 elif vc_audio_mode == "Upload audio":83 if vc_upload is None:84 return "You need to upload an audio", None85 sampling_rate, audio = vc_upload86 duration = audio.shape[0] / sampling_rate87 if duration > 20 and spaces:88 return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None89 audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)90 if len(audio.shape) > 1:91 audio = librosa.to_mono(audio.transpose(1, 0))92 if sampling_rate != 16000:93 audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)94 elif vc_audio_mode == "TTS Audio":95 if len(tts_text) > 100 and spaces:96 return "Text is too long", None97 if tts_text is None or tts_voice is None:98 return "You need to enter text and select a voice", None99 inc_rate = "+0%"100 if tts_rate < 0 :101 inc_rate = (f"{round(tts_rate)}%")102 else:103 inc_rate = (f"+{round(tts_rate)}%")104 105 asyncio.run(edge_tts.Communicate(text=tts_text, voice= "-".join(tts_voice.split('-')[:-1]), rate= inc_rate).save("tts.mp3"))106 audio, sr = librosa.load("tts.mp3", sr=16000, mono=True)107 vc_input = "tts.mp3"108 times = [0, 0, 0]109 f0_up_key = int(f0_up_key)110 audio_opt = vc.pipeline(111 hubert_model,112 net_g,113 0,114 audio,115 vc_input,116 times,117 f0_up_key,118 f0_method,119 file_index,120 # file_big_npy,121 index_rate,122 if_f0,123 filter_radius,124 tgt_sr,125 resample_sr,126 rms_mix_rate,127 version,128 protect,129 f0_file=None,130 )131 info = f"[{datetime.now().strftime('%Y-%m-%d %H:%M')}]: npy: {times[0]}, f0: {times[1]}s, infer: {times[2]}s"132 print(f"{model_name} | {info}")133 logs.append(f"Successfully Convert {model_name}\n{info}")134 yield "\n".join(logs), (tgt_sr, audio_opt)135 except Exception as err:136 info = traceback.format_exc()137 print(info)138 primt(f"Error when using {model_name}.\n{str(err)}")139 yield info, None140 return vc_fn141 142def load_model():143 categories = []144 if os.path.isfile("weights/folder_info.json"):145 for _, w_dirs, _ in os.walk(f"weights"):146 category_count_total = len(w_dirs)147 category_count = 1148 with open("weights/folder_info.json", "r", encoding="utf-8") as f:149 folder_info = json.load(f)150 for category_name, category_info in folder_info.items():151 if not category_info['enable']:152 continue153 category_title = category_info['title']154 category_folder = category_info['folder_path']155 description = category_info['description']156 print(f"Load {category_title} [{category_count}/{category_count_total}]")157 models = []158 for _, m_dirs, _ in os.walk(f"weights/{category_folder}"):159 model_count_total = len(m_dirs)160 model_count = 1161 with open(f"weights/{category_folder}/model_info.json", "r", encoding="utf-8") as f:162 models_info = json.load(f)163 for character_name, info in models_info.items():164 if not info['enable']:165 continue166 model_title = info['title']167 model_name = info['model_path']168 model_author = info.get("author", None)169 model_cover = f"weights/{category_folder}/{character_name}/{info['cover']}"170 model_index = f"weights/{category_folder}/{character_name}/{info['feature_retrieval_library']}"171 cpt = torch.load(f"weights/{category_folder}/{character_name}/{model_name}", map_location="cpu")172 tgt_sr = cpt["config"][-1]173 cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk174 if_f0 = cpt.get("f0", 1)175 version = cpt.get("version", "v1")176 if version == "v1":177 if if_f0 == 1:178 net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)179 else:180 net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])181 model_version = "V1"182 elif version == "v2":183 if if_f0 == 1:184 net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)185 else:186 net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])187 model_version = "V2"188 del net_g.enc_q189 print(net_g.load_state_dict(cpt["weight"], strict=False))190 net_g.eval().to(config.device)191 if config.is_half:192 net_g = net_g.half()193 else:194 net_g = net_g.float()195 vc = VC(tgt_sr, config)196 print(f"Model loaded [{model_count}/{model_count_total}]: {character_name} / {info['feature_retrieval_library']} | ({model_version})")197 model_count += 1198 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)))199 category_count += 1200 categories.append([category_title, description, models])201 elif os.path.exists("weights"):202 models = []203 for w_root, w_dirs, _ in os.walk("weights"):204 model_count = 1205 for sub_dir in w_dirs:206 pth_files = glob.glob(f"weights/{sub_dir}/*.pth")207 index_files = glob.glob(f"weights/{sub_dir}/*.index")208 if pth_files == []:209 print(f"Model [{model_count}/{len(w_dirs)}]: No Model file detected, skipping...")210 continue211 cpt = torch.load(pth_files[0])212 tgt_sr = cpt["config"][-1]213 cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk214 if_f0 = cpt.get("f0", 1)215 version = cpt.get("version", "v1")216 if version == "v1":217 if if_f0 == 1:218 net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)219 else:220 net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])221 model_version = "V1"222 elif version == "v2":223 if if_f0 == 1:224 net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)225 else:226 net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])227 model_version = "V2"228 del net_g.enc_q229 print(net_g.load_state_dict(cpt["weight"], strict=False))230 net_g.eval().to(config.device)231 if config.is_half:232 net_g = net_g.half()233 else:234 net_g = net_g.float()235 vc = VC(tgt_sr, config)236 if index_files == []:237 print("Warning: No Index file detected!")238 index_info = "None"239 model_index = ""240 else:241 index_info = index_files[0]242 model_index = index_files[0]243 print(f"Model loaded [{model_count}/{len(w_dirs)}]: {index_files[0]} / {index_info} | ({model_version})")244 model_count += 1245 models.append((index_files[0][:-4], index_files[0][:-4], "", "", model_version, create_vc_fn(index_files[0], tgt_sr, net_g, vc, if_f0, version, model_index)))246 categories.append(["Models", "", models])247 else:248 categories = []249 return categories250 251def download_audio(url, audio_provider):252 logs = []253 if url == "":254 logs.append("URL required!")255 yield None, "\n".join(logs)256 return None, "\n".join(logs)257 if not os.path.exists("dl_audio"):258 os.mkdir("dl_audio")259 if audio_provider == "Youtube":260 logs.append("Downloading the audio...")261 yield None, "\n".join(logs)262 ydl_opts = {263 'noplaylist': True,264 'format': 'bestaudio/best',265 'postprocessors': [{266 'key': 'FFmpegExtractAudio',267 'preferredcodec': 'wav',268 }],269 "outtmpl": 'dl_audio/audio',270 }271 audio_path = "dl_audio/audio.wav"272 with yt_dlp.YoutubeDL(ydl_opts) as ydl:273 ydl.download([url])274 logs.append("Download Complete.")275 yield audio_path, "\n".join(logs)276 277def cut_vocal_and_inst(split_model):278 logs = []279 logs.append("Starting the audio splitting process...")280 yield "\n".join(logs), None, None, None281 command = f"demucs --two-stems=vocals -n {split_model} dl_audio/audio.wav -o output"282 result = subprocess.Popen(command.split(), stdout=subprocess.PIPE, text=True)283 for line in result.stdout:284 logs.append(line)285 yield "\n".join(logs), None, None, None286 print(result.stdout)287 vocal = f"output/{split_model}/audio/vocals.wav"288 inst = f"output/{split_model}/audio/no_vocals.wav"289 logs.append("Audio splitting complete.")290 yield "\n".join(logs), vocal, inst, vocal291 292def combine_vocal_and_inst(audio_data, vocal_volume, inst_volume, split_model):293 if not os.path.exists("output/result"):294 os.mkdir("output/result")295 vocal_path = "output/result/output.wav"296 output_path = "output/result/combine.mp3"297 inst_path = f"output/{split_model}/audio/no_vocals.wav"298 with wave.open(vocal_path, "w") as wave_file:299 wave_file.setnchannels(1) 300 wave_file.setsampwidth(2)301 wave_file.setframerate(audio_data[0])302 wave_file.writeframes(audio_data[1].tobytes())303 command = f'ffmpeg -y -i {inst_path} -i {vocal_path} -filter_complex [0:a]volume={inst_volume}[i];[1:a]volume={vocal_volume}[v];[i][v]amix=inputs=2:duration=longest[a] -map [a] -b:a 320k -c:a libmp3lame {output_path}'304 result = subprocess.run(command.split(), stdout=subprocess.PIPE)305 print(result.stdout.decode())306 return output_path307 308def load_hubert():309 global hubert_model310 models, _, _ = checkpoint_utils.load_model_ensemble_and_task(311 ["hubert_base.pt"],312 suffix="",313 )314 hubert_model = models[0]315 hubert_model = hubert_model.to(config.device)316 if config.is_half:317 hubert_model = hubert_model.half()318 else:319 hubert_model = hubert_model.float()320 hubert_model.eval()321 322def change_audio_mode(vc_audio_mode):323 if vc_audio_mode == "Input path":324 return (325 # Input & Upload326 gr.Textbox.update(visible=True),327 gr.Checkbox.update(visible=False),328 gr.Audio.update(visible=False),329 # Youtube330 gr.Dropdown.update(visible=False),331 gr.Textbox.update(visible=False),332 gr.Textbox.update(visible=False),333 gr.Button.update(visible=False),334 # Splitter335 gr.Dropdown.update(visible=False),336 gr.Textbox.update(visible=False),337 gr.Button.update(visible=False),338 gr.Audio.update(visible=False),339 gr.Audio.update(visible=False),340 gr.Audio.update(visible=False),341 gr.Slider.update(visible=False),342 gr.Slider.update(visible=False),343 gr.Audio.update(visible=False),344 gr.Button.update(visible=False),345 # TTS346 gr.Textbox.update(visible=False),347 gr.Dropdown.update(visible=False),348 gr.Number.update(visible=False)349 )350 elif vc_audio_mode == "Upload audio":351 return (352 # Input & Upload353 gr.Textbox.update(visible=False),354 gr.Checkbox.update(visible=True),355 gr.Audio.update(visible=True),356 # Youtube357 gr.Dropdown.update(visible=False),358 gr.Textbox.update(visible=False),359 gr.Textbox.update(visible=False),360 gr.Button.update(visible=False),361 # Splitter362 gr.Dropdown.update(visible=False),363 gr.Textbox.update(visible=False),364 gr.Button.update(visible=False),365 gr.Audio.update(visible=False),366 gr.Audio.update(visible=False),367 gr.Audio.update(visible=False),368 gr.Slider.update(visible=False),369 gr.Slider.update(visible=False),370 gr.Audio.update(visible=False),371 gr.Button.update(visible=False),372 # TTS373 gr.Textbox.update(visible=False),374 gr.Dropdown.update(visible=False),375 gr.Number.update(visible=False)376 )377 elif vc_audio_mode == "Youtube":378 return (379 # Input & Upload380 gr.Textbox.update(visible=False),381 gr.Checkbox.update(visible=False),382 gr.Audio.update(visible=False),383 # Youtube384 gr.Dropdown.update(visible=True),385 gr.Textbox.update(visible=True),386 gr.Textbox.update(visible=True),387 gr.Button.update(visible=True),388 # Splitter389 gr.Dropdown.update(visible=True),390 gr.Textbox.update(visible=True),391 gr.Button.update(visible=True),392 gr.Audio.update(visible=True),393 gr.Audio.update(visible=True),394 gr.Audio.update(visible=True),395 gr.Slider.update(visible=True),396 gr.Slider.update(visible=True),397 gr.Audio.update(visible=True),398 gr.Button.update(visible=True),399 # TTS400 gr.Textbox.update(visible=False),401 gr.Dropdown.update(visible=False),402 gr.Number.update(visible=False)403 )404 elif vc_audio_mode == "TTS Audio":405 return (406 # Input & Upload407 gr.Textbox.update(visible=False),408 gr.Checkbox.update(visible=False),409 gr.Audio.update(visible=False),410 # Youtube411 gr.Dropdown.update(visible=False),412 gr.Textbox.update(visible=False),413 gr.Textbox.update(visible=False),414 gr.Button.update(visible=False),415 # Splitter416 gr.Dropdown.update(visible=False),417 gr.Textbox.update(visible=False),418 gr.Button.update(visible=False),419 gr.Audio.update(visible=False),420 gr.Audio.update(visible=False),421 gr.Audio.update(visible=False),422 gr.Slider.update(visible=False),423 gr.Slider.update(visible=False),424 gr.Audio.update(visible=False),425 gr.Button.update(visible=False),426 # TTS427 gr.Textbox.update(visible=True),428 gr.Dropdown.update(visible=True),429 gr.Number.update(visible=True)430 )431 432def use_microphone(microphone):433 if microphone == True:434 return gr.Audio.update(source="microphone")435 else:436 return gr.Audio.update(source="upload")437 438 439 440# Audio Tool Functions441 442# cvt audio443 444from pydub import AudioSegment445def convert_audio(url,title):446 447 # Mendefinisikan path untuk file audio448 input_path = url449 file_name = os.path.basename(input_path)450 filename = os.path.splitext(file_name)[0]451 452 453 parent_dir = os.path.dirname(url)454 new_path = os.path.relpath(parent_dir, "")455 456 457 458 output_path = f'youtubeaudio/{title}_converted.mp3'459 460 # Mengkonversi file audio WAV menjadi MP3 menggunakan pydub461 sound = AudioSegment.from_wav(input_path)462 sound.export(output_path, format="mp3")463 464 # Mengecek apakah file audio MP3 sudah tersimpan465 if os.path.isfile(output_path):466 # return output_path467 return "sukses"468 else:469 return "Konversi gagal"470 471 472# Fungsi play Audio473def play_audio(url):474 475 file_path = url476 file_name = os.path.basename(file_path)477 filename = os.path.splitext(file_name)[0]478 479 original_path = f"/content/youtubeaudio/{filename}.wav"480 vocal_path = f"/content/separated/htdemucs/{filename}/vocals.wav"481 instrument_path = f"/content/separated/htdemucs/{filename}/no_vocals.wav"482 483 return url484 485 486 487# Fungsi download audio488 489import yt_dlp490import ffmpeg491import sys492 493 494def download_audio(title, url):495 496 ydl_opts = {497 'format': 'bestaudio/best',498 # 'outtmpl': 'output.%(ext)s',499 'postprocessors': [{500 'key': 'FFmpegExtractAudio',501 'preferredcodec': 'wav',502 }],503 "outtmpl": f'youtubeaudio/{title}', # this is where you can edit how you'd like the filenames to be formatted504 }505 506 with yt_dlp.YoutubeDL(ydl_opts) as ydl:507 # url = "https://www.youtube.com/watch?v=LCcNtQuhUgg" #@param {type:"string"}508 ydl.download([url])509 # return f"/content/youtubeaudio/{title}.wav"510 # return f"/content/youtubeaudio/adudio.wav"511 return "sukses"512 513#fungsi download video514def download_video(url, resolution):515 516 from pytube import YouTube517 518 yt = YouTube(url)519 try:520 stream_check = yt.streams.filter(res=f"{resolution}p")521 if len(stream_check) > 0:522 stream = yt.streams.filter(file_extension='mp4', res=f'{resolution}p').first()523 else:524 stream = yt.streams.get_highest_resolution()525 except Exception as e:526 return "error"527 528 529 530 531 folder_path = 'youtubevideo'532 if not os.path.exists(folder_path):533 os.makedirs(folder_path)534 535 file_path = os.path.join(folder_path, stream.default_filename)536 stream.download(output_path=folder_path, filename=stream.default_filename)537 538 return "sukses"539 540 541# fungsi split audio542def split_audio(url):543 import subprocess544 545 command = f"demucs --two-stems=vocals {url}"546 result = subprocess.run(command.split(), stdout=subprocess.PIPE)547 print(result.stdout.decode())548 return "sukses"549 550 551def aio(title, yt_url):552 download_status = download_audio(title, yt_url)553 554 audio_url = f"youtubeaudio/{title}.wav"555 split_status = split_audio(audio_url)556 557 vocal_url = f"separated/htdemucs/{title}/vocals.wav"558 no_vocal_url = f"separated/htdemucs/{title}/no_vocals.wav"559 560 vocal_convert_status = convert_audio(vocal_url, title+"_vocal")561 no_vocal_convert_status = convert_audio(no_vocal_url, title+"_instrumen")562 563 import os564 565 # specify old file path name566 # old_vocal_name = f"separated/htdemucs/{title}/vocals_converted.mp3"567 # old_instrumen_name = f"separated/htdemucs/{title}/no_vocals_converted.mp3"568 569 570 # Specify the new file path and name571 # new_vocal_name = f"separated/htdemucs/{title}/{title}_vocal.mp3"572 # new_instrumen_name = f"separated/htdemucs/{title}/{title}_instrumen.mp3"573 574 # Rename the file separated575 # os.rename(old_vocal_name, new_vocal_name)576 # os.rename(old_instrumen_name, new_instrumen_name)577 578 579 return "sukses"580 581 582 583 584if __name__ == '__main__':585 load_hubert()586 categories = load_model()587 tts_voice_list = asyncio.new_event_loop().run_until_complete(edge_tts.list_voices())588 voices = [f"{v['ShortName']}-{v['Gender']}" for v in tts_voice_list]589 with gr.Blocks() as app:590 gr.Markdown(591 "<div align='center'>\n\n"+592 "# RVC Genshin Impact\n\n"+593 "### Recommended to use Google Colab to use other character and feature.\n\n"+594 "[](https://colab.research.google.com/drive/110kiMZTdP6Ri1lY9-NbQf17GVPPhHyeT?usp=sharing)\n\n"+595 "</div>\n\n"+596 "[](https://github.com/ArkanDash/Multi-Model-RVC-Inference)"597 )598 if categories == []:599 gr.Markdown(600 "<div align='center'>\n\n"+601 "## No model found, please add the model into weights folder\n\n"+602 "</div>"603 )604 for (folder_title, description, models) in categories:605 with gr.TabItem(folder_title):606 if description:607 gr.Markdown(f"### <center> {description}")608 with gr.Tabs():609 if not models:610 gr.Markdown("# <center> No Model Loaded.")611 gr.Markdown("## <center> Please add the model or fix your model path.")612 continue613 for (name, title, author, cover, model_version, vc_fn) in models:614 with gr.TabItem(name):615 with gr.Row():616 gr.Markdown(617 '<div align="center">'618 f'<div>{title}</div>\n'+619 f'<div>RVC {model_version} Model</div>\n'+620 (f'<div>Model author: {author}</div>' if author else "")+621 (f'<img style="width:auto;height:300px;" src="file/{cover}">' if cover else "")+622 '</div>'623 )624 with gr.Row():625 if spaces is False:626 with gr.TabItem("Input"):627 with gr.Row():628 with gr.Column():629 vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")630 # Input631 vc_input = gr.Textbox(label="Input audio path", visible=False)632 # Upload633 vc_microphone_mode = gr.Checkbox(label="Use Microphone", value=False, visible=True, interactive=True)634 vc_upload = gr.Audio(label="Upload audio file", source="upload", visible=True, interactive=True)635 # Youtube636 vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")637 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=...")638 vc_log_yt = gr.Textbox(label="Output Information", visible=False, interactive=False)639 vc_download_button = gr.Button("Download Audio", variant="primary", visible=False)640 vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)641 # TTS642 tts_text = gr.Textbox(label="TTS text", value="hello world", info="Text to speech input", visible=False)643 tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")644 tts_rate = gr.Number(label="TTS Rate", value = 0 ,info='Change to increase tts speed (0 = normal)', visible=False)645 with gr.Column():646 vc_split_model = gr.Dropdown(label="Splitter Model", choices=["hdemucs_mmi", "htdemucs", "htdemucs_ft", "mdx", "mdx_q", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", info="Select the splitter model (Default: htdemucs)")647 vc_split_log = gr.Textbox(label="Output Information", visible=False, interactive=False)648 vc_split = gr.Button("Split Audio", variant="primary", visible=False)649 vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)650 vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)651 with gr.TabItem("Convert"):652 with gr.Row():653 with gr.Column():654 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')655 f0method0 = gr.Radio(656 label="Pitch extraction algorithm",657 info=f0method_info,658 choices=f0method_mode,659 value="pm",660 interactive=True661 )662 index_rate1 = gr.Slider(663 minimum=0,664 maximum=1,665 label="Retrieval feature ratio",666 info="(Default: 0.7)",667 value=0.7,668 interactive=True,669 )670 filter_radius0 = gr.Slider(671 minimum=0,672 maximum=7,673 label="Apply Median Filtering",674 info="The value represents the filter radius and can reduce breathiness.",675 value=3,676 step=1,677 interactive=True,678 )679 resample_sr0 = gr.Slider(680 minimum=0,681 maximum=48000,682 label="Resample the output audio",683 info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",684 value=0,685 step=1,686 interactive=True,687 )688 rms_mix_rate0 = gr.Slider(689 minimum=0,690 maximum=1,691 label="Volume Envelope",692 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",693 value=1,694 interactive=True,695 )696 protect0 = gr.Slider(697 minimum=0,698 maximum=0.5,699 label="Voice Protection",700 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",701 value=0.5,702 step=0.01,703 interactive=True,704 )705 with gr.Column():706 vc_log = gr.Textbox(label="Output Information", interactive=False)707 vc_output = gr.Audio(label="Output Audio", interactive=False)708 vc_convert = gr.Button("Convert", variant="primary")709 vc_vocal_volume = gr.Slider(710 minimum=0,711 maximum=10,712 label="Vocal volume",713 value=1,714 interactive=True,715 step=1,716 info="Adjust vocal volume (Default: 1}",717 visible=False718 )719 vc_inst_volume = gr.Slider(720 minimum=0,721 maximum=10,722 label="Instrument volume",723 value=1,724 interactive=True,725 step=1,726 info="Adjust instrument volume (Default: 1}",727 visible=False728 )729 vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)730 vc_combine = gr.Button("Combine",variant="primary", visible=False)731 else:732 with gr.Column():733 vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")734 # Input735 vc_input = gr.Textbox(label="Input audio path", visible=False)736 # Upload737 vc_microphone_mode = gr.Checkbox(label="Use Microphone", value=False, visible=True, interactive=True)738 vc_upload = gr.Audio(label="Upload audio file", source="upload", visible=True, interactive=True)739 # Youtube740 vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")741 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=...")742 vc_log_yt = gr.Textbox(label="Output Information", visible=False, interactive=False)743 vc_download_button = gr.Button("Download Audio", variant="primary", visible=False)744 vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)745 # Splitter746 vc_split_model = gr.Dropdown(label="Splitter Model", choices=["hdemucs_mmi", "htdemucs", "htdemucs_ft", "mdx", "mdx_q", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", info="Select the splitter model (Default: htdemucs)")747 vc_split_log = gr.Textbox(label="Output Information", visible=False, interactive=False)748 vc_split = gr.Button("Split Audio", variant="primary", visible=False)749 vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)750 vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)751 # TTS752 tts_text = gr.Textbox(label="TTS text", info="Text to speech input", visible=False)753 tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")754 with gr.Column():755 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')756 f0method0 = gr.Radio(757 label="Pitch extraction algorithm",758 info=f0method_info,759 choices=f0method_mode,760 value="pm",761 interactive=True762 )763 index_rate1 = gr.Slider(764 minimum=0,765 maximum=1,766 label="Retrieval feature ratio",767 info="(Default: 0.7)",768 value=0.7,769 interactive=True,770 )771 filter_radius0 = gr.Slider(772 minimum=0,773 maximum=7,774 label="Apply Median Filtering",775 info="The value represents the filter radius and can reduce breathiness.",776 value=3,777 step=1,778 interactive=True,779 )780 resample_sr0 = gr.Slider(781 minimum=0,782 maximum=48000,783 label="Resample the output audio",784 info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",785 value=0,786 step=1,787 interactive=True,788 )789 rms_mix_rate0 = gr.Slider(790 minimum=0,791 maximum=1,792 label="Volume Envelope",793 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",794 value=1,795 interactive=True,796 )797 protect0 = gr.Slider(798 minimum=0,799 maximum=0.5,800 label="Voice Protection",801 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",802 value=0.5,803 step=0.01,804 interactive=True,805 )806 with gr.Column():807 vc_log = gr.Textbox(label="Output Information", interactive=False)808 vc_output = gr.Audio(label="Output Audio", interactive=False)809 vc_convert = gr.Button("Convert", variant="primary")810 vc_vocal_volume = gr.Slider(811 minimum=0,812 maximum=10,813 label="Vocal volume",814 value=1,815 interactive=True,816 step=1,817 info="Adjust vocal volume (Default: 1}",818 visible=False819 )820 vc_inst_volume = gr.Slider(821 minimum=0,822 maximum=10,823 label="Instrument volume",824 value=1,825 interactive=True,826 step=1,827 info="Adjust instrument volume (Default: 1}",828 visible=False829 )830 vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)831 vc_combine = gr.Button("Combine",variant="primary", visible=False)832 vc_convert.click(833 fn=vc_fn, 834 inputs=[835 vc_audio_mode,836 vc_input,837 vc_upload,838 tts_text,839 tts_voice,840 tts_rate,841 vc_transform0,842 f0method0,843 index_rate1,844 filter_radius0,845 resample_sr0,846 rms_mix_rate0,847 protect0,848 ], 849 outputs=[vc_log ,vc_output]850 )851 vc_download_button.click(852 fn=download_audio, 853 inputs=[vc_link, vc_download_audio], 854 outputs=[vc_audio_preview, vc_log_yt]855 )856 vc_split.click(857 fn=cut_vocal_and_inst, 858 inputs=[vc_split_model], 859 outputs=[vc_split_log, vc_vocal_preview, vc_inst_preview, vc_input]860 )861 vc_combine.click(862 fn=combine_vocal_and_inst,863 inputs=[vc_output, vc_vocal_volume, vc_inst_volume, vc_split_model],864 outputs=[vc_combined_output]865 )866 vc_microphone_mode.change(867 fn=use_microphone,868 inputs=vc_microphone_mode,869 outputs=vc_upload870 )871 vc_audio_mode.change(872 fn=change_audio_mode,873 inputs=[vc_audio_mode],874 outputs=[875 vc_input,876 vc_microphone_mode,877 vc_upload,878 vc_download_audio,879 vc_link,880 vc_log_yt,881 vc_download_button,882 vc_split_model,883 vc_split_log,884 vc_split,885 vc_audio_preview,886 vc_vocal_preview,887 vc_inst_preview,888 vc_vocal_volume,889 vc_inst_volume,890 vc_combined_output,891 vc_combine,892 tts_text,893 tts_voice,894 tts_rate895 ]896 )897 # Audio tool898 899 with gr.Tab("AIO"):900 with gr.Row():901 with gr.Column():902 aio_input = [gr.Textbox(label = "title"), gr.Textbox(label = "Youtube Url")]903 aio_button = gr.Button("Procces")904 with gr.Column():905 aio_output =[gr.Textbox(label = "Status Output")]906 907 aio_button.click(aio, inputs=aio_input, outputs=aio_output)908 909 910 app.queue(concurrency_count=5, max_size=50, api_open=config.api).launch(share=config.share, debug=True)