Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
-
|
2 |
-
import os
|
3 |
-
import gradio as gr
|
4 |
from TTS.config import load_config
|
|
|
|
|
5 |
from TTS.utils.manage import ModelManager
|
6 |
from TTS.utils.synthesizer import Synthesizer
|
7 |
-
from TTS.utils.download import download_url
|
8 |
|
9 |
-
MODEL_NAMES
|
10 |
"vits male1 (best)",
|
11 |
"vits female (best)",
|
12 |
"vits-male",
|
@@ -15,47 +15,45 @@ MODEL_NAMES = [
|
|
15 |
"glowtts-female",
|
16 |
"female tacotron2"
|
17 |
]
|
18 |
-
|
19 |
MAX_TXT_LEN = 800
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
["vits-male", "best_model_65633.pth", "config-0.json",
|
24 |
-
"https://huggingface.co/Kamtera/persian-tts-male-vits/resolve/main/"],
|
25 |
-
["vits female (best)", "checkpoint_48000.pth", "config-2.json",
|
26 |
-
"https://huggingface.co/Kamtera/persian-tts-female-vits/resolve/main/"],
|
27 |
-
["glowtts-male", "best_model_77797.pth", "config-1.json",
|
28 |
-
"https://huggingface.co/Kamtera/persian-tts-male-glow_tts/resolve/main/"],
|
29 |
-
["glowtts-female", "best_model.pth", "config.json",
|
30 |
-
"https://huggingface.co/Kamtera/persian-tts-female-glow_tts/resolve/main/"],
|
31 |
-
["vits male1 (best)", "checkpoint_88000.pth", "config.json",
|
32 |
-
"https://huggingface.co/Kamtera/persian-tts-male1-vits/resolve/main/"],
|
33 |
-
["vits female1", "checkpoint_50000.pth", "config.json",
|
34 |
-
"https://huggingface.co/Kamtera/persian-tts-female1-vits/resolve/main/"],
|
35 |
-
["female tacotron2", "checkpoint_313000.pth", "config-2.json",
|
36 |
-
"https://huggingface.co/Kamtera/persian-tts-female-tacotron2/resolve/main/"]
|
37 |
-
]
|
38 |
|
39 |
-
for model in modelInfo:
|
40 |
-
model_name, model_filename, config_filename, model_url = model
|
41 |
-
model_directory = os.path.join(MODELS_DIRECTORY, model_name)
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
if len(text) > MAX_TXT_LEN:
|
51 |
text = text[:MAX_TXT_LEN]
|
52 |
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
|
|
53 |
|
|
|
54 |
# synthesize
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
synthesizer = Synthesizer(model_path, config_path)
|
59 |
if synthesizer is None:
|
60 |
raise NameError("model not found")
|
61 |
wavs = synthesizer.tts(text)
|
@@ -65,18 +63,35 @@ def tts(text: str, model_name: str):
|
|
65 |
return fp.name
|
66 |
|
67 |
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
["تاجر تو چه تجارت می کنی ، تو را چه که چه تجارت می کنم؟", "vits female (best)"],
|
73 |
-
["شیش سیخ جیگر سیخی شیش هزار", "vits female (best)"],
|
74 |
-
["سه شیشه شیر ، سه سیر سرشیر", "vits female (best)"],
|
75 |
-
["دزدی دزدید ز بز دزدی بزی ، عجب دزدی که دزدید ز بز دزدی بزی", "vits male1 (best)"],
|
76 |
-
["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد", "vits female1"],
|
77 |
-
["در گلو ماند خس او سالها، چیست آن خس مهر ��اه و مالها", "vits male1 (best)"],
|
78 |
-
]
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
iface = gr.Interface(
|
81 |
fn=tts,
|
82 |
inputs=[
|
@@ -90,11 +105,11 @@ iface = gr.Interface(
|
|
90 |
value="vits-female",
|
91 |
),
|
92 |
],
|
93 |
-
outputs=gr.Audio(label="Output",
|
94 |
examples=examples,
|
95 |
title="🗣️ Persian tts 🗣️",
|
96 |
description=description,
|
97 |
article=article,
|
98 |
live=False
|
99 |
)
|
100 |
-
iface.launch(share=False)
|
|
|
1 |
+
|
2 |
+
import tempfile ,os
|
|
|
3 |
from TTS.config import load_config
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
from TTS.utils.manage import ModelManager
|
7 |
from TTS.utils.synthesizer import Synthesizer
|
|
|
8 |
|
9 |
+
MODEL_NAMES=[
|
10 |
"vits male1 (best)",
|
11 |
"vits female (best)",
|
12 |
"vits-male",
|
|
|
15 |
"glowtts-female",
|
16 |
"female tacotron2"
|
17 |
]
|
|
|
18 |
MAX_TXT_LEN = 800
|
19 |
+
model_path = os.getcwd() + "/best_model.pth"
|
20 |
+
config_path = os.getcwd() + "/config.json"
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
from TTS.utils.download import download_url
|
25 |
+
modelInfo=[
|
26 |
+
["vits-male","best_model_65633.pth","config-0.json","https://huggingface.co/Kamtera/persian-tts-male-vits/resolve/main/"],
|
27 |
+
["vits female (best)","checkpoint_48000.pth","config-2.json","https://huggingface.co/Kamtera/persian-tts-female-vits/resolve/main/"],
|
28 |
+
["glowtts-male","best_model_77797.pth","config-1.json","https://huggingface.co/Kamtera/persian-tts-male-glow_tts/resolve/main/"],
|
29 |
+
["glowtts-female","best_model.pth","config.json","https://huggingface.co/Kamtera/persian-tts-female-glow_tts/resolve/main/"],
|
30 |
+
["vits male1 (best)","checkpoint_88000.pth","config.json","https://huggingface.co/Kamtera/persian-tts-male1-vits/resolve/main/"],
|
31 |
+
["vits female1","checkpoint_50000.pth","config.json","https://huggingface.co/Kamtera/persian-tts-female1-vits/resolve/main/"],
|
32 |
+
["female tacotron2","checkpoint_313000.pth","config-2.json","https://huggingface.co/Kamtera/persian-tts-female-tacotron2/resolve/main/"]
|
33 |
+
]
|
34 |
|
35 |
+
for d in modelInfo:
|
36 |
+
directory=d[0]
|
37 |
+
if not os.path.exists(directory):
|
38 |
+
os.makedirs(directory)
|
39 |
+
print("|> Downloading: ",directory)
|
40 |
+
download_url(
|
41 |
+
d[3]+d[1],directory,"best_model.pth"
|
42 |
+
)
|
43 |
+
download_url(
|
44 |
+
d[3]+d[2],directory,"config.json"
|
45 |
+
)
|
46 |
+
def tts(text: str,model_name: str):
|
47 |
if len(text) > MAX_TXT_LEN:
|
48 |
text = text[:MAX_TXT_LEN]
|
49 |
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
50 |
+
print(text)
|
51 |
|
52 |
+
|
53 |
# synthesize
|
54 |
+
synthesizer = Synthesizer(
|
55 |
+
model_name+"/best_model.pth", model_name+"/config.json"
|
56 |
+
)
|
|
|
57 |
if synthesizer is None:
|
58 |
raise NameError("model not found")
|
59 |
wavs = synthesizer.tts(text)
|
|
|
63 |
return fp.name
|
64 |
|
65 |
|
66 |
+
description="""
|
67 |
+
This is a demo of persian text to speech model.
|
68 |
|
69 |
+
**Github : https://github.com/karim23657/Persian-tts-coqui **
|
70 |
+
|
71 |
+
Models can be found here: <br>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
|Model|Dataset|
|
74 |
+
|----|------|
|
75 |
+
|[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)|
|
76 |
+
|[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)|
|
77 |
+
|[vits female1](https://huggingface.co/Kamtera/persian-tts-female1-vits)|[ParsiGoo](https://github.com/karim23657/ParsiGoo)|
|
78 |
+
|[vits male](https://huggingface.co/Kamtera/persian-tts-male-vits)|[persian-tts-dataset](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset)|
|
79 |
+
|[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)|
|
80 |
+
|[glowtts male](https://huggingface.co/Kamtera/persian-tts-male-glow_tts)|[persian-tts-dataset](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset)|
|
81 |
+
|[tacotron2 female](https://huggingface.co/Kamtera/persian-tts-female-tacotron2)|[persian-tts-dataset-famale](https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale)|
|
82 |
+
|
83 |
+
|
84 |
+
"""
|
85 |
+
article= ""
|
86 |
+
examples=[
|
87 |
+
["و خداوند شما را با ارسال روح در جسم زندگانی و حیات بخشید","vits-male"],
|
88 |
+
["تاجر تو چه تجارت می کنی ، تو را چه که چه تجارت می کنم؟","vits female (best)"],
|
89 |
+
["شیش سیخ جیگر سیخی شیش هزار","vits female (best)"],
|
90 |
+
["سه شیشه شیر ، سه سیر سرشیر","vits female (best)"],
|
91 |
+
["دزدی دزدید ز بز دزدی بزی ، عجب دزدی که دزدید ز بز دزدی بزی","vits male1 (best)"],
|
92 |
+
["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد","vits female1"],
|
93 |
+
["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها","vits male1 (best)"],
|
94 |
+
]
|
95 |
iface = gr.Interface(
|
96 |
fn=tts,
|
97 |
inputs=[
|
|
|
105 |
value="vits-female",
|
106 |
),
|
107 |
],
|
108 |
+
outputs=gr.Audio(label="Output",type='filepath'),
|
109 |
examples=examples,
|
110 |
title="🗣️ Persian tts 🗣️",
|
111 |
description=description,
|
112 |
article=article,
|
113 |
live=False
|
114 |
)
|
115 |
+
iface.launch(share=False)
|