
    1;ji                         d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 dZ
dZ G d d	e          Z G d
 de          Zd Z G d de	          ZdS )zBUses standard-library modules to read AIFF, AIFF-C, and WAV files.    N   )DecodeError)	AudioFile   )r   r         c                       e Zd ZdZdS )UnsupportedErrorz%File is not an AIFF, WAV, or Au file.N__name__
__module____qualname____doc__     K/root/voice-cloning/.venv/lib/python3.11/site-packages/audioread/rawread.pyr
   r
       s        ////r   r
   c                       e Zd ZdZdS )BitWidthErrorz'The file uses an unsupported bit width.Nr   r   r   r   r   r   $   s        1111r   r   c                 0   t          |           dz  dk    sJ g }t          dt          |           d          D ]I}| ||dz            }t          j        dgt          j        d|          R  }|                    |           Jd                    |          S )zSwaps the endianness of the bytestring s, which must be an array
    of shorts (16-bit signed integers). This is probably less efficient
    than it should be.
    r   r   z<hz>hr   )lenrangestructpackunpackappendjoin)spartsichunknewchunks        r   byteswapr"   (   s    
 q66A:????E1c!ffa    !AE'
;tAfmD%&@&@AAAX88E??r   c                       e Zd ZdZd Zd Zd Zed             Zed             Z	ed             Z
dd	Zd
 Zd Zd ZdS )RawAudioFilez|An AIFF, WAV, or Au file that can be read by the Python standard
    library modules ``wave``, ``aifc``, and ``sunau``.
    c                    t          |d          | _        	 t          j         | j                  | _        d| _        |                                  d S # t          j        $ r | j                            d           Y nw xY w	 t          j         | j                  | _        d| _        |                                  d S # t          j        $ r | j                            d           Y nw xY w	 t          j         | j                  | _        d| _        |                                  d S # t          j        $ r | j                            d           Y nw xY w| j        
                                 t                      )NrbTr   F)open_fhaifc_file_needs_byteswap_checkErrorseekwavesunaucloser
   )selffilenames     r   __init__zRawAudioFile.__init__:   sx   $''	48,,DJ
 $(D KKMMMF z 	 	 	HMM!		48,,DJ
 $)D KKMMMF z 	 	 	HMM!D		DH--DJ
 $(D KKMMMF { 	 	 	HMM!D	 	   s5   A )A>=A>B= =)C)(C)-D( ()EEc                     | j                                         t          vr"|                                  t	                      dS )zeCheck that the files' parameters allow us to decode it and
        raise an error otherwise.
        N)r*   getsampwidthSUPPORTED_WIDTHSr1   r   r2   s    r   r,   zRawAudioFile._check_   s=     :""$$,<<<JJLLL//! =<r   c                 j    | j                                          | j                                         dS )zClose the underlying file.N)r*   r1   r(   r8   s    r   r1   zRawAudioFile.closeg   s.    
r   c                 4    | j                                         S )zNumber of audio channels.)r*   getnchannelsr8   s    r   channelszRawAudioFile.channelsl        z&&(((r   c                 4    | j                                         S )zSample rate in Hz.)r*   getframerater8   s    r   
sampleratezRawAudioFile.samplerateq   r=   r   c                 ^    t          | j                                                  | j        z  S )z)Length of the audio in seconds (a float).)floatr*   
getnframesr@   r8   s    r   durationzRawAudioFile.durationv   s'     TZ**,,--??r      c              #     K   | j                                         }	 | j                             |          }|sdS t          j        ||t
                    }| j        r,| j                                         dk    rt          |          }|V  q)z/Generates blocks of PCM data found in the file.TsowtN)	r*   r6   
readframesaudiooplin2linTARGET_WIDTHr+   getcomptyper"   )r2   block_samples	old_widthdatas       r   	read_datazRawAudioFile.read_data{   s      J++--	
	:((77D  ?4LAAD# &
(>(>(@(@F(J(J~~JJJ
	r   c                     | S Nr   r8   s    r   	__enter__zRawAudioFile.__enter__   s    r   c                 .    |                                   dS )NF)r1   )r2   exc_typeexc_valexc_tbs       r   __exit__zRawAudioFile.__exit__   s    

ur   c                 *    |                                  S rR   )rP   r8   s    r   __iter__zRawAudioFile.__iter__   s    ~~r   N)rE   )r   r   r   r   r4   r,   r1   propertyr<   r@   rD   rP   rS   rX   rZ   r   r   r   r$   r$   6   s         #! #! #!J" " "  
 ) ) X) ) ) X) @ @ X@   "    
         r   r$   )r   r)   rI   r   r0   r/   
exceptionsr   baser   rK   r7   r
   r   r"   r$   r   r   r   <module>r^      s   I H      # # # # # #          0 0 0 0 0{ 0 0 02 2 2 2 2K 2 2 2  _  _  _  _  _ 9 _  _  _  _  _ r   