§
    \zniÌ   ã                   óþ   — d dl Z d dlZd dlZd dlmZmZmZ d dlZde	de
dej        fd„Z	 dde
ded	efd
„Z	 	 	 dde
dedee
         deeeeef         ef                  d	ef
d„Zdde
dee
e
f         defd„Zde
fd„ZdS )é    N)ÚOptionalÚTupleÚUnionÚbpayloadÚsampling_rateÚreturnc                 ó¸  — |› }d}d}dddd|d|d|d	d
ddg}	 t          j        |t           j        t           j        ¬¦  «        5 }|                     | ¦  «        }ddd¦  «         n# 1 swxY w Y   n"# t          $ r}t          d¦  «        |‚d}~ww xY w|d         }	t          j        |	t          j        ¦  «        }
|
j	        d         dk    rt          d¦  «        ‚|
S )z?
    Helper function to read an audio file through ffmpeg.
    Ú1Úf32leÚffmpegú-izpipe:0ú-acú-arú-fú-hide_bannerú	-loglevelÚquietúpipe:1)ÚstdinÚstdoutNzFffmpeg was not found but is required to load audio files from filenamer   a  Soundfile is either not in the correct format or is malformed. Ensure that the soundfile has a valid audio file extension (e.g. wav, flac or mp3) and is not corrupted. If reading from a remote URL, ensure that the URL is the full address to **download** the audio file.)
Ú
subprocessÚPopenÚPIPEÚcommunicateÚFileNotFoundErrorÚ
ValueErrorÚnpÚ
frombufferÚfloat32Úshape)r   r   ÚarÚacÚformat_for_conversionÚffmpeg_commandÚffmpeg_processÚoutput_streamÚerrorÚ	out_bytesÚaudios              ú‚/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/pipelines/audio_utils.pyÚffmpeg_readr+   
   s`  € ð Ð	€BØ	€BØ#ÐàØØØØ
ØØ
ØØØØØØð€Nð nÝÔ˜nµJ´OÍJÌOÐ\Ñ\Ô\ð 	AÐ`nØ*×6Ò6°xÑ@Ô@ˆMð	Að 	Að 	Añ 	Aô 	Að 	Að 	Að 	Að 	Að 	Að 	Aøøøð 	Að 	Að 	Að 	Aøøåð nð nð nÝÐaÑbÔbÐhmÐmøøøøðnøøøà˜aÔ €IÝŒM˜)¥R¤ZÑ0Ô0€EØ„{�1„~˜ÒÐÝð[ñ
ô 
ð 	
ð
 €Ls;   ˜+A1 ÁA%ÁA1 Á%A)Á)A1 Á,A)Á-A1 Á1
BÁ;BÂBr   Úchunk_length_sr#   c              #   ó`  K  — | › }d}|dk    rd}n|dk    rd}nt          d|› d�¦  «        ‚t          j        ¦   «         }|dk    rd	}d
}n|dk    rd}d}n
|dk    rd}d
}dd|d|d|d|d|ddddddg}	t          t	          | |z  ¦  «        ¦  «        |z  }
t          |	|
¦  «        }|D ]}|V — ŒdS )z6
    Helper function ro read raw microphone data.
    r
   Ús16leé   r   é   úUnhandled format `ú `. Please use `s16le` or `f32le`ÚLinuxÚalsaÚdefaultÚDarwinÚavfoundationz:0ÚWindowsÚdshowr   r   r   r   r   z-fflagsÚnobufferr   r   r   r   N)r   ÚplatformÚsystemÚintÚroundÚ_ffmpeg_stream)r   r,   r#   r!   r"   Úsize_of_sampler<   Úformat_Úinput_r$   Ú	chunk_lenÚiteratorÚitems                r*   Úffmpeg_microphonerF   1   s4  è è € ð Ð	€BØ	€BØ Ò'Ð'ØˆˆØ	 'Ò	)Ð	)ØˆˆåÐeÐ.CÐeÐeÐeÑfÔfÐfåŒ_ÑÔ€FØ�ÒÐØˆØˆˆØ	�8Ò	Ð	Ø ˆØˆˆØ	�9Ò	Ð	ØˆØˆð 	ØØØØØØ
ØØ
ØØØØØØØØð#€Nõ& •E˜-¨.Ñ8Ñ9Ô9Ñ:Ô:¸^ÑK€IÝ˜n¨iÑ8Ô8€HØð ð ˆØˆ
ˆ
ˆ
ˆ
ðð ó    Ústream_chunk_sÚstride_length_sc              #   ót  K  — |�|}n|}t          | ||¬¦  «        }|dk    rt          j        }d}n(|dk    rt          j        }d}nt	          d|› d�¦  «        ‚|€|d	z  }t          t          | |z  ¦  «        ¦  «        |z  }	t          |t
          t          f¦  «        r||g}t          t          | |d
         z  ¦  «        ¦  «        |z  }
t          t          | |d         z  ¦  «        ¦  «        |z  }t          j	         
                    ¦   «         }t          j        |¬¦  «        }t          ||	|
|fd¬¦  «        D ]}}t          j        |d         |¬¦  «        |d<   |d         d
         |z  |d         d         |z  f|d<   | |d<   ||z  }t          j	         
                    ¦   «         |d|z  z   k    rŒy|V — Œ~dS )a  
    Helper function to read audio from the microphone file through ffmpeg. This will output `partial` overlapping
    chunks starting from `stream_chunk_s` (if it is defined) until `chunk_length_s` is reached. It will make use of
    striding to avoid errors on the "sides" of the various chunks.

    Arguments:
        sampling_rate (`int`):
            The sampling_rate to use when reading the data from the microphone. Try using the model's sampling_rate to
            avoid resampling later.
        chunk_length_s (`float` or `int`):
            The length of the maximum chunk of audio to be sent returned. This includes the eventual striding.
        stream_chunk_s (`float` or `int`)
            The length of the minimal temporary audio to be returned.
        stride_length_s (`float` or `int` or `(float, float)`, *optional*, defaults to `None`)
            The length of the striding to be used. Stride is used to provide context to a model on the (left, right) of
            an audio sample but without using that part to actually make the prediction. Setting this does not change
            the length of the chunk.
        format_for_conversion (`str`, defalts to `f32le`)
            The name of the format of the audio samples to be returned by ffmpeg. The standard is `f32le`, `s16le`
            could also be used.
    Return:
        A generator yielding dictionaries of the following form

        `{"sampling_rate": int, "raw": np.array(), "partial" bool}` With optionnally a `"stride" (int, int)` key if
        `stride_length_s` is defined.

        `stride` and `raw` are all expressed in `samples`, and `partial` is a boolean saying if the current yield item
        is a whole chunk, or a partial temporary result to be later replaced by another larger chunk.


    N)r#   r.   r/   r   r0   r1   r2   é   r   é   )ÚsecondsT)ÚstrideÚstreamÚraw)ÚdtyperN   r   é
   )rF   r   Úint16r   r   r=   r>   Ú
isinstanceÚfloatÚdatetimeÚnowÚ	timedeltaÚchunk_bytes_iterr   )r   r,   rH   rI   r#   Úchunk_sÚ
microphonerQ   r@   rC   Ústride_leftÚstride_rightÚ
audio_timeÚdeltarE   s                  r*   Úffmpeg_microphone_liver`   f   sû  è è € ðL Ð!Ø ˆˆà ˆå" =°'ÐQfÐgÑgÔg€JØ Ò'Ð'Ý”ˆØˆˆØ	 'Ò	)Ð	)Ý”
ˆØˆˆåÐeÐ.CÐeÐeÐeÑfÔfÐfàÐØ(¨1Ñ,ˆÝ•E˜-¨.Ñ8Ñ9Ô9Ñ:Ô:¸^ÑK€IÝ�/¥C­ <Ñ0Ô0ð =Ø*¨OÐ<ˆå•e˜M¨O¸AÔ,>Ñ>Ñ?Ô?Ñ@Ô@À>ÑQ€KÝ•u˜]¨_¸QÔ-?Ñ?Ñ@Ô@ÑAÔAÀNÑR€LÝÔ"×&Ò&Ñ(Ô(€JÝÔ wÐ/Ñ/Ô/€EÝ  ¨YÀÈ\Ð?ZÐcgÐhÑhÔhð ð ˆå”m D¨¤K°uÐ=Ñ=Ô=ˆˆU‰à�ŒN˜1Ô Ñ/Ø�ŒN˜1Ô Ñ/ð
ˆˆX‰ð !.ˆˆ_ÑØ�eÑˆ
ÝÔ× Ò Ñ"Ô" Z°"°u±*Ñ%<Ò<Ð<àØˆ
ˆ
ˆ
ˆ
ðð rG   FrC   rN   rO   c              #   ó¼  K  — d}|\  }}||z   |k    rt          d|› d|› d|› �¦  «        ‚d}| D ]…}||z  }|r(t          |¦  «        |k     r|df}|d|…         |ddœV — Œ1t          |¦  «        |k    rA||f}|d|…         |d	œ}	|rd
|	d<   |	V — |}|||z
  |z
  d…         }t          |¦  «        |k    °AŒ†t          |¦  «        |k    r||dfd	œ}	|rd
|	d<   |	V — dS dS )zê
    Reads raw bytes from an iterator and does chunks of length `chunk_len`. Optionally adds `stride` to each chunks to
    get overlaps. `stream` is used to return partial results even if a full `chunk_len` is not yet available.
    rG   z5Stride needs to be strictly smaller than chunk_len: (z, z) vs r   NT)rP   rN   Úpartial)rP   rN   Frb   )r   Úlen)
rD   rC   rN   rO   Úaccr\   r]   Ú_stride_leftrP   rE   s
             r*   rY   rY   ´   sƒ  è è € ð
 €CØ &Ñ€K�Ø�\Ñ! YÒ.Ð.ÝØqÀKÐqÐqÐS_ÐqÐqÐfoÐqÐqñ
ô 
ð 	
ð €LØð Dð DˆØˆs‰
ˆØð 	D•c˜#‘h”h Ò*Ð*Ø" AÐ&ˆFØ˜j˜y˜jœ/°VÈÐMÐMÐMÐMÐMÐMå�c‘(”(˜iÒ'Ð'à&¨Ð5�Ø" : I :œ¸&ÐAÐA�Øð ,Ø&+�D˜‘OØ�
�
�
Ø*�Ø˜) kÑ1°LÑ@ÐBÐBÔC�õ �c‘(”(˜iÒ'Ð'øõ ˆ3�x„x�+ÒÐØ |°QÐ&7Ð8Ð8ˆØð 	$Ø#ˆD�‰OØˆ
ˆ
ˆ
ˆ
ˆ
ð	 ÐrG   Úbuflenc              #   ó  K  — d}	 t          j        | t           j        |¬¦  «        5 }	 |j                             |¦  «        }|dk    rn|V — Œ&	 ddd¦  «         dS # 1 swxY w Y   dS # t
          $ r}t          d¦  «        |‚d}~ww xY w)zJ
    Internal function to create the generator of data through ffmpeg
    i   )r   ÚbufsizeTrG   NzHffmpeg was not found but is required to stream audio files from filename)r   r   r   r   Úreadr   r   )r$   rf   rh   r%   rP   r'   s         r*   r?   r?   ×   s   è è € ð €GðpÝÔ˜nµZ´_ÈgÐVÑVÔVð 	ÐZhðØ$Ô+×0Ò0°Ñ8Ô8�Ø˜#’:�:ØØ�	�	�	ð	ð ð		ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	øõ ð pð pð pÝÐcÑdÔdÐjoÐoøøøøðpøøøs:   †!A* §(AÁA* ÁA!Á!A* Á$A!Á%A* Á*
B	Á4BÂB	)r   )NNr   )F)rV   r;   r   Útypingr   r   r   Únumpyr   Úbytesr=   Úarrayr+   rU   ÚstrrF   r`   ÚboolrY   r?   © rG   r*   ú<module>rq      s�  ðà €€€Ø €€€Ø Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )Ð )Ð )à Ð Ð Ð ð$˜%ð $°ð $¸¼ð $ð $ð $ð $ðT ")ð2ð 2Øð2àð2ð ð2ð 2ð 2ð 2ðp %)ØCGØ!(ðKð KØðKàðKð ˜S”MðKð ˜e E¨%°¨,Ô$7¸Ð$>Ô?Ô@ð	Kð
 ðKð Kð Kð Kð\ ð  ¨#ð  °u¸SÀ#¸X´ð  ÐPTð  ð  ð  ð  ðFp¨3ð pð pð pð pð pð prG   