Skip to content

fix(tts): ensure AudioFileClip is always closed in ElevenLabs, Chatterbox, and Fish Audio - #1269

Merged
harry0703 merged 1 commit into
harry0703:mainfrom
Mihir7027:fix/audio-clip-leak-in-tts-providers
Aug 26, 2026
Merged

fix(tts): ensure AudioFileClip is always closed in ElevenLabs, Chatterbox, and Fish Audio#1269
harry0703 merged 1 commit into
harry0703:mainfrom
Mihir7027:fix/audio-clip-leak-in-tts-providers

Conversation

@Mihir7027

Copy link
Copy Markdown
Contributor

Summary

  • elevenlabs_tts, chatterbox_tts, and fish_audio_tts each open an
    AudioFileClip (spawning an FFmpeg subprocess) and call .close() in
    plain sequential code, with no try/finally. If anything raises between
    construction and close the subprocess leaks.
  • The pre-existing _write_validated_minimax_audio already wraps
    .duration in try/finally; this PR extends that pattern to the three
    remaining providers.

Changes

  • Wrapped audio_clip.duration in try/finally: audio_clip.close() in
    elevenlabs_tts, chatterbox_tts, and fish_audio_tts
    (app/services/voice.py)
  • Added three unit tests that mock .duration to raise a RuntimeError
    and assert .close() is still called

Test plan

  • test_elevenlabs_tts_audio_clip_closed_on_duration_error passes
  • test_chatterbox_tts_audio_clip_closed_on_duration_error passes
  • test_fish_audio_tts_audio_clip_closed_on_duration_error passes
  • Existing ElevenLabs/Chatterbox TTS success tests still pass

…chatterbox, and fish_audio

In a long-running FastAPI server process, MoviePy's AudioFileClip spawns
an FFmpeg subprocess.  If anything raises between AudioFileClip() and
.close() the subprocess is leaked.  The three providers affected
(elevenlabs_tts, chatterbox_tts, fish_audio_tts) all used the bare
sequential pattern; the pre-existing _write_validated_minimax_audio
already wraps .duration in try/finally.  This commit makes all four
sites consistent.

Add three unit tests that confirm .close() is called even when reading
.duration raises a RuntimeError.
@harry0703
harry0703 merged commit cc68132 into harry0703:main Aug 26, 2026
3 checks passed
@harry0703

Copy link
Copy Markdown
Owner

Thanks for fixing these resource cleanup paths and adding regression tests for all three providers. I verified the change against the latest main, and the focused and full test suites pass. Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants