gnosticdev commited on
Commit
26a40ee
·
verified ·
1 Parent(s): f560070

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +9 -3
conver.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from dataclasses import dataclass
2
  from typing import List, Tuple, Dict
3
  import os
@@ -14,7 +15,7 @@ from threading import Thread
14
 
15
  @dataclass
16
  class ConversationConfig:
17
- max_words: int = 5000 # Aumentado para diálogos más largos
18
  prefix_url: str = "https://r.jina.ai/"
19
  model_name: str = "meta-llama/Llama-3-8b-chat-hf"
20
 
@@ -23,10 +24,9 @@ class URLToAudioConverter:
23
  self.config = config
24
  self.llm_client = OpenAI(api_key=llm_api_key, base_url="https://api.together.xyz/v1")
25
  self.llm_out = None
26
- self._start_cleaner() # Inicia limpieza automática
27
 
28
  def _start_cleaner(self, max_age_hours: int = 24):
29
- """Elimina archivos antiguos cada hora"""
30
  def cleaner():
31
  while True:
32
  now = time.time()
@@ -80,12 +80,17 @@ class URLToAudioConverter:
80
  output_dir = Path(self._create_output_directory())
81
  filenames = []
82
  try:
 
 
83
  for i, turn in enumerate(conversation_json["conversation"]):
84
  filename = output_dir / f"segment_{i}.mp3"
85
  voice = voice_1 if turn["speaker"] == "Anfitrión1" else voice_2
 
86
  tmp_path = await self._generate_audio(turn["text"], voice)
87
  os.rename(tmp_path, filename)
88
  filenames.append(str(filename))
 
 
89
  return filenames, str(output_dir)
90
  except Exception as e:
91
  raise RuntimeError(f"Text-to-speech failed: {e}")
@@ -183,3 +188,4 @@ class URLToAudioConverter:
183
  for turn in conversation["conversation"]
184
  )
185
  return output_path, text_output
 
 
1
+ ```python
2
  from dataclasses import dataclass
3
  from typing import List, Tuple, Dict
4
  import os
 
15
 
16
  @dataclass
17
  class ConversationConfig:
18
+ max_words: int = 3000
19
  prefix_url: str = "https://r.jina.ai/"
20
  model_name: str = "meta-llama/Llama-3-8b-chat-hf"
21
 
 
24
  self.config = config
25
  self.llm_client = OpenAI(api_key=llm_api_key, base_url="https://api.together.xyz/v1")
26
  self.llm_out = None
27
+ self._start_cleaner()
28
 
29
  def _start_cleaner(self, max_age_hours: int = 24):
 
30
  def cleaner():
31
  while True:
32
  now = time.time()
 
80
  output_dir = Path(self._create_output_directory())
81
  filenames = []
82
  try:
83
+ if not conversation_json["conversation"]:
84
+ raise ValueError("No conversation data to process")
85
  for i, turn in enumerate(conversation_json["conversation"]):
86
  filename = output_dir / f"segment_{i}.mp3"
87
  voice = voice_1 if turn["speaker"] == "Anfitrión1" else voice_2
88
+ print(f"Generating audio for {turn['speaker']}: {turn['text'][:50]}... with voice {voice}")
89
  tmp_path = await self._generate_audio(turn["text"], voice)
90
  os.rename(tmp_path, filename)
91
  filenames.append(str(filename))
92
+ if not filenames:
93
+ raise ValueError("No audio files generated")
94
  return filenames, str(output_dir)
95
  except Exception as e:
96
  raise RuntimeError(f"Text-to-speech failed: {e}")
 
188
  for turn in conversation["conversation"]
189
  )
190
  return output_path, text_output
191
+ ```