o
    i                     @   s4   d Z ddlZddlZddlmZ G dd deZdS )zResampy-based audio resampler implementation.

This module provides an audio resampler that uses the resampy library
for high-quality audio sample rate conversion.
    N)BaseAudioResamplerc                   @   s2   e Zd ZdZdd Zdedededefdd	Zd
S )ResampyResamplerzAudio resampler implementation using the resampy library.

    This resampler uses the resampy library's Kaiser windowing filter
    for high-quality audio resampling with good performance characteristics.
    c                 K   s   dS )zInitialize the resampy resampler.

        Args:
            **kwargs: Additional keyword arguments (currently unused).
        N )selfkwargsr   r   ^/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/audio/resamplers/resampy_resampler.py__init__   s   zResampyResampler.__init__audioin_rateout_ratereturnc                    sD   ||kr|S t j|t jd}tj|||dd}|t j }|S )aH  Resample audio data using resampy library.

        Args:
            audio: Input audio data as raw bytes (16-bit signed integers).
            in_rate: Original sample rate in Hz.
            out_rate: Target sample rate in Hz.

        Returns:
            Resampled audio data as raw bytes (16-bit signed integers).
        )dtypekaiser_fast)filter)np
frombufferint16resampyresampleastypetobytes)r   r	   r
   r   
audio_dataresampled_audioresultr   r   r   r   "   s   zResampyResampler.resampleN)__name__
__module____qualname____doc__r   bytesintr   r   r   r   r   r      s    r   )r   numpyr   r   -pipecat.audio.resamplers.base_audio_resamplerr   r   r   r   r   r   <module>   s
   