From 7f1ae4b8ccd846366fd21eac070bf6356c9da74d Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Tue, 4 Feb 2025 20:10:56 -0300 Subject: [PATCH] Fixing the issue in Krisp when trying to create more than one filter in the same process. --- src/pipecat/audio/filters/krisp_filter.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pipecat/audio/filters/krisp_filter.py b/src/pipecat/audio/filters/krisp_filter.py index 194dd848d..b23a46b65 100644 --- a/src/pipecat/audio/filters/krisp_filter.py +++ b/src/pipecat/audio/filters/krisp_filter.py @@ -20,6 +20,22 @@ except ModuleNotFoundError as e: raise Exception(f"Missing module: {e}") +class KrispProcessorManager: + """ + Ensures that only one KrispAudioProcessor instance exists for the entire program. + """ + + _krisp_instance = None + + @classmethod + def get_processor(cls, sample_rate: int, sample_type: str, channels: int, model_path: str): + if cls._krisp_instance is None: + cls._krisp_instance = KrispAudioProcessor( + sample_rate, sample_type, channels, model_path + ) + return cls._krisp_instance + + class KrispFilter(BaseAudioFilter): def __init__( self, sample_type: str = "PCM_16", channels: int = 1, model_path: str = None @@ -48,7 +64,7 @@ class KrispFilter(BaseAudioFilter): async def start(self, sample_rate: int): self._sample_rate = sample_rate - self._krisp_processor = KrispAudioProcessor( + self._krisp_processor = KrispProcessorManager.get_processor( self._sample_rate, self._sample_type, self._channels, self._model_path )