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.