vits-test / app.py
vic-yes's picture
Update app.py
f0344bb
import os
from TTS.utils.download import download_url
from TTS.utils.synthesizer import Synthesizer
import gradio as gr
import tempfile
MAX_TXT_LEN = 800
Model_DIR = "models"
MODEL_URL = "https://huggingface.co/SpicyqSama007/Bert-VITS2-train-models/resolve/main/G_0.pth"
CONFIG_URL = "https://huggingface.co/SpicyqSama007/Bert-VITS2-train-models/resolve/main/config.json"
def download_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")
return Model_DIR
download_model_and_config()
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
#model_dir = BASE_DIR.format("male" if voice == "Male" else "female")
# 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
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="TTS",
live=False
)
iface.launch(share=False)