forked from effusiveperiscope/so-vits-svc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sovits_gradio.py
47 lines (43 loc) · 2.3 KB
/
sovits_gradio.py
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
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()