Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
NaruseMioShirakana authored Jan 16, 2023
1 parent 6857d54 commit 7ccf1f2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions sovits_gradio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from inference.infer_tool_grad import VitsSvc
import gradio as gr
import os

class VitsGradio:
def __init__(self):
self.so = VitsSvc()
self.lspk = []
self.modelPaths = []
for root,dirs,files in os.walk("checkpoints"):
for dir in dirs:
self.modelPaths.append(dir)
with gr.Blocks() as self.Vits:
with gr.Tab("VoiceConversion"):
with gr.Row(visible=False) as self.VoiceConversion:
with gr.Column():
with gr.Row():
with gr.Column():
self.srcaudio = gr.Audio(label = "输入音频")
self.btnVC = gr.Button("说话人转换")
with gr.Column():
self.dsid = gr.Dropdown(label = "目标角色", choices = self.lspk)
self.tran = gr.Slider(label = "升降调", maximum = 60, minimum = -60, step = 1, value = 0)
self.th = gr.Slider(label = "切片阈值", maximum = 32767, minimum = -32768, step = 0.1, value = -40)
with gr.Row():
self.VCOutputs = gr.Audio()
self.btnVC.click(self.so.inference, inputs=[self.srcaudio,self.dsid,self.tran,self.th], outputs=[self.VCOutputs])
with gr.Tab("SelectModel"):
with gr.Column():
modelstrs = gr.Dropdown(label = "模型", choices = self.modelPaths, value = self.modelPaths[0], type = "value")
devicestrs = gr.Dropdown(label = "设备", choices = ["cpu","cuda"], value = "cpu", type = "value")
btnMod = gr.Button("载入模型")
btnMod.click(self.loadModel, inputs=[modelstrs,devicestrs], outputs = [self.dsid,self.VoiceConversion])

def loadModel(self, path, device):
self.lspk = []
self.so.set_device(device)
self.so.loadCheckpoint(path)
for spk, sid in self.so.hps.spk.items():
self.lspk.append(spk)
VChange = gr.update(visible = True)
SDChange = gr.update(choices = self.lspk, value = self.lspk[0])
return [SDChange,VChange]

grVits = VitsGradio()

grVits.Vits.launch()

0 comments on commit 7ccf1f2

Please sign in to comment.