Spaces:
Running
Running
Update conver.py
Browse files
conver.py
CHANGED
@@ -11,6 +11,7 @@ from pydub import AudioSegment
|
|
11 |
import base64
|
12 |
from pathlib import Path
|
13 |
import hashlib
|
|
|
14 |
|
15 |
@dataclass
|
16 |
class ConversationConfig:
|
@@ -111,8 +112,43 @@ class URLToAudioConverter:
|
|
111 |
return final_output, conversation_text
|
112 |
|
113 |
async def raw_text_to_audio(self, text: str, voice_1: str, voice_2: str) -> Tuple[str, str]:
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
import base64
|
12 |
from pathlib import Path
|
13 |
import hashlib
|
14 |
+
import asyncio
|
15 |
|
16 |
@dataclass
|
17 |
class ConversationConfig:
|
|
|
112 |
return final_output, conversation_text
|
113 |
|
114 |
async def raw_text_to_audio(self, text: str, voice_1: str, voice_2: str) -> Tuple[str, str]:
|
115 |
+
try:
|
116 |
+
print("\n=== DEBUG INICIO (raw_text_to_audio) ===")
|
117 |
+
print(f"Texto recibido: {text[:200]}...") # Verifica el input
|
118 |
+
|
119 |
+
# Usa una ruta absoluta en /tmp (compatible con Spaces)
|
120 |
+
output_dir = "/tmp/podcast_outputs"
|
121 |
+
os.makedirs(output_dir, exist_ok=True)
|
122 |
+
hash_name = hashlib.md5(text.encode()).hexdigest()[:8]
|
123 |
+
output_file = os.path.join(output_dir, f"podcast_{hash_name}.mp3")
|
124 |
+
print(f"Ruta de salida: {output_file}")
|
125 |
+
|
126 |
+
# Verifica voces disponibles (DEBUG)
|
127 |
+
voices = await edge_tts.list_voices()
|
128 |
+
voice_names = [v['Name'] for v in voices]
|
129 |
+
print(f"Voces disponibles (primeras 5): {voice_names[:5]}...")
|
130 |
+
|
131 |
+
# Extrae el nombre corto de la voz (ej: "en-US-AvaMultilingualNeural")
|
132 |
+
voice_short = voice_1.split(" - ")[0] if " - " in voice_1 else voice_1
|
133 |
+
print(f"Voz a usar: {voice_short}")
|
134 |
+
|
135 |
+
# Genera el audio
|
136 |
+
communicate = edge_tts.Communicate(text, voice_short)
|
137 |
+
print("Generando audio...")
|
138 |
+
await communicate.save(output_file)
|
139 |
+
print("Audio generado.")
|
140 |
+
|
141 |
+
# Verifica que el archivo existe y no está vacío
|
142 |
+
if not os.path.exists(output_file):
|
143 |
+
print("ERROR: Archivo no creado.")
|
144 |
+
return "Error: Archivo no generado", None
|
145 |
+
elif os.path.getsize(output_file) == 0:
|
146 |
+
print("ERROR: Archivo vacío.")
|
147 |
+
return "Error: Archivo de audio vacío", None
|
148 |
+
|
149 |
+
print(f"=== DEBUG FIN (Archivo válido: {output_file}) ===")
|
150 |
+
return text, output_file
|
151 |
+
|
152 |
+
except Exception as e:
|
153 |
+
print(f"ERROR CRÍTICO: {str(e)}")
|
154 |
+
return f"Error: {str(e)}", None
|