gnosticdev commited on
Commit
bea0517
·
verified ·
1 Parent(s): fe32dd7

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +18 -15
conver.py CHANGED
@@ -166,19 +166,22 @@ class URLToAudioConverter:
166
  return final_output, conversation_text
167
 
168
  async def raw_text_to_audio(self, text: str, voice_1: str, voice_2: str) -> Tuple[str, str]:
169
- conversation = {
170
- "conversation": [
171
- {"speaker": "Host", "text": text},
172
- {"speaker": "Co-host", "text": "(Continuación del tema)"}
173
- ]
174
- }
175
- audio_files, folder_name = await self.text_to_speech(conversation, voice_1, voice_2)
176
- combined_audio = self.combine_audio_files(audio_files)
177
- music_path = "assets/musica.mp3"
178
- tags_paths = ["assets/tag.mp3", "assets/tag2.mp3"]
179
- final_audio = self.add_background_music_and_tags(combined_audio, music_path, tags_paths)
180
- output_file = os.path.join(folder_name, "raw_podcast_with_music.mp3")
181
- final_audio.export(output_file, format="mp3")
182
- for f in audio_files:
183
- os.remove(f)
184
  return text, output_file
 
 
 
 
 
166
  return final_output, conversation_text
167
 
168
  async def raw_text_to_audio(self, text: str, voice_1: str, voice_2: str) -> Tuple[str, str]:
169
+ try:
170
+ # 1. Guardar en el root del repo (sin subcarpetas)
171
+ output_file = f"podcast_{hashlib.md5(text.encode()).hexdigest()[:8]}.mp3"
172
+
173
+ # 2. Nombre corto de la voz (sin sufijos)
174
+ voice = voice_1.split(" - ")[0] # Ej: "es-ES-ElviraNeural"
175
+
176
+ # 3. Generar audio y verificar
177
+ communicate = edge_tts.Communicate(text, voice)
178
+ await communicate.save(output_file)
179
+
180
+ if not os.path.exists(output_file) or os.path.getsize(output_file) == 0:
181
+ raise RuntimeError("El archivo no se generó correctamente")
182
+
 
183
  return text, output_file
184
+
185
+ except Exception as e:
186
+ print(f"ERROR: {str(e)}")
187
+ return f"Error: {str(e)}", None