Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
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 |
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:
|