VeuReu commited on
Commit
08d7860
verified
1 Parent(s): e7cce35

Upload tts_ad_from_srt.py

Browse files
Files changed (1) hide show
  1. tts_ad_from_srt.py +24 -4
tts_ad_from_srt.py CHANGED
@@ -42,7 +42,7 @@ def _is_empty_ad_text(t: str) -> bool:
42
 
43
  def parse_srt_ad_only(path: str) -> List[Segment]:
44
  """
45
- Devuelve s贸lo segmentos cuyo bloque contiene l铆neas que empiezan por '(AD):'.
46
  Ignora los (AD) sin informaci贸n (punto 1 del encargo).
47
  """
48
  with open(path, "r", encoding="utf-8") as f:
@@ -68,8 +68,21 @@ def parse_srt_ad_only(path: str) -> List[Segment]:
68
  ad_texts = []
69
  for t in lines[2:]:
70
  t = t.strip()
71
- if t.startswith("(AD):"):
72
- t = t[len("(AD):"):].lstrip()
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  if t and not _is_empty_ad_text(t):
74
  ad_texts.append(t)
75
 
@@ -265,7 +278,14 @@ def ffmpeg_mux_video_with_audio(video_mp4: str, audio_mp3: str, out_mp4: str) ->
265
  def build_ad_track_from_srt(srt_path: str, output_path: str = "ad_master.mp3", voice: str = "central/grau") -> str:
266
  segs = parse_srt_ad_only(srt_path)
267
  if not segs:
268
- raise SystemExit("No se encontraron bloques (AD) con contenido en el SRT.")
 
 
 
 
 
 
 
269
  result = mix_segments_on_timeline(segs, voice=voice, out_final=output_path)
270
  return result
271
 
 
42
 
43
  def parse_srt_ad_only(path: str) -> List[Segment]:
44
  """
45
+ Devuelve s贸lo segmentos cuyo bloque contiene l铆neas que empiezan por '(AD):', '[AD]:', '(AD)' o '[AD]'.
46
  Ignora los (AD) sin informaci贸n (punto 1 del encargo).
47
  """
48
  with open(path, "r", encoding="utf-8") as f:
 
68
  ad_texts = []
69
  for t in lines[2:]:
70
  t = t.strip()
71
+ # Aceptar m煤ltiples formatos: (AD):, [AD]:, (AD), [AD]
72
+ if (t.startswith("(AD):") or t.startswith("[AD]:") or
73
+ t.startswith("(AD)") and not t.startswith("(AD):") or
74
+ t.startswith("[AD]") and not t.startswith("[AD]:")):
75
+
76
+ # Extraer el texto despu茅s del prefijo
77
+ if t.startswith("(AD):"):
78
+ t = t[len("(AD):"):].lstrip()
79
+ elif t.startswith("[AD]:"):
80
+ t = t[len("[AD]:"):].lstrip()
81
+ elif t.startswith("(AD)"):
82
+ t = t[len("(AD)"):].lstrip()
83
+ elif t.startswith("[AD]"):
84
+ t = t[len("[AD]"):].lstrip()
85
+
86
  if t and not _is_empty_ad_text(t):
87
  ad_texts.append(t)
88
 
 
278
  def build_ad_track_from_srt(srt_path: str, output_path: str = "ad_master.mp3", voice: str = "central/grau") -> str:
279
  segs = parse_srt_ad_only(srt_path)
280
  if not segs:
281
+ # En lugar de fallar, crear un archivo de audio silencioso
282
+ print("鈿狅笍 No se encontraron bloques (AD) con contenido en el SRT. Creando pista silenciosa.")
283
+ from pydub import AudioSegment
284
+ # Crear 1 segundo de silencio
285
+ silence = AudioSegment.silent(duration=1000)
286
+ silence.export(output_path, format="mp3" if output_path.endswith(".mp3") else "wav")
287
+ return output_path
288
+
289
  result = mix_segments_on_timeline(segs, voice=voice, out_final=output_path)
290
  return result
291