Ë
    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 EnCodec.é    )ÚListÚOptionalÚUnionNé   )ÚSequenceFeatureExtractor)ÚBatchFeature)ÚPaddingStrategyÚ
TensorTypeÚloggingc                   óB  ‡ — e Zd ZdZddgZ	 	 	 	 	 ddedededee   dee   f
ˆ fd	„Ze	d
ee   fd„«       Z
e	d
ee   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 )ÚEncodecFeatureExtractora  
    Constructs an EnCodec 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.

    Instantiating a feature extractor with the defaults will yield a similar configuration to that of the
    [facebook/encodec_24khz](https://huggingface.co/facebook/encodec_24khz) architecture.

    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 24000):
            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 to fill the padding values.
        chunk_length_s (`float`, *optional*):
            If defined the audio is pre-processed into chunks of lengths `chunk_length_s` and then encoded.
        overlap (`float`, *optional*):
            Defines the overlap between each chunk. It is used to compute the `chunk_stride` using the following
            formulae : `int((1.0 - self.overlap) * self.chunk_length)`.
    Úinput_valuesÚpadding_maskÚfeature_sizeÚsampling_rateÚpadding_valueÚchunk_length_sÚoverlapc                 óH   •— t        ‰| �  d|||dœ|¤Ž || _        || _        y )N)r   r   r   © )ÚsuperÚ__init__r   r   )Úselfr   r   r   r   r   ÚkwargsÚ	__class__s          €út/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/encodec/feature_extraction_encodec.pyr   z EncodecFeatureExtractor.__init__7   s/   ø€ ô 	‰ÑÐw lÀ-Ð_lÑwÐpvÒwØ,ˆÔØˆ�ó    Úreturnc                 ó`   — | j                   €y t        | j                   | j                  z  «      S )N)r   Úintr   ©r   s    r   Úchunk_lengthz$EncodecFeatureExtractor.chunk_lengthE   s-   € à×ÑÐ&Øä�t×*Ñ*¨T×-?Ñ-?Ñ?Ó@Ð@r   c                 ó’   — | j                   �| j                  €y t        dt        d| j                  z
  | j                  z  «      «      S )Né   g      ð?)r   r   Úmaxr    r"   r!   s    r   Úchunk_stridez$EncodecFeatureExtractor.chunk_strideM   s@   € à×ÑÐ&¨$¯,©,Ð*>Øä�qœ#˜s T§\¡\Ñ1°T×5FÑ5FÑFÓGÓHÐHr   Ú	raw_audioÚpaddingÚ
truncationÚ
max_lengthÚreturn_tensorsc                 ó  — |�;|| 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Œw|
j(                  d   dk7  sŒŠt        d|
j(                  d   › d�«      ‚ d}t-        d|i«      }| j.                  �Ð| j0                  �Ä|€Â|r]t3        d„ |D «       «      }t5        t        j6                  || j.                  z  «      «      }|dz
  | j.                  z  | j0                  z   }nc|r_t9        d„ |D «       «      }t5        t        j:                  || j.                  z  «      «      }|dz
  | j.                  z  | j0                  z   }d}n|}|€,| j=                  |||||¬«      }|r|j?                  d«      |d<   g }|j?                  d«      D ]1  }
| j*                  dk(  r|
d   }
|jA                  |
j                  «       Œ3 ||d<   |�|jC                  |«      }|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*):
                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 r$   z$Expected mono audio but example has éÿÿÿÿz	 channelsz&Expected stereo audio but example has r   c              3   ó:   K  — | ]  }|j                   d    –— Œ y­w©r   N©Úshape©Ú.0Úarrays     r   ú	<genexpr>z3EncodecFeatureExtractor.__call__.<locals>.<genexpr>­   ó   è ø€ Ò G°E §¡¨Q¥Ñ Gùó   ‚c              3   ó:   K  — | ]  }|j                   d    –— Œ y­wr2   r3   r5   s     r   r8   z3EncodecFeatureExtractor.__call__.<locals>.<genexpr>±   r9   r:   r*   )r*   r)   r(   Úreturn_attention_maskÚattention_maskr   ).N)"r   Ú
ValueErrorÚloggerÚwarningr   Ú__name__ÚboolÚ
isinstanceÚlistÚtupleÚnpÚndarrayÚasarrayÚfloat32ÚTr.   Úfloat64ÚastypeÚ	enumerateÚndimr4   r   r   r&   r"   Úminr    Úfloorr%   ÚceilÚpadÚpopÚappendÚconvert_to_tensors)r   r'   r(   r)   r*   r+   r   Ú
is_batchedÚaudioÚidxÚexampleÚpadded_inputsr   Únb_steps                 r   Ú__call__z EncodecFeatureExtractor.__call__T   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ò 	h‰LˆC�Ø�|‰|˜aÒÜ Ð#YÐZa×ZgÑZgÐYhÐ!iÓjÐjØ× Ñ  AÒ%¨'¯,©,¸!Ò*;Ü Ð#GÈÏÉÐVXÑHYÐGZÐZcÐ!dÓeÐeØ× Ñ  AÓ%¨'¯-©-¸Ñ*;¸qÓ*@Ü Ð#IÈ'Ï-É-ÐXZÑJ[ÐI\Ð\eÐ!fÓgÐgð	hð ˆÜ# ^°YÐ$?Ó@ˆØ×ÑÐ(¨T×->Ñ->Ð-JÈzÐOaÙÜ Ñ G¸YÔ GÓG�
ÜœbŸh™h z°D×4EÑ4EÑ'EÓFÓG�Ø%¨™k¨T×->Ñ->Ñ>À×ARÑARÑR‘
ÙÜ Ñ G¸YÔ GÓG�
ÜœbŸg™g j°4×3DÑ3DÑ&DÓEÓF�Ø%¨™k¨T×->Ñ->Ñ>À×ARÑARÑR�
Ø&‘à ,�ð Ð Ø ŸH™HØØ%Ø%ØØ&-ð %ó ˆMñ Ø0=×0AÑ0AÐBRÓ0S�˜nÑ-àˆØ$×(Ñ(¨Ó8ò 	+ˆGØ× Ñ  AÒ%Ø! )Ñ,�Ø×Ñ §	¡	Õ*ð	+ð
 )5ˆ�nÑ%ØÐ%Ø)×<Ñ<¸^ÓLˆMàÐùòq Ws   Ã6O>)r$   iÀ]  g        NN)NFNNN)rA   Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr    Úfloatr   r   Úpropertyr"   r&   r   rF   rG   r   rB   Ústrr	   r
   r   r\   Ú__classcell__)r   s   @r   r   r      s^  ø„ ñð. (¨Ð8Ðð Ø"Ø"Ø*.Ø#'ñàðð ðð ð	ð
 ! ™ðð ˜%‘õð ðA˜h s™mò Aó ðAð ðI˜h s™mò Ió ðIð @DØ%*Ø$(Ø;?Ø'+ñzà˜Ÿ™ T¨%¡[°$°r·z±zÑ2BÀDÈÈeÉÑDUÐUÑVðzð ˜%  c¨?Ð :Ñ;Ñ<ðzð ˜T‘Nð	zð
 ˜S‘Mðzð !  s¨J Ñ!7Ñ8ðzð   ‘}ðzð 
÷zr   r   )r_   Útypingr   r   r   ÚnumpyrF   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr	   r
   r   Ú
get_loggerrA   r?   r   Ú__all__r   r   r   ú<module>rl      sM   ðñ +ç (Ñ (ã å IÝ 4ß 9Ñ 9ð 
ˆ×	Ñ	˜HÓ	%€ôqÐ6ô qðh %Ð
%�r   