vietTTS / app.py
ntt123's picture
Update app.py
fe213ca
raw
history blame
No virus
1.41 kB
from vietTTS.hifigan.mel2wave import mel2wave
from vietTTS.nat.text2mel import text2mel
from vietTTS import nat_normalize_text
import numpy as np
import gradio as gr
import os
def text_to_speech(text):
# prevent too long text
if len(text) > 500:
text = text[:500]
text = nat_normalize_text(text)
mel = text2mel(
text,
"lexicon.txt",
0.2,
"acoustic_ckpt_latest.pickle",
"duration_ckpt_latest.pickle",
)
wave = mel2wave(mel, "config.json", "hk_hifi.pickle")
return (wave * (2**15)).astype(np.int16)
def speak(text):
y = text_to_speech(text)
return 16_000, y
title = "vietTTS"
description = "A vietnamese text-to-speech demo."
gr.Interface(
fn=speak,
inputs="text",
outputs="audio",
title = title,
examples = [
"Trăm năm trong cõi người ta, chữ tài chữ mệnh khéo là ghét nhau.",
"Đoạn trường tân thanh, thường được biết đến với cái tên đơn giản là Truyện Kiều, là một truyện thơ của đại thi hào Nguyễn Du",
"Lục Vân Tiên quê ở huyện Đông Thành, khôi ngô tuấn tú, tài kiêm văn võ. Nghe tin triều đình mở khoa thi, Vân Tiên từ giã thầy xuống núi đua tài."
],
description=description,
theme="default",
allow_screenshot=False,
allow_flagging="never",
).launch(debug=False)