Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pymatcha
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
with open("vocoder.onnx", "rb") as f:
|
| 6 |
+
vocoder = f.read()
|
| 7 |
+
|
| 8 |
+
with open("uji-tts_amitaro.onnx", "rb") as f:
|
| 9 |
+
model = f.read()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
matcha = pymatcha.Matcha(vocoder, model)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def generate(text):
|
| 16 |
+
clean_text = matcha.preprocess(text)
|
| 17 |
+
mel, mel_lengths = matcha.synthesise(clean_text)
|
| 18 |
+
wav_data = matcha.decode(mel, mel_lengths)
|
| 19 |
+
byte_io = io.BytesIO(wav_data)
|
| 20 |
+
sr, data = wavfile.read(byte_io)
|
| 21 |
+
return sr, data
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
gradio_app = gr.Interface(
|
| 25 |
+
fn=generate,
|
| 26 |
+
inputs=["text"],
|
| 27 |
+
outputs=[gr.Audio()],
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
gradio_app.launch(server_name="0.0.0.0")
|