Skip to content

Commit

Permalink
Updata and Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ylzz1997 committed Mar 31, 2023
1 parent c38cf7d commit 91c3320
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions webUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import asyncio
from scipy.io import wavfile
import librosa
import torch

logging.getLogger('numba').setLevel(logging.WARNING)
logging.getLogger('markdown_it').setLevel(logging.WARNING)
Expand All @@ -24,6 +25,10 @@

model = None
spk = None
cuda = []
if torch.cuda.is_available():
for i in range(torch.cuda.device_count()):
cuda.append("cuda:{}".format(i))

def vc_fn(sid, input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num):
global model
Expand All @@ -38,7 +43,7 @@ def vc_fn(sid, input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise
if len(audio.shape) > 1:
audio = librosa.to_mono(audio.transpose(1, 0))
temp_path = "temp.wav"
soundfile.write(temp_path, audio, model.target_sample, format="wav")
soundfile.write(temp_path, audio, sampling_rate, format="wav")
_audio = model.slice_inference(temp_path, sid, vc_transform, slice_db, cluster_ratio, auto_f0, noise_scale,pad_seconds,cl_num,lg_num,lgr_num)
model.clear_empty()
os.remove(temp_path)
Expand Down Expand Up @@ -109,15 +114,15 @@ def vc_fn2(sid, input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, nois
<font size=3>下面是聚类模型文件选择,没有可以不填:</font>
""")
cluster_model_path = gr.File(label="聚类模型文件")
device = gr.Dropdown(label="推理设备,留白则为自动选择cpu和gpu",choices=[None,"cuda","cpu"],value=None)
device = gr.Dropdown(label="推理设备,默认为自动选择cpu和gpu",choices=["Auto",*cuda,"cpu"],value="Auto")
gr.Markdown(value="""
<font size=3>全部上传完毕后(全部文件模块显示download),点击模型解析进行解析:</font>
""")
model_analysis_button = gr.Button(value="模型解析")
sid = gr.Dropdown(label="音色(说话人)")
sid_output = gr.Textbox(label="Output Message")

text2tts=gr.Textbox(label="在此输入要转译的文字")
text2tts=gr.Textbox(label="在此输入要转译的文字。注意,使用该功能建议打开F0预测,不然会跟怪")
tts_rate = gr.Number(label="tts语速", value=0)

vc_input3 = gr.Audio(label="上传音频")
Expand All @@ -136,16 +141,17 @@ def vc_fn2(sid, input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, nois
vc_output2 = gr.Audio(label="Output Audio")
def modelAnalysis(model_path,config_path,cluster_model_path,device):
global model
debug=False
debug=True
if debug:
model = Svc(model_path.name, config_path.name,device=device if device!="" else None,cluster_model_path= cluster_model_path.name if cluster_model_path!=None else "")
model = Svc(model_path.name, config_path.name,device=device if device!="Auto" else None,cluster_model_path= cluster_model_path.name if cluster_model_path!=None else "")
spks = list(model.spk2id.keys())
return sid.update(choices = spks,value=spks[0]),"ok"
return sid.update(choices = spks,value=spks[0]),"ok,模型被加载到了设备{}之上".format(device_name)
else:
try:
model = Svc(model_path.name, config_path.name,device=device if device!="" else None,cluster_model_path= cluster_model_path.name if cluster_model_path!=None else "")
model = Svc(model_path.name, config_path.name,device=device if device!="Auto" else None,cluster_model_path= cluster_model_path.name if cluster_model_path!=None else "")
spks = list(model.spk2id.keys())
return sid.update(choices = spks,value=spks[0]),"ok"
device_name = torch.cuda.get_device_properties(model.dev).name if "cuda" in str(model.dev) else str(model.dev)
return sid.update(choices = spks,value=spks[0]),"ok,模型被加载到了设备{}之上".format(device_name)
except Exception as e:
return "","异常信息:"+str(e)+"\n请排障后重试"
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num], [vc_output1, vc_output2])
Expand Down

0 comments on commit 91c3320

Please sign in to comment.