gnosticdev commited on
Commit
4f39ae8
·
verified ·
1 Parent(s): a0673c0

Update tts_module.py

Browse files
Files changed (1) hide show
  1. tts_module.py +13 -11
tts_module.py CHANGED
@@ -1,15 +1,17 @@
1
- import pyttsx3
2
- import tempfile
 
3
 
4
  async def get_voices():
5
- engine = pyttsx3.init()
6
- voices = engine.getProperty('voices')
7
- return {f"{v.name} - {v.languages[0]} ({v.gender})": v.id for v in voices}
8
 
9
- async def text_to_speech(text, voice_id):
10
- engine = pyttsx3.init()
11
- engine.setProperty('voice', voice_id)
 
 
 
12
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
13
- engine.save_to_file(text, tmp_file.name)
14
- engine.runAndWait()
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