From 02cfb129d32be44a31bae95975fe3cd4ee369556 Mon Sep 17 00:00:00 2001 From: filipi87 Date: Tue, 24 Mar 2026 10:49:14 -0300 Subject: [PATCH] Invoke cleanup method on VAD analyzer. --- src/pipecat/audio/vad/vad_analyzer.py | 9 +++++++++ src/pipecat/audio/vad/vad_controller.py | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/pipecat/audio/vad/vad_analyzer.py b/src/pipecat/audio/vad/vad_analyzer.py index 2c3ef5531..c519b0861 100644 --- a/src/pipecat/audio/vad/vad_analyzer.py +++ b/src/pipecat/audio/vad/vad_analyzer.py @@ -242,3 +242,12 @@ class VADAnalyzer(ABC): self._vad_stopping_count = 0 return self._vad_state + + async def cleanup(self): + """Clean up resources. + + This method should be called when the object is no longer needed. + It waits for all currently executing event handler tasks to finish + before returning. + """ + pass diff --git a/src/pipecat/audio/vad/vad_controller.py b/src/pipecat/audio/vad/vad_controller.py index 1db590e10..0316f3793 100644 --- a/src/pipecat/audio/vad/vad_controller.py +++ b/src/pipecat/audio/vad/vad_controller.py @@ -109,6 +109,16 @@ class VADController(BaseObject): # Broadcast initial VAD params so other services (e.g. STT) can use them await self.broadcast_frame(SpeechControlParamsFrame, vad_params=self._vad_analyzer.params) + async def cleanup(self): + """Clean up resources. + + This method should be called when the object is no longer needed. + It waits for all currently executing event handler tasks to finish + before returning. + """ + if self._vad_analyzer: + await self._vad_analyzer.cleanup() + async def _handle_audio(self, frame: InputAudioRawFrame): """Process an audio chunk and emit speech events as needed.