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