gnosticdev commited on
Commit
97cd35a
·
verified ·
1 Parent(s): 2b097e8

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +18 -18
conver.py CHANGED
@@ -76,23 +76,23 @@ class URLToAudioConverter:
76
  raise RuntimeError(f"Failed to parse dialogue: {str(e)}")
77
 
78
  async def text_to_speech(self, conversation_json: Dict, voice_1: str, voice_2: str) -> Tuple[List[str], str]:
79
- output_dir = Path(self._create_output_directory())
80
- filenames = []
81
- try:
82
- if not conversation_json["conversation"]:
83
- raise ValueError("No conversation data to process")
84
- for i, turn in enumerate(conversation_json["conversation"]):
85
- filename = output_dir / f"segment_{i}.mp3"
86
- voice = voice_1 if turn["speaker"] == "Anfitrión1" else voice_2
87
- print(f"Generando audio para {turn['speaker']}: {turn['text'][:50]}... con voz {voice}")
88
- tmp_path = await self._generate_audio(turn["text"], voice)
89
- os.rename(tmp_path, filename)
90
- filenames.append(str(filename))
91
- if not filenames:
92
- raise ValueError("No audio files generated")
93
- return filenames, str(output_dir)
94
- except Exception as e:
95
- raise RuntimeError(f"Text-to-speech failed: {e}")
96
 
97
  async def _generate_audio(self, text: str, voice: str) -> str:
98
  if not text.strip():
@@ -186,4 +186,4 @@ class URLToAudioConverter:
186
  f"{turn['speaker']}: {turn['text']}"
187
  for turn in conversation["conversation"]
188
  )
189
- return output_path, text_output
 
76
  raise RuntimeError(f"Failed to parse dialogue: {str(e)}")
77
 
78
  async def text_to_speech(self, conversation_json: Dict, voice_1: str, voice_2: str) -> Tuple[List[str], str]:
79
+ output_dir = Path(self._create_output_directory())
80
+ filenames = []
81
+ try:
82
+ if not conversation_json["conversation"]:
83
+ raise ValueError("No conversation data to process")
84
+ for i, turn in enumerate(conversation_json["conversation"]):
85
+ filename = output_dir / f"segment_{i}.mp3"
86
+ voice = voice_1 if turn["speaker"] == "Anfitrión1" else voice_2
87
+ print(f"Generando audio para {turn['speaker']}: {turn['text'][:50]}... con voz {voice}")
88
+ tmp_path = await self._generate_audio(turn["text"], voice)
89
+ os.rename(tmp_path, filename)
90
+ filenames.append(str(filename))
91
+ if not filenames:
92
+ raise ValueError("No audio files generated")
93
+ return filenames, str(output_dir)
94
+ except Exception as e:
95
+ raise RuntimeError(f"Text-to-speech failed: {e}")
96
 
97
  async def _generate_audio(self, text: str, voice: str) -> str:
98
  if not text.strip():
 
186
  f"{turn['speaker']}: {turn['text']}"
187
  for turn in conversation["conversation"]
188
  )
189
+ return output_path, text_output