|
import io |
|
|
|
import gradio as gr |
|
import librosa |
|
import numpy as np |
|
import soundfile |
|
import torch |
|
from inference.infer_tool import Svc |
|
import logging |
|
|
|
logging.getLogger('numba').setLevel(logging.WARNING) |
|
|
|
model_name = "logs/32k/tiehu.pth" |
|
config_name = "configs/tiehu.json" |
|
|
|
svc_model = Svc(model_name, config_name) |
|
sid_map = { |
|
"南云铁虎": "tiehu" |
|
} |
|
|
|
|
|
def vc_fn(sid, input_audio, vc_transform): |
|
if input_audio is None: |
|
return "You need to upload an audio", None |
|
sampling_rate, audio = input_audio |
|
|
|
duration = audio.shape[0] / sampling_rate |
|
if duration > 45: |
|
return "请上传小于45s的音频,需要转换长音频请本地进行转换", None |
|
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32) |
|
if len(audio.shape) > 1: |
|
audio = librosa.to_mono(audio.transpose(1, 0)) |
|
if sampling_rate != 16000: |
|
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000) |
|
print(audio.shape) |
|
out_wav_path = io.BytesIO() |
|
soundfile.write(out_wav_path, audio, 16000, format="wav") |
|
out_wav_path.seek(0) |
|
|
|
sid = sid_map[sid] |
|
out_audio, out_sr = svc_model.infer(sid, vc_transform, out_wav_path) |
|
_audio = out_audio.cpu().numpy() |
|
return "Success", (32000, _audio) |
|
|
|
|
|
app = gr.Blocks() |
|
with app: |
|
with gr.Tabs(): |
|
with gr.TabItem("Basic"): |
|
gr.Markdown(value=""" |
|
|
|
南云铁虎Sovits3.0模型 |
|
如需本地使用,下载files里configs文件夹中.json格式文件, |
|
logs/32k文件夹中.pth格式文件 |
|
3.0.zip文件并解压,查看说明.txt文件 |
|
|
|
项目改写基于 https://huggingface.co/spaces/innnky/nyaru-svc-3.0 |
|
|
|
模型使用协议(重要): |
|
1.请勿用于商业目的 |
|
2.请勿用于会影响本人的行为(比如冒充本人发表争议言论) |
|
3.请勿用于血腥、暴力、性相关、政治相关内容 |
|
4.非个人使用场合请注明模型作者 |
|
5.允许用于个人娱乐场景下的游戏语音、直播活动 |
|
sid = gr.Dropdown(label="音色", choices=["南云铁虎"], value="tiehu") |
|
vc_input3 = gr.Audio(label="上传音频(长度小于45秒)") |
|
vc_transform = gr.Number(label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0) |
|
vc_submit = gr.Button("转换", variant="primary") |
|
vc_output1 = gr.Textbox(label="Output Message") |
|
vc_output2 = gr.Audio(label="Output Audio") |
|
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform], [vc_output1, vc_output2]) |
|
|
|
app.launch() |
|
|