Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,21 @@ static_folder = os.path.join(script_path, "static")
|
|
18 |
# Ensure the static folder exists
|
19 |
os.makedirs(static_folder, exist_ok=True)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
class Component:
|
22 |
def __init__(self, component_type, label, options=None, value=None):
|
23 |
self.component_type = component_type
|
@@ -143,8 +158,9 @@ def copy_lang_dict(data_folder, destination,lang):
|
|
143 |
def compile_espeak():
|
144 |
compile_command = [espeak_path, "--compile=fa"]
|
145 |
cwd_path = os.path.join(static_folder,"dictsource")
|
|
|
146 |
subprocess.run(compile_command, cwd=cwd_path)
|
147 |
-
print("Compilation done!")
|
148 |
|
149 |
|
150 |
|
@@ -167,6 +183,9 @@ with gzip.open(phonetc_data_file_path, 'at',encoding='utf-8') as f: # 'at' for
|
|
167 |
f.write(f'// started at : {get_iran_time_no_packages()}\n')
|
168 |
|
169 |
|
|
|
|
|
|
|
170 |
def tts(input_data):
|
171 |
text = input_data.get('text')
|
172 |
voice = input_data.get('voice')
|
@@ -186,10 +205,18 @@ def tts(input_data):
|
|
186 |
phonemized_text = phonemes_result.stdout.strip()
|
187 |
|
188 |
# Generate audio file
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
return {"audio": f"/static/{os.path.basename(audio_file)}", # Return the static path
|
195 |
"status": status
|
@@ -251,8 +278,9 @@ def listWords(input_data):
|
|
251 |
def example_function(input_data):
|
252 |
return input_data
|
253 |
|
|
|
254 |
input_components = [
|
255 |
-
Component("radio", "voice", options=
|
256 |
]
|
257 |
|
258 |
output_components = [
|
@@ -328,6 +356,7 @@ def download():
|
|
328 |
@app.route('/download/fa_dict')
|
329 |
def download1():
|
330 |
dict_file='fa_dict'
|
|
|
331 |
return send_file(os.path.join(find_espeak_ng_data_folder(),dict_file ), as_attachment=True)
|
332 |
if __name__ == "__main__":
|
333 |
app.run(host='0.0.0.0', port= 7860)
|
|
|
18 |
# Ensure the static folder exists
|
19 |
os.makedirs(static_folder, exist_ok=True)
|
20 |
|
21 |
+
models = [
|
22 |
+
['mms fa','https://huggingface.co/willwade/mms-tts-multilingual-models-onnx/resolve/main/fas',"🌠 راد",'https://huggingface.co/facebook/mms-tts-fas'],
|
23 |
+
['coqui-vits-female1-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/persian-tts-female1-vits-coqui',"🌺 نگار",'https://huggingface.co/Kamtera/persian-tts-female1-vits'],
|
24 |
+
['coqui-vits-male1-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/persian-tts-male1-vits-coqui',"🌟 آرش",'https://huggingface.co/Kamtera/persian-tts-male1-vits'],
|
25 |
+
['coqui-vits-male-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/male-male-coqui-vits',"🦁 کیان",'https://huggingface.co/Kamtera/persian-tts-male-vits'],
|
26 |
+
['coqui-vits-female-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/female-female-coqui-vits',"🌷 مهتاب",'https://huggingface.co/Kamtera/persian-tts-female-vits'],
|
27 |
+
['coqui-vits-female-GPTInformal-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/female-GPTInformal-coqui-vits',"🌼 شیوا",'https://huggingface.co/karim23657/persian-tts-female-GPTInformal-Persian-vits'],
|
28 |
+
['coqui-vits-male-SmartGitiCorp','https://huggingface.co/karim23657/persian-tts-vits/tree/main/male-SmartGitiCorp-coqui-vits',"🚀 بهمن",'https://huggingface.co/SmartGitiCorp/persian_tts_vits'],
|
29 |
+
['vits-piper-fa-gyro-medium','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fa_IR-gyro-medium.tar.bz2',"💧 نیما",'https://huggingface.co/gyroing/Persian-Piper-Model-gyro'],
|
30 |
+
['piper-fa-amir-medium','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fa_IR-amir-medium.tar.bz2',"⚡️ آریا",'https://huggingface.co/SadeghK/persian-text-to-speech'],
|
31 |
+
['vits-mimic3-fa-haaniye_low','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-mimic3-fa-haaniye_low.tar.bz2',"🌹 ریما",'https://github.com/MycroftAI/mimic3'],
|
32 |
+
['vits-piper-fa_en-rezahedayatfar-ibrahimwalk-medium','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fa_en-rezahedayatfar-ibrahimwalk-medium.tar.bz2',"🌠 پیام",'https://huggingface.co/mah92/persian-english-piper-tts-model'],
|
33 |
+
]
|
34 |
+
|
35 |
+
|
36 |
class Component:
|
37 |
def __init__(self, component_type, label, options=None, value=None):
|
38 |
self.component_type = component_type
|
|
|
158 |
def compile_espeak():
|
159 |
compile_command = [espeak_path, "--compile=fa"]
|
160 |
cwd_path = os.path.join(static_folder,"dictsource")
|
161 |
+
os.makedirs(cwd_path, exist_ok=True)
|
162 |
subprocess.run(compile_command, cwd=cwd_path)
|
163 |
+
print("Compilation done!")
|
164 |
|
165 |
|
166 |
|
|
|
183 |
f.write(f'// started at : {get_iran_time_no_packages()}\n')
|
184 |
|
185 |
|
186 |
+
import soundfile as sf
|
187 |
+
from app_utils import tts_interface
|
188 |
+
|
189 |
def tts(input_data):
|
190 |
text = input_data.get('text')
|
191 |
voice = input_data.get('voice')
|
|
|
205 |
phonemized_text = phonemes_result.stdout.strip()
|
206 |
|
207 |
# Generate audio file
|
208 |
+
(sample_rate, audio_data), final_status = tts_interface(voice, text, '')
|
209 |
+
sf.write(
|
210 |
+
audio_file,
|
211 |
+
audio_data,
|
212 |
+
samplerate=sample_rate,
|
213 |
+
subtype="PCM_16",
|
214 |
+
)
|
215 |
+
|
216 |
+
for model in models:
|
217 |
+
if voice==model[2]:
|
218 |
+
model_url = model[3]
|
219 |
+
status = f'مدل : {model_url}\nآوانگاشت: {phonemized_text}'
|
220 |
|
221 |
return {"audio": f"/static/{os.path.basename(audio_file)}", # Return the static path
|
222 |
"status": status
|
|
|
278 |
def example_function(input_data):
|
279 |
return input_data
|
280 |
|
281 |
+
input_options = list([i[2] for i in models])
|
282 |
input_components = [
|
283 |
+
Component("radio", "voice", options=input_options, value=input_options[7])
|
284 |
]
|
285 |
|
286 |
output_components = [
|
|
|
356 |
@app.route('/download/fa_dict')
|
357 |
def download1():
|
358 |
dict_file='fa_dict'
|
359 |
+
compile_espeak()
|
360 |
return send_file(os.path.join(find_espeak_ng_data_folder(),dict_file ), as_attachment=True)
|
361 |
if __name__ == "__main__":
|
362 |
app.run(host='0.0.0.0', port= 7860)
|