Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from vietTTS.hifigan.mel2wave import mel2wave
|
3 |
+
from vietTTS.nat.text2mel import text2mel
|
4 |
+
from vietTTS import nat_normalize_text
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
import os
|
8 |
+
os.system("gdown --id 16UhN8QBxG1YYwUh8smdEeVnKo9qZhvZj -O duration_latest_ckpt.pickle")
|
9 |
+
os.system("gdown --id 1-8Ig65S3irNHSzcskT37SLgeyuUhjKdj -O acoustic_latest_ckpt.pickle")
|
10 |
+
os.system("gdown --id 19cRNDC6IrHFAAE4U9I7K0mzLMgPsi5zb -O hk_hifi.pickle")
|
11 |
+
|
12 |
+
|
13 |
+
def text_to_speech(text):
|
14 |
+
text = nat_normalize_text(text)
|
15 |
+
mel = text2mel(
|
16 |
+
text,
|
17 |
+
"lexicon.txt",
|
18 |
+
0.2,
|
19 |
+
Path("acoustic_latest_ckpt.pickle"),
|
20 |
+
Path("duration_latest_ckpt.pickle")
|
21 |
+
)
|
22 |
+
wave = mel2wave(mel, Path("config.json"), Path("hk_hifi.pickle"))
|
23 |
+
return (wave * (2**15)).astype(np.int16)
|
24 |
+
import gradio as gr
|
25 |
+
|
26 |
+
|
27 |
+
def speak(text):
|
28 |
+
y = text_to_speech(text)
|
29 |
+
return 16_000, y
|
30 |
+
|
31 |
+
title = "vietTTS"
|
32 |
+
description = "A vietnamese text-to-speech demo."
|
33 |
+
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=speak,
|
36 |
+
inputs="text",
|
37 |
+
outputs="audio",
|
38 |
+
title = title,
|
39 |
+
description=description
|
40 |
+
)
|
41 |
+
|
42 |
+
iface.launch()
|