gnosticdev commited on
Commit
cc36c27
·
verified ·
1 Parent(s): 37a6fed

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +16 -11
conver.py CHANGED
@@ -155,27 +155,31 @@ class URLToAudioConverter:
155
  speech_audio: AudioSegment,
156
  music_path: str,
157
  tags_paths: List[str],
158
- custom_music_path: str = None
 
159
  ) -> AudioSegment:
160
- music_file = custom_music_path if custom_music_path and os.path.exists(custom_music_path) else self.MUSICA_FONDO
161
  tag_outro_file = self.TAG1
162
  tag_trans_file = self.TAG2
163
 
164
- if not os.path.exists(music_file):
165
- raise FileNotFoundError(f"Music file not found: {music_file}")
166
  if not os.path.exists(tag_outro_file):
167
  raise FileNotFoundError(f"Tag file not found: {tag_outro_file}")
168
  if not os.path.exists(tag_trans_file):
169
  raise FileNotFoundError(f"Tag file not found: {tag_trans_file}")
170
 
171
- music = AudioSegment.from_file(music_file).fade_out(2000) - 25
172
- if len(music) < len(speech_audio):
173
- music = music * ((len(speech_audio) // len(music)) + 1)
174
- music = music[:len(speech_audio)]
175
- mixed = speech_audio.overlay(music)
 
 
 
 
 
 
176
  tag_outro = AudioSegment.from_file(tag_outro_file) - 10
177
  tag_trans = AudioSegment.from_file(tag_trans_file) - 10
178
- final_audio = mixed + tag_outro
179
  silent_ranges = []
180
  for i in range(0, len(speech_audio) - 500, 100):
181
  chunk = speech_audio[i:i+500]
@@ -214,7 +218,8 @@ class URLToAudioConverter:
214
  combined,
215
  self.MUSICA_FONDO,
216
  [self.TAG1, self.TAG2],
217
- custom_music_path
 
218
  )
219
  output_path = os.path.join(folder_name, "podcast_final.mp3")
220
  final_audio.export(output_path, format="mp3")
 
155
  speech_audio: AudioSegment,
156
  music_path: str,
157
  tags_paths: List[str],
158
+ custom_music_path: str = None,
159
+ use_background_music: bool = True
160
  ) -> AudioSegment:
 
161
  tag_outro_file = self.TAG1
162
  tag_trans_file = self.TAG2
163
 
 
 
164
  if not os.path.exists(tag_outro_file):
165
  raise FileNotFoundError(f"Tag file not found: {tag_outro_file}")
166
  if not os.path.exists(tag_trans_file):
167
  raise FileNotFoundError(f"Tag file not found: {tag_trans_file}")
168
 
169
+ final_audio = speech_audio
170
+ if use_background_music:
171
+ music_file = custom_music_path if custom_music_path and os.path.exists(custom_music_path) else self.MUSICA_FONDO
172
+ if not os.path.exists(music_file):
173
+ raise FileNotFoundError(f"Music file not found: {music_file}")
174
+ music = AudioSegment.from_file(music_file).fade_out(2000) - 25
175
+ if len(music) < len(speech_audio):
176
+ music = music * ((len(speech_audio) // len(music)) + 1)
177
+ music = music[:len(speech_audio)]
178
+ final_audio = final_audio.overlay(music)
179
+
180
  tag_outro = AudioSegment.from_file(tag_outro_file) - 10
181
  tag_trans = AudioSegment.from_file(tag_trans_file) - 10
182
+ final_audio = final_audio + tag_outro
183
  silent_ranges = []
184
  for i in range(0, len(speech_audio) - 500, 100):
185
  chunk = speech_audio[i:i+500]
 
218
  combined,
219
  self.MUSICA_FONDO,
220
  [self.TAG1, self.TAG2],
221
+ custom_music_path,
222
+ use_background_music=custom_music_path is not None
223
  )
224
  output_path = os.path.join(folder_name, "podcast_final.mp3")
225
  final_audio.export(output_path, format="mp3")