From 742a278c0509ee521f9b9fe0f011b29f42ef2a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 30 Mar 2026 13:58:14 -0700 Subject: [PATCH] audio(filters): remove NoisereduceFilter --- pyproject.toml | 1 - .../audio/filters/noisereduce_filter.py | 104 ------------------ 2 files changed, 105 deletions(-) delete mode 100644 src/pipecat/audio/filters/noisereduce_filter.py diff --git a/pyproject.toml b/pyproject.toml index 851c8c709..8accf7a4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,6 @@ mlx-whisper = [ "mlx-whisper~=0.4.2" ] moondream = [ "accelerate~=1.10.0", "einops~=0.8.0", "pyvips[binary]~=3.0.0", "timm~=1.0.13", "transformers>=4.48.0,<6" ] nebius = [] neuphonic = [ "pipecat-ai[websockets-base]" ] -noisereduce = [ "noisereduce~=3.0.3" ] novita = [] nvidia = [ "nvidia-riva-client>=2.25.1,<3" ] openai = [ "pipecat-ai[websockets-base]" ] diff --git a/src/pipecat/audio/filters/noisereduce_filter.py b/src/pipecat/audio/filters/noisereduce_filter.py deleted file mode 100644 index 377a45ff3..000000000 --- a/src/pipecat/audio/filters/noisereduce_filter.py +++ /dev/null @@ -1,104 +0,0 @@ -# -# Copyright (c) 2024-2026, Daily -# -# SPDX-License-Identifier: BSD 2-Clause License -# - -"""Noisereduce audio filter for Pipecat. - -This module provides an audio filter implementation using the noisereduce -library to reduce background noise in audio streams through spectral -gating algorithms. -""" - -import numpy as np -from loguru import logger - -from pipecat.audio.filters.base_audio_filter import BaseAudioFilter -from pipecat.frames.frames import FilterControlFrame, FilterEnableFrame - -try: - import noisereduce as nr -except ModuleNotFoundError as e: - logger.error(f"Exception: {e}") - logger.error( - "In order to use the noisereduce filter, you need to `pip install pipecat-ai[noisereduce]`." - ) - raise Exception(f"Missing module: {e}") - - -class NoisereduceFilter(BaseAudioFilter): - """Audio filter using the noisereduce library for noise suppression. - - Applies spectral gating noise reduction algorithms to suppress background - noise in audio streams. Uses the noisereduce library's default noise - reduction parameters. - - .. deprecated:: 0.0.85 - `NoisereduceFilter` is deprecated and will be removed in a future version. - We recommend using other real-time audio filters like `KrispFilter` or `AICFilter`. - """ - - def __init__(self) -> None: - """Initialize the noisereduce filter.""" - self._filtering = True - self._sample_rate = 0 - - import warnings - - with warnings.catch_warnings(): - warnings.simplefilter("always") - warnings.warn( - "`NoisereduceFilter` is deprecated. " - "Use other real-time audio filters like `KrispFilter` or `AICFilter`.", - DeprecationWarning, - stacklevel=2, - ) - - async def start(self, sample_rate: int): - """Initialize the filter with the transport's sample rate. - - Args: - sample_rate: The sample rate of the input transport in Hz. - """ - self._sample_rate = sample_rate - - async def stop(self): - """Clean up the filter when stopping.""" - pass - - async def process_frame(self, frame: FilterControlFrame): - """Process control frames to enable/disable filtering. - - Args: - frame: The control frame containing filter commands. - """ - if isinstance(frame, FilterEnableFrame): - self._filtering = frame.enable - - async def filter(self, audio: bytes) -> bytes: - """Apply noise reduction to audio data using spectral gating. - - Converts audio to float32, applies noisereduce processing, and returns - the filtered audio clipped to int16 range. - - Args: - audio: Raw audio data as bytes to be filtered. - - Returns: - Noise-reduced audio data as bytes. - """ - if not self._filtering: - return audio - - data = np.frombuffer(audio, dtype=np.int16) - - # Add a small epsilon to avoid division by zero. - epsilon = 1e-10 - data = data.astype(np.float32) + epsilon - - # Noise reduction - reduced_noise = nr.reduce_noise(y=data, sr=self._sample_rate) - audio = np.clip(reduced_noise, -32768, 32767).astype(np.int16).tobytes() - - return audio