gnosticdev commited on
Commit
007a5eb
·
verified ·
1 Parent(s): 6692a78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -47
app.py CHANGED
@@ -180,53 +180,53 @@ def generate_script(prompt, max_length=150):
180
  return prompt.strip()
181
 
182
  async def text_to_speech(text, output_path, voice):
183
- global tts_model
184
- logger.info(f"Convirtiendo texto a voz | Caracteres: {len(text)} | Voz: {voice} | Salida: {output_path}")
185
- if not text or not text.strip():
186
- logger.warning("Texto vacío para TTS")
187
- return False
188
-
189
- try:
190
- # Inicializar el modelo TTS si no está cargado
191
- if tts_model is None:
192
- logger.info("Inicializando modelo Coqui TTS...")
193
- tts_model = TTS(model_name="tts_models/es/mai/vits", progress_bar=False)
194
- logger.info("Modelo Coqui TTS cargado exitosamente")
195
-
196
- # Generar el audio
197
- logger.info("Generando audio con Coqui TTS...")
198
- tts_model.tts_to_file(
199
- text=text,
200
- speaker=tts_model.speakers[0] if tts_model.speakers else None,
201
- file_path=output_path
202
- )
203
-
204
- # Verificar que el archivo se creó correctamente
205
- if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
206
- logger.info(f"Audio guardado exitosamente en: {output_path} | Tamaño: {os.path.getsize(output_path)} bytes")
207
- return True
208
- else:
209
- logger.error(f"TTS guardó un archivo pequeño o vacío en: {output_path}")
210
- return False
211
-
212
- except Exception as e:
213
- logger.error(f"Error en TTS con Coqui: {str(e)}", exc_info=True)
214
-
215
- # Si falla Coqui TTS, intentar con Edge TTS como último recurso
216
- logger.warning("Intentando con Edge TTS como respaldo...")
217
- try:
218
- communicate = edge_tts.Communicate(text, voice)
219
- await communicate.save(output_path)
220
-
221
- if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
222
- logger.info(f"Audio guardado exitosamente con Edge TTS: {output_path}")
223
- return True
224
- else:
225
- logger.error(f"Edge TTS guardó un archivo pequeño o vacío: {output_path}")
226
- return False
227
- except Exception as e2:
228
- logger.error(f"Error en TTS con Edge TTS: {str(e2)}")
229
- return False
230
 
231
  def download_video_file(url, temp_dir):
232
  if not url:
 
180
  return prompt.strip()
181
 
182
  async def text_to_speech(text, output_path, voice):
183
+ global tts_model
184
+ logger.info(f"Convirtiendo texto a voz | Caracteres: {len(text)} | Voz: {voice} | Salida: {output_path}")
185
+ if not text or not text.strip():
186
+ logger.warning("Texto vacío para TTS")
187
+ return False
188
+ try:
189
+ # Inicializar el modelo TTS si no está cargado
190
+ if 'tts_model' not in globals() or tts_model is None:
191
+ logger.info("Inicializando modelo Coqui TTS...")
192
+ tts_model = TTS(model_name="tts_models/es/mai/vits", progress_bar=False)
193
+ logger.info("Modelo Coqui TTS cargado exitosamente")
194
+
195
+ # Generar el audio
196
+ logger.info("Generando audio con Coqui TTS...")
197
+ tts_model.tts_to_file(
198
+ text=text,
199
+ speaker=tts_model.speakers[0] if tts_model.speakers else None,
200
+ file_path=output_path
201
+ )
202
+
203
+ # Verificar que el archivo se creó correctamente
204
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
205
+ logger.info(f"Audio guardado exitosamente en: {output_path} | Tamaño: {os.path.getsize(output_path)} bytes")
206
+ return True
207
+ else:
208
+ logger.error(f"TTS guardó un archivo pequeño o vacío en: {output_path}")
209
+ return False
210
+
211
+ except Exception as e:
212
+ logger.error(f"Error en TTS con Coqui: {str(e)}", exc_info=True)
213
+
214
+ # Si falla Coqui TTS, intentar con Edge TTS como último recurso
215
+ logger.warning("Intentando con Edge TTS como respaldo...")
216
+ try:
217
+ import edge_tts
218
+ communicate = edge_tts.Communicate(text, voice)
219
+ await communicate.save(output_path)
220
+
221
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
222
+ logger.info(f"Audio guardado exitosamente con Edge TTS: {output_path}")
223
+ return True
224
+ else:
225
+ logger.error(f"Edge TTS guardó un archivo pequeño o vacío: {output_path}")
226
+ return False
227
+ except Exception as e2:
228
+ logger.error(f"Error en TTS con Edge TTS: {str(e2)}")
229
+ return False
230
 
231
  def download_video_file(url, temp_dir):
232
  if not url: