From 5871858a5f12536e823a70f8e77265a462ff37b9 Mon Sep 17 00:00:00 2001 From: Guillaume Klein Date: Fri, 1 Sep 2023 15:25:13 +0200 Subject: [PATCH] Force the garbage collector to run after decoding the audio with PyAV (#448) --- faster_whisper/audio.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/faster_whisper/audio.py b/faster_whisper/audio.py index fbecc48..4dd8aae 100644 --- a/faster_whisper/audio.py +++ b/faster_whisper/audio.py @@ -6,6 +6,7 @@ system dependencies. FFmpeg does not need to be installed on the system. However, the API is quite low-level so we need to manipulate audio frames directly. """ +import gc import io import itertools @@ -53,6 +54,11 @@ def decode_audio( dtype = array.dtype raw_buffer.write(array) + # It appears that some objects related to the resampler are not freed + # unless the garbage collector is manually run. + del resampler + gc.collect() + audio = np.frombuffer(raw_buffer.getbuffer(), dtype=dtype) # Convert s16 back to f32.