From ca3290620280fdea1b0312f42cf9c2ae4e604c8d Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Tue, 26 Nov 2024 20:10:50 +0000 Subject: [PATCH] add cleanup for generated audio files; ensure temporary files are removed after processing --- api/src/utils/generate_audiocast.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/src/utils/generate_audiocast.py b/api/src/utils/generate_audiocast.py index 5ba3530..2adfe1e 100644 --- a/api/src/utils/generate_audiocast.py +++ b/api/src/utils/generate_audiocast.py @@ -1,3 +1,5 @@ +import os + from fastapi import BackgroundTasks, HTTPException from src.services.storage import StorageManager @@ -36,6 +38,9 @@ def post_generate_audio( waveform_utils.run_all() except Exception as e: print(f"Error in generate_audiocast background_tasks: {str(e)}") + finally: + if os.path.exists(audio_path): + os.remove(audio_path) async def generate_audiocast(request: GenerateAudioCastRequest, background_tasks: BackgroundTasks):