gnosticdev commited on
Commit
c6e67aa
verified
1 Parent(s): c5c3111

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -179,37 +179,37 @@ def generate_script(prompt, max_length=150):
179
  return prompt.strip()
180
 
181
  async def text_to_speech(text, output_path, voice):
182
- global tts_model
183
- logger.info(f"Convirtiendo texto a voz | Caracteres: {len(text)} | Voz: {voice} | Salida: {output_path}")
184
- if not text or not text.strip():
185
- logger.warning("Texto vac铆o para TTS")
186
- return False
187
- try:
188
- # Inicializar el modelo TTS si no est谩 cargado
189
- if 'tts_model' not in globals() or tts_model is None:
190
- logger.info("Inicializando modelo Coqui TTS...")
191
- tts_model = TTS(model_name="tts_models/es/mai/vits", progress_bar=False)
192
- logger.info("Modelo Coqui TTS cargado exitosamente")
193
-
194
- # Generar el audio
195
- logger.info("Generando audio con Coqui TTS...")
196
- tts_model.tts_to_file(
197
- text=text,
198
- speaker=tts_model.speakers[0] if tts_model.speakers else None,
199
- file_path=output_path
200
- )
201
-
202
- # Verificar que el archivo se cre贸 correctamente
203
- if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
204
- logger.info(f"Audio guardado exitosamente en: {output_path} | Tama帽o: {os.path.getsize(output_path)} bytes")
205
- return True
206
- else:
207
- logger.error(f"TTS guard贸 un archivo peque帽o o vac铆o en: {output_path}")
208
- return False
209
-
210
- except Exception as e:
211
- logger.error(f"Error en TTS con Coqui: {str(e)}", exc_info=True)
212
- return False
213
 
214
  def download_video_file(url, temp_dir):
215
  if not url:
 
179
  return prompt.strip()
180
 
181
  async def text_to_speech(text, output_path, voice):
182
+ global tts_model
183
+ logger.info(f"Convirtiendo texto a voz | Caracteres: {len(text)} | Voz: {voice} | Salida: {output_path}")
184
+ if not text or not text.strip():
185
+ logger.warning("Texto vac铆o para TTS")
186
+ return False
187
+ try:
188
+ # Inicializar el modelo TTS si no est谩 cargado
189
+ if 'tts_model' not in globals() or tts_model is None:
190
+ logger.info("Inicializando modelo Coqui XTTS v2...")
191
+ tts_model = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
192
+ logger.info("Modelo Coqui XTTS v2 cargado exitosamente")
193
+
194
+ # Generar el audio
195
+ logger.info("Generando audio con Coqui XTTS v2...")
196
+ tts_model.tts_to_file(
197
+ text=text,
198
+ file_path=output_path,
199
+ language="es"
200
+ )
201
+
202
+ # Verificar que el archivo se cre贸 correctamente
203
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 100:
204
+ logger.info(f"Audio guardado exitosamente en: {output_path} | Tama帽o: {os.path.getsize(output_path)} bytes")
205
+ return True
206
+ else:
207
+ logger.error(f"TTS guard贸 un archivo peque帽o o vac铆o en: {output_path}")
208
+ return False
209
+
210
+ except Exception as e:
211
+ logger.error(f"Error en TTS con Coqui: {str(e)}", exc_info=True)
212
+ return False
213
 
214
  def download_video_file(url, temp_dir):
215
  if not url: