fix(tts): ensure AudioFileClip is always closed in ElevenLabs, Chatterbox, and Fish Audio - #1269
Merged
harry0703 merged 1 commit intoAug 26, 2026
Conversation
…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.
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
elevenlabs_tts,chatterbox_tts, andfish_audio_ttseach open anAudioFileClip(spawning an FFmpeg subprocess) and call.close()inplain sequential code, with no
try/finally. If anything raises betweenconstruction and close the subprocess leaks.
_write_validated_minimax_audioalready wraps.durationintry/finally; this PR extends that pattern to the threeremaining providers.
Changes
audio_clip.durationintry/finally: audio_clip.close()inelevenlabs_tts,chatterbox_tts, andfish_audio_tts(
app/services/voice.py).durationto raise aRuntimeErrorand assert
.close()is still calledTest plan
test_elevenlabs_tts_audio_clip_closed_on_duration_errorpassestest_chatterbox_tts_audio_clip_closed_on_duration_errorpassestest_fish_audio_tts_audio_clip_closed_on_duration_errorpasses