Ë
    »dæjû  ã                   óŒ   — d Z ddlZddlZddlmZ ddlZddlmZ ddl	m
Z
 ej                   G d„ d«      «       Z G d„ d	e«      Zy)
zMediaPipe audio data.é    N)ÚOptional)Úaudio_data_c)Údoc_controlsc                   ó4   — e Zd ZU dZdZeed<   dZee	   ed<   y)ÚAudioDataFormatzŒAudio format metadata.

  Attributes:
    num_channels: the number of channels of the audio data.
    sample_rate: the audio sample rate.
  é   Únum_channelsNÚsample_rate)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   ÚintÚ__annotations__r
   r   Úfloat© ó    úz/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/mediapipe/tasks/python/components/containers/audio_data.pyr   r      s!   … ñð €,�ÓØ!%€+ˆx˜‰Ô%r   r   c            	       ó:  — e Zd ZdZ e«       fdededdfd„Zd„ Z	 	 ddej                  d	ed
eddfd„Z
e	 ddej                  dee   dd fd„«       Zedefd„«       Zedefd„«       Zedej                  fd„«       Zej(                  dej,                  fd„«       Zy)Ú	AudioDataz!MediaPipe Tasks' audio container.Úbuffer_lengthÚaudio_formatÚreturnNc                 ó’   — || _         t        j                  || j                   j                  gt        j                  ¬«      | _        y)z—Initializes the `AudioData` object.

    Args:
      buffer_length: the length of the audio buffer.
      audio_format: the audio format metadata.
    )ÚdtypeN)Ú_audio_formatÚnpÚzerosr	   Úfloat32Ú_buffer)Úselfr   r   s      r   Ú__init__zAudioData.__init__)   s6   € ð &€DÔÜ—8‘8˜]¨D×,>Ñ,>×,KÑ,KÐLÜ"$§*¡*ô.€D…Lr   c                 ó:   — | j                   j                  d«       y)z2Clears the internal buffer and fill it with zeros.r   N)r    Úfill©r!   s    r   ÚclearzAudioData.clear8   s   € à‡L�L×Ñ�aÕr   ÚsrcÚoffsetÚsizec           
      ó<  — t        |j                  «      dk(  r<| j                  j                  dk7  rlt	        d| j                  j                  › d�«      ‚|j                  d   | j                  j                  k7  r#t	        d| j                  j                  › d�«      ‚|dk  rt        |«      }||z   t        |«      kD  rt	        d|› d|› d	t        |«      › �«      ‚t        |«      t        | j
                  «      k\  rL||z   t        | j
                  «      z
  }t        | j
                  «      }||||z    j                  «       | _        y|}t        j                  | j
                  | d¬
«      | _        ||||z    j                  «       | j
                  | d…dd…f<   y)aÍ  Loads the audio data from a NumPy array.

    Args:
      src: A NumPy source array contains the input audio.
      offset: An optional offset for loading a slice of the `src` array to the
        buffer.
      size: An optional size parameter denoting the number of samples to load
        from the `src` array.

    Raises:
      ValueError: If the input array has an incorrect shape or if
        `offset` + `size` exceeds the length of the `src` array.
    r   z<Input audio is mono, but the audio data is expected to have z
 channels.z;Input audio contains an invalid number of channels. Expect ú.r   zIndex out of range. offset z + size z should be <= src's length: )ÚaxisN)	ÚlenÚshaper   r	   Ú
ValueErrorr    Úcopyr   Úroll)r!   r'   r(   r)   Ú
new_offsetÚnew_sizeÚshifts          r   Úload_from_arrayzAudioData.load_from_array<   s”  € ô" ˆ3�9‰9ƒ~˜ÒØ	×	Ñ	×	(Ñ	(¨AÒ	-Üð $Ø$(×$6Ñ$6×$CÑ$CÐ#DÀJðPó Qð 	Qà	�‰�1‰˜×+Ñ+×8Ñ8Ò	8Üð !Ø!%×!3Ñ!3×!@Ñ!@Ð AÀðDó Eð Eð ˆa‚xÜ�‹X€dà��}”s˜3“xÒÜØ'¨ x¨x¸°vð >Ü˜s›8˜*ð&ó'ð 'ô ˆ3ƒx”3�t—|‘|Ó$Ò$ð ˜D‘=¤3 t§|¡|Ó#4Ñ4€jÜ�T—\‘\Ó"€hØ˜ J°Ñ$9Ð:×?Ñ?ÓA€d…lð €eÜ—W‘W˜TŸ\™\¨E¨6¸Ô:€d„lØ!$ V¨F°T©MÐ!:×!?Ñ!?Ó!A€d‡l�l�E�6‘7šA�:Òr   r
   c                 óø   — |j                  t        j                  «      } | |j                  d   t	        t        |j                  «      dk(  rdn|j                  d   |¬«      ¬«      }|j                  |«       |S )a  Creates an `AudioData` object from a NumPy array.

    Args:
      src: A NumPy source array contains the input audio.
      sample_rate: the optional audio sample rate.

    Returns:
      An `AudioData` object that contains a copy of the NumPy source array as
      the data.
    r   r   )r	   r
   )r   r   )Úastyper   r   r.   r   r-   r5   )Úclsr'   r
   Úobjs       r   Úcreate_from_arrayzAudioData.create_from_arrayj   sg   € ð �*‰*”R—Z‘ZÓ
 €CÙ
Ø—i‘i ‘lÜ$Ü! #§)¡)›n°Ò1™°s·y±yÀ±|Ø#ô%ô&€Cð
 ×Ñ˜ÔØ€Jr   c                 ó   — | j                   S )z#Gets the audio format of the audio.)r   r%   s    r   r   zAudioData.audio_format�   s   € ð ×ÑÐr   c                 ó4   — | j                   j                  d   S )z#Gets the sample count of the audio.r   )r    r.   r%   s    r   r   zAudioData.buffer_length†   s   € ð �<‰<×Ñ˜aÑ Ð r   c                 ó   — | j                   S )zGets the internal buffer.)r    r%   s    r   ÚbufferzAudioData.buffer‹   s   € ð �<‰<Ðr   c           	      ó4  — t        j                  | j                  j                  | j                  j                  | j
                  j                  j                  t        j                  t        j                  «      «      | j
                  j                  ¬«      S )z2Converts the object to a ctypes audio data object.)r	   r
   Ú
audio_dataÚaudio_data_size)r   Ú
AudioDataCr   r	   r
   r    ÚctypesÚdata_asÚPOINTERÚc_floatr)   r%   s    r   Ú	to_ctypeszAudioData.to_ctypes�   sg   € ô ×"Ñ"Ø×&Ñ&×3Ñ3Ø×%Ñ%×1Ñ1Ø—<‘<×&Ñ&×.Ñ.¬v¯~©~¼f¿n¹nÓ/MÓNØŸ™×)Ñ)ô	ð r   )r   éÿÿÿÿ)N)r   r   r   r   r   r   r"   r&   r   Úndarrayr5   Úclassmethodr   r   r:   Úpropertyr   r   r>   r   Údo_not_generate_docsr   rB   rG   r   r   r   r   r   &   s#  „ Ù)ñ
 '6Ó&7ñ.àð.ð $ð.ð ó	.òð %&Ø"$ñ,BØŸ:™:ð,Bà!ð,Bð  ð,Bð *.ó,Bð\ ð 8<ñØŸZ™Zðà%-¨e¡_ðà@Kòó ðð, ð˜Oò ó ðð ð!˜Sò !ó ð!ð ð�b—j‘jò ó ðð ×$Ñ$ð˜×0Ñ0ò ó %ñr   r   )r   rC   ÚdataclassesÚtypingr   Únumpyr   Ú,mediapipe.tasks.python.components.containersr   Ú1mediapipe.tasks.python.core.optional_dependenciesr   Ú	dataclassr   Úobjectr   r   r   r   ú<module>rT      sI   ðñ ã Û Ý ã å EÝ Jð ×Ñ÷&ð &ó ð&ôr�õ rr   