Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,50 @@ model = Svc("G_754.pth", "config.json")
|
|
| 21 |
# model = Svc("E:/Items/so-vits-svc/models/Arknights/G_10400.pth", "E:/Items/so-vits-svc/models/Arknights/config.json")
|
| 22 |
|
| 23 |
|
| 24 |
-
def vc_fn(sid,input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise_scale):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if input_audio is None:
|
| 26 |
return "You need to upload an audio", None
|
| 27 |
sampling_rate, audio = input_audio
|
|
@@ -32,13 +75,13 @@ def vc_fn(sid,input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise_
|
|
| 32 |
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
| 33 |
if len(audio.shape) > 1:
|
| 34 |
audio = librosa.to_mono(audio.transpose(1, 0))
|
| 35 |
-
|
| 36 |
-
|
| 37 |
print(audio.shape)
|
| 38 |
out_wav_path = "temp.wav"
|
| 39 |
soundfile.write(out_wav_path, audio, 16000, format="wav")
|
| 40 |
-
|
| 41 |
-
_audio = model.slice_inference(out_wav_path,sid, vc_transform, slice_db, cluster_ratio, auto_f0, noise_scale)
|
| 42 |
return "Success", (44100, _audio)
|
| 43 |
|
| 44 |
|
|
@@ -51,13 +94,16 @@ with app:
|
|
| 51 |
Upload your audio
|
| 52 |
""")
|
| 53 |
spks = list(model.spk2id.keys())
|
| 54 |
-
|
| 55 |
-
vc_input3 = gr.Audio(label="
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
vc_output1 = gr.Textbox(label="Output Message")
|
| 58 |
vc_output2 = gr.Audio(label="Output Audio")
|
| 59 |
-
vc_submit.click(vc_fn, [vc_input3], [vc_output1, vc_output2])
|
| 60 |
-
# vc_submit.click(vc_fn, [vc_input3,0,-40,0,False,0.4], [vc_output1, vc_output2])
|
| 61 |
-
|
| 62 |
-
app.launch()
|
| 63 |
|
|
|
|
|
|
| 21 |
# model = Svc("E:/Items/so-vits-svc/models/Arknights/G_10400.pth", "E:/Items/so-vits-svc/models/Arknights/config.json")
|
| 22 |
|
| 23 |
|
| 24 |
+
# def vc_fn(sid,input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise_scale):
|
| 25 |
+
# if input_audio is None:
|
| 26 |
+
# return "You need to upload an audio", None
|
| 27 |
+
# sampling_rate, audio = input_audio
|
| 28 |
+
# # print(audio.shape,sampling_rate)
|
| 29 |
+
# duration = audio.shape[0] / sampling_rate
|
| 30 |
+
# if duration > 90:
|
| 31 |
+
# return "请上传小于90s的音频,需要转换长音频请本地进行转换", None
|
| 32 |
+
# audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
| 33 |
+
# if len(audio.shape) > 1:
|
| 34 |
+
# audio = librosa.to_mono(audio.transpose(1, 0))
|
| 35 |
+
# # if sampling_rate != 16000:
|
| 36 |
+
# # audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
| 37 |
+
# print(audio.shape)
|
| 38 |
+
# out_wav_path = "temp.wav"
|
| 39 |
+
# soundfile.write(out_wav_path, audio, 16000, format="wav")
|
| 40 |
+
# # print( cluster_ratio, auto_f0, noise_scale)
|
| 41 |
+
# _audio = model.slice_inference(out_wav_path,sid, vc_transform, slice_db, cluster_ratio, auto_f0, noise_scale)
|
| 42 |
+
# return "Success", (44100, _audio)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# app = gr.Blocks()
|
| 46 |
+
# with app:
|
| 47 |
+
# with gr.Tabs():
|
| 48 |
+
# with gr.TabItem("Basic"):
|
| 49 |
+
# gr.Markdown(value="""
|
| 50 |
+
# sovits Ameli
|
| 51 |
+
# Upload your audio
|
| 52 |
+
# """)
|
| 53 |
+
# spks = list(model.spk2id.keys())
|
| 54 |
+
# # sid = gr.Dropdown(label="Voice Tone", choices=spks, value=spks[0])
|
| 55 |
+
# vc_input3 = gr.Audio(label="Upload your audio(under 90s length)")
|
| 56 |
+
# vc_submit = gr.Button("Run", variant="primary")
|
| 57 |
+
# vc_output1 = gr.Textbox(label="Output Message")
|
| 58 |
+
# vc_output2 = gr.Audio(label="Output Audio")
|
| 59 |
+
# vc_submit.click(vc_fn, [vc_input3], [vc_output1, vc_output2])
|
| 60 |
+
# # vc_submit.click(vc_fn, [vc_input3,0,-40,0,False,0.4], [vc_output1, vc_output2])
|
| 61 |
+
|
| 62 |
+
# app.launch()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def vc_fn(sid, input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise_scale):
|
| 68 |
if input_audio is None:
|
| 69 |
return "You need to upload an audio", None
|
| 70 |
sampling_rate, audio = input_audio
|
|
|
|
| 75 |
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
| 76 |
if len(audio.shape) > 1:
|
| 77 |
audio = librosa.to_mono(audio.transpose(1, 0))
|
| 78 |
+
if sampling_rate != 16000:
|
| 79 |
+
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
| 80 |
print(audio.shape)
|
| 81 |
out_wav_path = "temp.wav"
|
| 82 |
soundfile.write(out_wav_path, audio, 16000, format="wav")
|
| 83 |
+
print( cluster_ratio, auto_f0, noise_scale)
|
| 84 |
+
_audio = model.slice_inference(out_wav_path, sid, vc_transform, slice_db, cluster_ratio, auto_f0, noise_scale)
|
| 85 |
return "Success", (44100, _audio)
|
| 86 |
|
| 87 |
|
|
|
|
| 94 |
Upload your audio
|
| 95 |
""")
|
| 96 |
spks = list(model.spk2id.keys())
|
| 97 |
+
sid = gr.Dropdown(label="音色", choices=spks, value=spks[0])
|
| 98 |
+
vc_input3 = gr.Audio(label="上传音频(长度小于90秒)")
|
| 99 |
+
vc_transform = gr.Number(label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0)
|
| 100 |
+
cluster_ratio = gr.Number(label="聚类模型混合比例,0-1之间,默认为0不启用聚类,能提升音色相似度,但会导致咬字下降(如果使用建议0.5左右)", value=0)
|
| 101 |
+
auto_f0 = gr.Checkbox(label="自动f0预测,配合聚类模型f0预测效果更好,会导致变调功能失效(仅限转换语音,歌声不要勾选此项会究极跑调)", value=False)
|
| 102 |
+
slice_db = gr.Number(label="切片阈值", value=-40)
|
| 103 |
+
noise_scale = gr.Number(label="noise_scale 建议不要动,会影响音质,玄学参数", value=0.4)
|
| 104 |
+
vc_submit = gr.Button("转换", variant="primary")
|
| 105 |
vc_output1 = gr.Textbox(label="Output Message")
|
| 106 |
vc_output2 = gr.Audio(label="Output Audio")
|
| 107 |
+
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale], [vc_output1, vc_output2])
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
app.launch()
|