Spaces:
Runtime error
Runtime error
File size: 5,747 Bytes
6b89d0b c6293ee 6b89d0b c6293ee 6b89d0b f1b7e70 6b89d0b aa1d4f2 6b89d0b aa1d4f2 6b89d0b aa1d4f2 6b89d0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
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
###################################################
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'}
}
print(spk_dict)
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)
print(svc_model)
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 # 音高调整,支持正负(半音)
# 加速倍数
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)
f0_gen,_=get_pitch_parselmouth(*svc_model.vocoder.wav2spec(wav_gen),hparams)
f0_tst[f0_tst==0]=np.nan#ground truth f0
f0_pred[f0_pred==0]=np.nan#f0 pe predicted
f0_gen[f0_gen==0]=np.nan#f0 generated
fig=plt.figure(figsize=[15,5])
plt.plot(np.arange(0,len(f0_tst)),f0_tst,color='black')
plt.plot(np.arange(0,len(f0_pred)),f0_pred,color='orange')
plt.plot(np.arange(0,len(f0_gen)),f0_gen,color='red')
plt.axhline(librosa.note_to_hz('C4'),ls=":",c="blue")
plt.axhline(librosa.note_to_hz('G4'),ls=":",c="green")
plt.axhline(librosa.note_to_hz('C5'),ls=":",c="orange")
plt.axhline(librosa.note_to_hz('F#5'),ls=":",c="red")
#plt.axhline(librosa.note_to_hz('A#5'),ls=":",c="black")
plt.savefig('./temp.png')
return "Success", (hparams['audio_sample_rate'], audio), gr.Image.update("temp.png")
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, f0_image])
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()
|