gnosticdev commited on
Commit
d63df9c
verified
1 Parent(s): dcb0f6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -14
app.py CHANGED
@@ -182,20 +182,53 @@ async def text_to_speech(text, output_path, voice):
182
  logger.warning("Texto vac铆o para TTS")
183
  return False
184
 
185
- try:
186
- communicate = edge_tts.Communicate(text, voice)
187
- await communicate.save(output_path)
188
-
189
- if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
190
- logger.info(f"Audio guardado exitosamente en: {output_path} | Tama帽o: {os.path.getsize(output_path)} bytes")
191
- return True
192
- else:
193
- logger.error(f"TTS guard贸 un archivo peque帽o o vac铆o en: {output_path}")
194
- return False
195
-
196
- except Exception as e:
197
- logger.error(f"Error en TTS con voz '{voice}': {str(e)}", exc_info=True)
198
- return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
200
  def download_video_file(url, temp_dir):
201
  if not url:
 
182
  logger.warning("Texto vac铆o para TTS")
183
  return False
184
 
185
+ # Lista extendida de voces de respaldo
186
+ backup_voices = [
187
+ "es-ES-JuanNeural",
188
+ "es-ES-ElviraNeural",
189
+ "es-ES-AlvaroNeural",
190
+ "es-MX-DaliaNeural",
191
+ "es-AR-ElenaNeural"
192
+ ]
193
+
194
+ # Configuraci贸n de reintentos con espera exponencial
195
+ max_retries = 5
196
+ base_delay = 2 # segundos
197
+
198
+ for attempt in range(max_retries):
199
+ current_voice = backup_voices[attempt % len(backup_voices)]
200
+
201
+ if attempt > 0:
202
+ delay = base_delay * (2 ** (attempt - 1)) # Espera exponencial
203
+ logger.warning(f"Esperando {delay} segundos antes del reintento {attempt + 1}/{max_retries} con voz {current_voice}")
204
+ await asyncio.sleep(delay)
205
+
206
+ try:
207
+ communicate = edge_tts.Communicate(text, current_voice)
208
+ await communicate.save(output_path)
209
+
210
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
211
+ logger.info(f"Audio guardado exitosamente en: {output_path} | Tama帽o: {os.path.getsize(output_path)} bytes")
212
+ return True
213
+ else:
214
+ logger.error(f"TTS guard贸 un archivo peque帽o o vac铆o en: {output_path}")
215
+
216
+ except Exception as e:
217
+ logger.error(f"Error en TTS con voz '{current_voice}': {str(e)}")
218
+
219
+ # Manejo espec铆fico para error 403
220
+ if "403" in str(e) or "Forbidden" in str(e):
221
+ logger.error("Error 403 detectado - Posible bloqueo temporal")
222
+ # Espera adicional para errores 403
223
+ if attempt < max_retries - 1:
224
+ await asyncio.sleep(base_delay * 3)
225
+ elif "timeout" in str(e).lower():
226
+ logger.error("Timeout detectado - Reintentando")
227
+ elif "connection" in str(e).lower():
228
+ logger.error("Error de conexi贸n detectado - Reintentando")
229
+
230
+ logger.error("Todos los intentos de TTS fallaron")
231
+ return False
232
 
233
  def download_video_file(url, temp_dir):
234
  if not url: