Update tts_module.py
Browse files- tts_module.py +7 -2
tts_module.py
CHANGED
|
@@ -1,17 +1,22 @@
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 16 |
await communicate.save(tmp_file.name)
|
| 17 |
return tmp_file.name
|
|
|
|
| 1 |
# tts_module.py
|
| 2 |
import asyncio
|
| 3 |
import edge_tts
|
| 4 |
+
import tempfile
|
| 5 |
|
| 6 |
async def get_voices():
|
| 7 |
voices = await edge_tts.list_voices()
|
| 8 |
return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
| 9 |
|
| 10 |
+
async def text_to_speech(text, voice, rate=0, pitch=0):
|
| 11 |
if not text.strip():
|
| 12 |
raise ValueError("El texto no puede estar vacío.")
|
| 13 |
if not voice:
|
| 14 |
raise ValueError("Debes seleccionar una voz.")
|
| 15 |
+
|
| 16 |
+
voice_short_name = voice.split(" - ")[0]
|
| 17 |
+
rate_str = f"{rate:+d}%"
|
| 18 |
+
pitch_str = f"{pitch:+d}Hz"
|
| 19 |
+
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
|
| 20 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 21 |
await communicate.save(tmp_file.name)
|
| 22 |
return tmp_file.name
|