Ë
    S^(h  ã                   ó�   — d Z ddlmZmZmZ ddlZddlmZ ddl	m
Z
 ddlmZmZmZ  ej                  e«      Z G d„ d	e«      Zd	gZy)
zFeature extractor class for DACé    )ÚListÚOptionalÚUnionNé   )ÚSequenceFeatureExtractor)ÚBatchFeature)ÚPaddingStrategyÚ
TensorTypeÚloggingc                   óø   ‡ — e Zd ZdZddgZ	 	 	 	 ddedededefˆ fd„Z	 	 	 	 	 dd	ee	j                  ee   ee	j                     eee      f   d
eeeeef      dee   dee   deeeef      dee   defd„Zˆ xZS )ÚDacFeatureExtractora>  
    Constructs an Dac feature extractor.

    This feature extractor inherits from [`~feature_extraction_sequence_utils.SequenceFeatureExtractor`] which contains
    most of the main methods. Users should refer to this superclass for more information regarding those methods.

    Args:
        feature_size (`int`, *optional*, defaults to 1):
            The feature dimension of the extracted features. Use 1 for mono, 2 for stereo.
        sampling_rate (`int`, *optional*, defaults to 16000):
            The sampling rate at which the audio waveform should be digitalized, expressed in hertz (Hz).
        padding_value (`float`, *optional*, defaults to 0.0):
            The value that is used for padding.
        hop_length (`int`, *optional*, defaults to 512):
            Overlap length between successive windows.
    Úinput_valuesÚn_quantizersÚfeature_sizeÚsampling_rateÚpadding_valueÚ
hop_lengthc                 ó:   •— t        ‰| �  d|||dœ|¤Ž || _        y )N)r   r   r   © )ÚsuperÚ__init__r   )Úselfr   r   r   r   ÚkwargsÚ	__class__s         €úl/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/dac/feature_extraction_dac.pyr   zDacFeatureExtractor.__init__1   s'   ø€ ô 	‰ÑÐw lÀ-Ð_lÑwÐpvÒwØ$ˆ�ó    Ú	raw_audioÚpaddingÚ
truncationÚ
max_lengthÚreturn_tensorsÚreturnc                 ó>  — |�;|| j                   k7  rYt        d| › d| j                   › d| j                   › d|› d�	«      ‚t        j                  d| j                  j
                  › d�«       |r|rt        d	«      ‚|€d
}t        t        |t        t        f«      xr( t        |d   t        j                  t        t        f«      «      }|r=|D �cg c]1  }t        j                  |t        j                  ¬«      j                  ‘Œ3 }}nª|s@t        |t        j                  «      s&t        j                  |t        j                  ¬«      }nht        |t        j                  «      rN|j                  t        j                  t        j                   «      u r|j#                  t        j                  «      }|s t        j                  |«      j                  g}t%        |«      D ]€  \  }	}
|
j&                  dkD  rt        d|
j(                  › �«      ‚| j*                  dk(  r+|
j&                  dk7  rt        d|
j(                  d   › d�«      ‚| j*                  dk(  sŒwt        d«      ‚ t-        d|i«      }| j/                  ||||d| j0                  ¬«      }|r)|j2                  dd…t        j4                  dd…f   |_        g }|j7                  d«      D ]1  }
| j*                  dk(  r|
d   }
|j9                  |
j                  «       Œ3 ||d<   |�|j;                  |«      }|S c c}w )aÞ  
        Main method to featurize and prepare for the model one or several sequence(s).

        Args:
            raw_audio (`np.ndarray`, `List[float]`, `List[np.ndarray]`, `List[List[float]]`):
                The sequence or batch of sequences to be processed. Each sequence can be a numpy array, a list of float
                values, a list of numpy arrays or a list of list of float values. The numpy array must be of shape
                `(num_samples,)` for mono audio (`feature_size = 1`), or `(2, num_samples)` for stereo audio
                (`feature_size = 2`).
            padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `True`):
                Select a strategy to pad the returned sequences (according to the model's padding side and padding
                index) among:

                - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
                  sequence if provided).
                - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
                  acceptable input length for the model if that argument is not provided.
                - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
                  lengths).
            truncation (`bool`, *optional*, defaults to `False`):
                Activates truncation to cut input sequences longer than `max_length` to `max_length`.
            max_length (`int`, *optional*):
                Maximum length of the returned list and optionally padding length (see above).
            return_tensors (`str` or [`~utils.TensorType`], *optional*, default to 'pt'):
                If set, will return tensors instead of list of python integers. Acceptable values are:

                - `'tf'`: Return TensorFlow `tf.constant` objects.
                - `'pt'`: Return PyTorch `torch.Tensor` objects.
                - `'np'`: Return Numpy `np.ndarray` objects.
            sampling_rate (`int`, *optional*):
                The sampling rate at which the `audio` input was sampled. It is strongly recommended to pass
                `sampling_rate` at the forward call to prevent silent errors.
        Nz3The model corresponding to this feature extractor: z& was trained using a sampling rate of zB. Please make sure that the provided audio input was sampled with z	 and not ú.zDIt is strongly recommended to pass the `sampling_rate` argument to `zN()`. Failing to do so can result in silent errors that might be hard to debug.zABoth padding and truncation were set. Make sure you only set one.Tr   )Údtypeé   z6Expected input shape (channels, length) but got shape é   z$Expected mono audio but example has éÿÿÿÿz	 channelsz$Stereo audio isn't supported for nowr   F)r    r   r   Úreturn_attention_maskÚpad_to_multiple_of).N)r   Ú
ValueErrorÚloggerÚwarningr   Ú__name__ÚboolÚ
isinstanceÚlistÚtupleÚnpÚndarrayÚasarrayÚfloat32ÚTr%   Úfloat64ÚastypeÚ	enumerateÚndimÚshaper   r   Úpadr   r   ÚnewaxisÚpopÚappendÚconvert_to_tensors)r   r   r   r   r    r!   r   Ú
is_batchedÚaudioÚidxÚexampler   Úpadded_inputss                r   Ú__call__zDacFeatureExtractor.__call__<   sù  € ðT Ð$Ø × 2Ñ 2Ò2Ü ØIÈ$Èð PØ×*Ñ*Ð+ð ,Ø×*Ñ*Ð+¨9°]°OÀ1ðFóð ô �N‰NØVÐW[×WeÑWe×WnÑWnÐVoð p\ð \ôñ
 ‘zÜÐ`ÓaÐaØˆ_àˆGäÜ�y¤4¬ -Ó0Òj´jÀÈ1ÁÔPR×PZÑPZÔ\aÔcgÐOhÓ6ió
ˆ
ñ ØLUÖVÀ5œŸ™ E´·±Ô<×>Ó>ÐVˆIÑVÙ¤J¨y¼"¿*¹*Ô$EÜŸ
™
 9´B·J±JÔ?‰IÜ˜	¤2§:¡:Ô.°9·?±?ÄbÇhÁhÌrÏzÉzÓFZÑ3ZØ!×(Ñ(¬¯©Ó4ˆIñ ÜŸ™ IÓ.×0Ñ0Ð1ˆIô & iÓ0ò 	I‰LˆC�Ø�|‰|˜aÒÜ Ð#YÐZa×ZgÑZgÐYhÐ!iÓjÐjØ× Ñ  AÒ%¨'¯,©,¸!Ò*;Ü Ð#GÈÏÉÐVXÑHYÐGZÐZcÐ!dÓeÐeØ× Ñ  AÓ%Ü Ð!GÓHÐHð	Iô $ ^°YÐ$?Ó@ˆð Ÿ™ØØ!Ø!ØØ"'Ø#Ÿ™ð !ó 
ˆñ Ø)6×)CÑ)CÂAÄrÇzÁzÒSTÐDTÑ)UˆMÔ&àˆØ$×(Ñ(¨Ó8ò 	+ˆGØ× Ñ  AÒ%Ø! )Ñ,�Ø×Ñ §	¡	Õ*ð	+ð
 )5ˆ�nÑ%ØÐ%Ø)×<Ñ<¸^ÓLˆMàÐùòY Ws   Ã6L)r'   i€>  g        i   )NFNNN)r.   Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesÚintÚfloatr   r   r3   r4   r   r   r/   Ústrr	   r
   r   rG   Ú__classcell__)r   s   @r   r   r      s  ø„ ñð" (¨Ð8Ðð Ø"Ø"Øñ	%àð	%ð ð	%ð ð		%ð
 õ	%ð @DØ%*Ø$(Ø;?Ø'+ñnà˜Ÿ™ T¨%¡[°$°r·z±zÑ2BÀDÈÈeÉÑDUÐUÑVðnð ˜%  c¨?Ð :Ñ;Ñ<ðnð ˜T‘Nð	nð
 ˜S‘Mðnð !  s¨J Ñ!7Ñ8ðnð   ‘}ðnð 
÷nr   r   )rJ   Útypingr   r   r   Únumpyr3   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr	   r
   r   Ú
get_loggerr.   r,   r   Ú__all__r   r   r   ú<module>rW      sM   ðñ &ç (Ñ (ã å IÝ 4ß 9Ñ 9ð 
ˆ×	Ñ	˜HÓ	%€ôMÐ2ô Mð` !Ð
!�r   