From ff3b744a05924c13cfd7c268d87e72ee6bdd0538 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 21 Nov 2025 01:04:09 -0500 Subject: feat: implement t-1rf15iH --- Biz/PodcastItLater/Worker.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Biz/PodcastItLater/Worker.py b/Biz/PodcastItLater/Worker.py index 5203490..48793cd 100644 --- a/Biz/PodcastItLater/Worker.py +++ b/Biz/PodcastItLater/Worker.py @@ -60,6 +60,8 @@ MAX_RETRIES = 3 TTS_MODEL = "tts-1" TTS_VOICE = "alloy" MEMORY_THRESHOLD = 80 # Percentage threshold for memory usage +CROSSFADE_DURATION = 500 # ms for crossfading segments +PAUSE_DURATION = 1000 # ms for silence between segments class ShutdownHandler: @@ -358,7 +360,7 @@ class ArticleProcessor: content_audio: bytes, outro_audio: bytes, ) -> bytes: - """Combine intro, content, and outro with 1-second pauses. + """Combine intro, content, and outro with crossfades. Args: intro_audio: MP3 bytes for intro @@ -373,11 +375,27 @@ class ArticleProcessor: content = AudioSegment.from_mp3(io.BytesIO(content_audio)) outro = AudioSegment.from_mp3(io.BytesIO(outro_audio)) - # Create 1-second silence - pause = AudioSegment.silent(duration=1000) # milliseconds + # Create bridge silence (pause + 2 * crossfade to account for overlap) + bridge = AudioSegment.silent(duration=PAUSE_DURATION + 2 * CROSSFADE_DURATION) - # Combine segments with pauses - combined = intro + pause + content + pause + outro + def safe_append(seg1: AudioSegment, seg2: AudioSegment, crossfade: int) -> AudioSegment: + if len(seg1) < crossfade or len(seg2) < crossfade: + logger.warning( + "Segment too short for crossfade (%dms vs %dms/%dms), using concatenation", + crossfade, + len(seg1), + len(seg2), + ) + return seg1 + seg2 + return seg1.append(seg2, crossfade=crossfade) + + # Combine segments with crossfades + # Intro -> Bridge -> Content -> Bridge -> Outro + # This effectively fades out the previous segment and fades in the next one + combined = safe_append(intro, bridge, CROSSFADE_DURATION) + combined = safe_append(combined, content, CROSSFADE_DURATION) + combined = safe_append(combined, bridge, CROSSFADE_DURATION) + combined = safe_append(combined, outro, CROSSFADE_DURATION) # Export to bytes output = io.BytesIO() -- cgit v1.2.3