Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from TTS.utils.download import download_url
|
3 |
+
from TTS.utils.synthesizer import Synthesizer
|
4 |
+
import gradio as gr
|
5 |
+
import tempfile
|
6 |
+
|
7 |
+
MAX_TXT_LEN = 800
|
8 |
+
Model_DIR = "models"
|
9 |
+
MODEL_URL = "https://huggingface.co/SpicyqSama007/Bert-VITS2-train-models/resolve/main/G_0.pth"
|
10 |
+
CONFIG_URL = "https://huggingface.co/SpicyqSama007/Bert-VITS2-train-models/resolve/main/config.json"
|
11 |
+
|
12 |
+
def download_model_and_config(gender):
|
13 |
+
if not os.path.exists(Model_DIR):
|
14 |
+
os.makedirs(Model_DIR)
|
15 |
+
download_url(MODEL_URL, dir_path, "model.pth")
|
16 |
+
download_url(CONFIG_URL, dir_path, "config.json")
|
17 |
+
return Model_DIR
|
18 |
+
|
19 |
+
download_model_and_config()
|
20 |
+
|
21 |
+
def tts(text: str):
|
22 |
+
if len(text) > MAX_TXT_LEN:
|
23 |
+
text = text[:MAX_TXT_LEN]
|
24 |
+
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
25 |
+
print(text)
|
26 |
+
|
27 |
+
#text = text.replace("I", "ӏ") #replace capital is with "Palochka" symbol
|
28 |
+
|
29 |
+
#model_dir = BASE_DIR.format("male" if voice == "Male" else "female")
|
30 |
+
|
31 |
+
# synthesize
|
32 |
+
synthesizer = Synthesizer(f"{Model_DIR}/model.pth", f"{model_dir}/config.json")
|
33 |
+
wavs = synthesizer.tts(text)
|
34 |
+
|
35 |
+
# return output
|
36 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
37 |
+
synthesizer.save_wav(wavs, fp)
|
38 |
+
return fp.name
|
39 |
+
|
40 |
+
iface = gr.Interface(
|
41 |
+
fn=tts,
|
42 |
+
inputs=[
|
43 |
+
gr.Textbox(
|
44 |
+
label="Text",
|
45 |
+
value="Default text here if you need it.",
|
46 |
+
)
|
47 |
+
],
|
48 |
+
outputs=gr.Audio(label="Output", type='filepath'),
|
49 |
+
title="TTS",
|
50 |
+
live=False
|
51 |
+
)
|
52 |
+
|
53 |
+
iface.launch(share=False)
|