Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ MODEL_NAMES = [
|
|
17 |
]
|
18 |
|
19 |
MAX_TXT_LEN = 800
|
20 |
-
MODELS_DIRECTORY =
|
21 |
|
22 |
modelInfo = [
|
23 |
["vits-male", "best_model_65633.pth", "config-0.json",
|
@@ -36,54 +36,32 @@ modelInfo = [
|
|
36 |
"https://huggingface.co/Kamtera/persian-tts-female-tacotron2/resolve/main/"]
|
37 |
]
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
if not os.path.exists(model_directory):
|
43 |
-
os.makedirs(model_directory)
|
44 |
-
print("|> Downloading: ", model_directory)
|
45 |
-
download_url(model_url + model_filename, model_directory, "best_model.pth")
|
46 |
-
download_url(model_url + config_filename, model_directory, "config.json")
|
47 |
|
|
|
|
|
|
|
48 |
|
49 |
-
def tts(text: str, model_name: str):
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
synthesizer.save_wav(wavs, fp)
|
65 |
-
return fp.name
|
66 |
|
67 |
|
68 |
-
description = """
|
69 |
-
This is a demo of persian text to speech model.
|
70 |
|
71 |
-
**Github : https://github.com/karim23657/Persian-tts-coqui **
|
72 |
-
|
73 |
-
Models can be found here: <br>
|
74 |
-
|
75 |
-
|Model|Dataset|
|
76 |
-
|----|------|
|
77 |
-
|[vits female (best)](https://huggingface.co/Kamtera/persian-tts-female-vits)|[persian-tts-dataset-famale](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale)|
|
78 |
-
|[vits male1 (best)](https://huggingface.co/Kamtera/persian-tts-male1-vits)|[persian-tts-dataset-male](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-male)|
|
79 |
-
|[vits female1](https://huggingface.co/Kamtera/persian-tts-female1-vits)|[ParsiGoo](https://github.com/karim23657/ParsiGoo)|
|
80 |
-
|[vits male](https://huggingface.co/Kamtera/persian-tts-male-vits)|[persian-tts-dataset](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset)|
|
81 |
-
|[glowtts female](https://huggingface.co/Kamtera/persian-tts-female-glow_tts)|[persian-tts-dataset-famale](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale)|
|
82 |
-
|[glowtts male](https://huggingface.co/Kamtera/persian-tts-male-glow_tts)|[persian-tts-dataset](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset)|
|
83 |
-
|[tacotron2 female](https://huggingface.co/Kamtera/persian-tts-female-tacotron2)|[persian-tts-dataset-famale](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale)|
|
84 |
-
|
85 |
-
|
86 |
-
"""
|
87 |
article = ""
|
88 |
examples = [
|
89 |
["و خداوند شما را با ارسال روح در جسم زندگانی و حیات بخشید", "vits-male"],
|
@@ -95,8 +73,10 @@ examples = [
|
|
95 |
["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها", "vits male1 (best)"],
|
96 |
]
|
97 |
|
|
|
|
|
98 |
iface = gr.Interface(
|
99 |
-
fn=tts,
|
100 |
inputs=[
|
101 |
gr.Textbox(
|
102 |
label="Text",
|
|
|
17 |
]
|
18 |
|
19 |
MAX_TXT_LEN = 800
|
20 |
+
MODELS_DIRECTORY = "models"
|
21 |
|
22 |
modelInfo = [
|
23 |
["vits-male", "best_model_65633.pth", "config-0.json",
|
|
|
36 |
"https://huggingface.co/Kamtera/persian-tts-female-tacotron2/resolve/main/"]
|
37 |
]
|
38 |
|
39 |
+
class PersianTTS:
|
40 |
+
def __init__(self):
|
41 |
+
self.model_manager = ModelManager(MODELS_DIRECTORY)
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
for model in modelInfo:
|
44 |
+
model_name, model_filename, config_filename, model_url = model
|
45 |
+
self.model_manager.download_model(model_name, model_filename, config_filename, model_url)
|
46 |
|
47 |
+
def tts(self, text: str, model_name: str):
|
48 |
+
if len(text) > MAX_TXT_LEN:
|
49 |
+
text = text[:MAX_TXT_LEN]
|
50 |
+
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
51 |
|
52 |
+
# synthesize
|
53 |
+
model_path, config_path = self.model_manager.get_model_paths(model_name)
|
54 |
+
synthesizer = Synthesizer(model_path, config_path)
|
55 |
+
if synthesizer is None:
|
56 |
+
raise NameError("model not found")
|
57 |
+
wavs = synthesizer.tts(text)
|
58 |
+
# return output
|
59 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
60 |
+
synthesizer.save_wav(wavs, fp)
|
61 |
+
return fp.name
|
|
|
|
|
62 |
|
63 |
|
|
|
|
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
article = ""
|
66 |
examples = [
|
67 |
["و خداوند شما را با ارسال روح در جسم زندگانی و حیات بخشید", "vits-male"],
|
|
|
73 |
["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها", "vits male1 (best)"],
|
74 |
]
|
75 |
|
76 |
+
persian_tts = PersianTTS()
|
77 |
+
|
78 |
iface = gr.Interface(
|
79 |
+
fn=persian_tts.tts,
|
80 |
inputs=[
|
81 |
gr.Textbox(
|
82 |
label="Text",
|