Spaces:
Running
Running
kevinwang676
commited on
Commit
·
acda046
1
Parent(s):
644a5bf
Update app.py
Browse files
app.py
CHANGED
@@ -82,6 +82,31 @@ def infer1(text):
|
|
82 |
f.write(output["output_wav"])
|
83 |
return filename + "file.wav"
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
app = gr.Blocks()
|
86 |
|
87 |
with app:
|
@@ -97,9 +122,14 @@ with app:
|
|
97 |
with gr.Row():
|
98 |
btn = gr.Button("使用AI娜娜的声音", variant="primary")
|
99 |
btn1 = gr.Button("使用AI小杰的声音", variant="primary")
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
102 |
btn.click(fn=infer, inputs=[inp], outputs=[out])
|
103 |
btn1.click(fn=infer1, inputs=[inp], outputs=[out])
|
|
|
104 |
|
105 |
app.launch(show_error=True)
|
|
|
82 |
f.write(output["output_wav"])
|
83 |
return filename + "file.wav"
|
84 |
|
85 |
+
# upsample
|
86 |
+
|
87 |
+
import numpy as np
|
88 |
+
import torch
|
89 |
+
from hifi_gan_bwe import BandwidthExtender
|
90 |
+
|
91 |
+
MAX_LENGTH = 600.0
|
92 |
+
|
93 |
+
model = BandwidthExtender.from_pretrained("hifi-gan-bwe-10-42890e3-vctk-48kHz")
|
94 |
+
|
95 |
+
def extend(audio):
|
96 |
+
fs, x = audio
|
97 |
+
x = x[:int(MAX_LENGTH * fs)]
|
98 |
+
x = x.astype(np.float32) / 32767.0
|
99 |
+
if len(x.shape) == 1:
|
100 |
+
x = x[:, np.newaxis]
|
101 |
+
|
102 |
+
with torch.no_grad():
|
103 |
+
y = np.stack([model(torch.from_numpy(x), fs) for x in x.T]).T
|
104 |
+
y = (y * 32767.0).astype(np.int16)
|
105 |
+
fs = int(model.sample_rate)
|
106 |
+
|
107 |
+
return fs, y
|
108 |
+
|
109 |
+
|
110 |
app = gr.Blocks()
|
111 |
|
112 |
with app:
|
|
|
122 |
with gr.Row():
|
123 |
btn = gr.Button("使用AI娜娜的声音", variant="primary")
|
124 |
btn1 = gr.Button("使用AI小杰的声音", variant="primary")
|
125 |
+
with gr.Column():
|
126 |
+
with gr.Row():
|
127 |
+
out = gr.Audio(label="为您生成的专属音频", type="filepath")
|
128 |
+
out1 = gr.Audio(label="更高采样率的专属音频", type="filepath")
|
129 |
+
btn2 = gr.Button("一键提高采样率")
|
130 |
+
|
131 |
btn.click(fn=infer, inputs=[inp], outputs=[out])
|
132 |
btn1.click(fn=infer1, inputs=[inp], outputs=[out])
|
133 |
+
btn2.click(fn=extend, inputs=[out], outputs=[out1])
|
134 |
|
135 |
app.launch(show_error=True)
|