import gradio as gr import pandas as pd import numpy as np import matplotlib.pyplot as plt import json import os import tempfile import shutil import requests from pathlib import Path global ckpt_temp_file global audio_temp_file global config_temp_file ################################################### from utils.hparams import hparams from preprocessing.data_gen_utils import get_pitch_parselmouth,get_pitch_crepe import numpy as np import matplotlib.pyplot as plt import IPython.display as ipd import utils import librosa import torchcrepe from infer import * import logging from infer_tools.infer_tool import * import io spk_dict = { "雷电将军": {"model_name": './models/genshin/raiden.ckpt', "config_name": './models/genshin/config.yaml'} } project_name = "Unnamed" model_path = spk_dict['雷电将军']['model_name'] config_path= spk_dict['雷电将军']['config_name'] hubert_gpu = False svc_model = Svc(project_name, config_path, hubert_gpu, model_path) def vc_fn(sid, audio_record, audio_upload, tran, pndm_speedup=20): print(sid) if audio_upload is not None: audio_path = audio_upload elif audio_record is not None: audio_path = audio_record else: return "你需要上传wav文件或使用网页内置的录音!", None tran = int(tran) pndm_speedup = int(pndm_speedup) print('model loaded') # demoaudio, sr = librosa.load(audio_path) key = tran # 音高调整,支持正负(半音) # 加速倍数 pndm_speedup = 20 wav_gen='queeeeee.wav' # Show the spinner and run the run_clip function inside the 'with' block f0_tst, f0_pred, audio = run_clip(svc_model, file_path=audio_path, key=key, acc=pndm_speedup, use_crepe=True, use_pe=True, thre=0.05, use_gt_mel=False, add_noise_step=500, project_name=project_name, out_path=wav_gen) return "Success", (hparams['audio_sample_rate'], audio) app = gr.Blocks() with app: with gr.Tabs(): with gr.TabItem("Basic"): gr.Markdown(value=""" 本模型为sovits_f0(含AI猫雷2.0音色),支持**60s以内**的**无伴奏**wav、mp3(单声道)格式,或使用**网页内置**的录音(二选一) 转换效果取决于源音频语气、节奏是否与目标音色相近,以及音域是否超出目标音色音域范围 猫雷音色低音音域效果不佳,如转换男声歌声,建议变调升 **6-10key** 该模型的 [github仓库链接](https://github.com/innnky/so-vits-svc),如果想自己制作并训练模型可以访问这个 [github仓库](https://github.com/IceKyrin/sovits_guide) """) speaker_id = gr.Dropdown(label="音色", choices=['雷电将军'], value="雷电将军") record_input = gr.Audio(source="microphone", label="录制你的声音", type="filepath", elem_id="audio_inputs") upload_input = gr.Audio(source="upload", label="上传音频(长度小于60秒)", type="filepath", elem_id="audio_inputs") vc_transform = gr.Number(label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0) vc_speedup = gr.Number(label="加速倍数", value=20) vc_submit = gr.Button("转换", variant="primary") out_audio = gr.Audio(label="Output Audio") gr.Markdown(value=""" 输出信息为音高平均偏差半音数量,体现转换音频的跑调情况(一般平均小于0.5个半音) """) out_message = gr.Textbox(label="Output") gr.Markdown(value="""f0曲线可以直观的显示跑调情况,蓝色为输入音高,橙色为合成音频的音高 若**只看见橙色**,说明蓝色曲线被覆盖,转换效果较好 """) # f0_image = gr.Image(label="f0曲线") vc_submit.click(vc_fn, [speaker_id, record_input, upload_input, vc_transform, vc_speedup], [out_message, out_audio]) with gr.TabItem("使用说明"): gr.Markdown(value=""" 0、合集:https://github.com/IceKyrin/sovits_guide/blob/main/README.md 1、仅支持sovit_f0(sovits2.0)模型 2、自行下载hubert-soft-0d54a1f4.pt改名为hubert.pt放置于pth文件夹下(已经下好了) https://github.com/bshall/hubert/releases/tag/v0.1 3、pth文件夹下放置sovits2.0的模型 4、与模型配套的xxx.json,需有speaker项——人物列表 5、放无伴奏的音频、或网页内置录音,不要放奇奇怪怪的格式 6、仅供交流使用,不对用户行为负责 """) app.launch()