vits-kbd-male / app.py
anzorq's picture
Update app.py
1d3c496
raw
history blame
1.43 kB
import os
from TTS.utils.download import download_url
from TTS.utils.synthesizer import Synthesizer
import gradio as gr
import tempfile
# Variables
MAX_TXT_LEN = 800
MODEL_DIR = "kbd-vits-tts-male"
MODEL_URL = "https://huggingface.co/anzorq/kbd-vits-tts-male/resolve/main/checkpoint_56000.pth"
CONFIG_URL = "https://huggingface.co/anzorq/kbd-vits-tts-male/resolve/main/config_35000.json"
# Downloading model and config
if not os.path.exists(MODEL_DIR):
os.makedirs(MODEL_DIR)
download_url(MODEL_URL, MODEL_DIR, "model.pth")
download_url(CONFIG_URL, MODEL_DIR, "config.json")
def tts(text: str):
if len(text) > MAX_TXT_LEN:
text = text[:MAX_TXT_LEN]
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
print(text)
text = text.replace("I", "ӏ") #replace capital is with "Palochka" symbol
# synthesize
synthesizer = Synthesizer(f"{MODEL_DIR}/model.pth", f"{MODEL_DIR}/config.json")
wavs = synthesizer.tts(text)
# return output
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
synthesizer.save_wav(wavs, fp)
return fp.name
# Gradio interface
iface = gr.Interface(
fn=tts,
inputs=gr.Textbox(
label="Text",
value="Default text here if you need it.",
),
outputs=gr.Audio(label="Output", type='filepath'),
title="KBD TTS",
live=False
)
iface.launch(share=False)