Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
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:
|