o
    i                     @   s   U d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	Z	ddl
mZ ddlmZ ddlmZ e Zi aeeef ed< daee ed	< ejd
ejdiZdddededefddZdS )zDTMF audio utilities.

This module provides functionality to load DTMF (Dual-Tone Multi-Frequency)
audio files corresponding to phone keypad entries. Audio data is cached
in-memory after first load to improve performance on subsequent accesses.
    N)files)DictOptional)KeypadEntry)BaseAudioResampler)create_file_resampler__DTMF_AUDIO____DTMF_RESAMPLER__zdtmf-pound.wavzdtmf-star.wavi@  )sample_ratebuttonr
   returnc             
      sp  t 4 I dH  | tv rt|  W  d  I dH  S tst at| d| j d}td|}t	
|d4 I dH }| I dH }W d  I dH  n1 I dH sSw   Y  t|7}t
|d!}|| }| }	t||	|I dH }
|
t| < W d   n1 sw   Y  W d   n1 sw   Y  W d  I dH  t|  S 1 I dH sw   Y  t|  S )a<  Load audio for DTMF tones associated with the given button.

    Args:
        button (KeypadEntry): The button for which the DTMF audio is to be loaded.
        sample_rate (int, optional): The sample rate for the audio. Defaults to 8000.

    Returns:
        bytes: The audio data for the DTMF tone as bytes.
    Nzdtmf-z.wavzpipecat.audio.dtmfrb)__DTMF_LOCK__r   r	   r   __DTMF_FILE_NAMEgetvaluer   joinpathaiofilesopenreadioBytesIOwave
readframes
getnframesgetframerateresample)r   r
   dtmf_file_namedtmf_file_pathfdatabufferwfaudioin_sample_rateresampled_audio r&   L/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/audio/dtmf/utils.pyload_dtmf_audio$   s6   (

r(   )__doc__asyncior   r   importlib.resourcesr   typingr   r   r   pipecat.audio.dtmf.typesr   -pipecat.audio.resamplers.base_audio_resamplerr   pipecat.audio.utilsr   Lockr   r   bytes__annotations__r	   POUNDSTARr   intr(   r&   r&   r&   r'   <module>   s"    