Spaces:
Building
Building
Update tts_module.py
Browse files- tts_module.py +13 -11
tts_module.py
CHANGED
@@ -1,15 +1,17 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
3 |
|
4 |
async def get_voices():
|
5 |
-
|
6 |
-
|
7 |
-
return {f"{v.name} - {v.languages[0]} ({v.gender})": v.id for v in voices}
|
8 |
|
9 |
-
async def text_to_speech(text,
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
13 |
-
|
14 |
-
|
15 |
-
return tmp_file.name
|
|
|
1 |
+
# tts_module.py
|
2 |
+
import asyncio
|
3 |
+
import edge_tts
|
4 |
|
5 |
async def get_voices():
|
6 |
+
voices = await edge_tts.list_voices()
|
7 |
+
return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
|
|
8 |
|
9 |
+
async def text_to_speech(text, voice):
|
10 |
+
if not text.strip():
|
11 |
+
raise ValueError("El texto no puede estar vacío.")
|
12 |
+
if not voice:
|
13 |
+
raise ValueError("Debes seleccionar una voz.")
|
14 |
+
communicate = edge_tts.Communicate(text, voice)
|
15 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
16 |
+
await communicate.save(tmp_file.name)
|
17 |
+
return tmp_file.name
|
|