§
    Þ˜ºhí/  ã                   ó`  — d dl Z d dlZd dlZd dl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d
ee         deee                  f
d„Z	 	 	 	 	 dde	dedee	         deeeeef         ef                  d	ed
ee         deee                  fd„Zdde	dee	e	f         defd„Zde	fd„Zd„ ZdS )é    N)ÚOptionalÚ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              új/var/www/html/services/rag-service/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"   Úffmpeg_input_deviceÚffmpeg_additional_argsc              #   óº  K  — | › }d}|dk    rd}n|dk    rd}nt          d|› d�¦  «        ‚t          j        ¦   «         }|dk    rd	}	|pd
}
n%|dk    rd}	|pd}
n|dk    rd}	|pt          ¦   «         }
|€g n|}dd|	d|
d|d|d|ddddddg}|                     |¦  «         t          t          | |z  ¦  «        ¦  «        |z  }t          ||¦  «        }|D ]}|V — ŒdS )a�  
    Helper function to read audio from a microphone using ffmpeg. The default input device will be used unless another
    input device is specified using the `ffmpeg_input_device` argument. Uses 'alsa' on Linux, 'avfoundation' on MacOS and
    'dshow' on Windows.

    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.
        format_for_conversion (`str`, defaults 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.
        ffmpeg_input_device (`str`, *optional*):
            The identifier of the input device to be used by ffmpeg (i.e. ffmpeg's '-i' argument). If unset,
            the default input device will be used. See `https://www.ffmpeg.org/ffmpeg-devices.html#Input-Devices`
            for how to specify and list input devices.
        ffmpeg_additional_args (`list[str]`, *optional*):
            Additional arguments to pass to ffmpeg, can include arguments like -nostdin for running as a background
            process. For example, to pass -nostdin to the ffmpeg process, pass in ["-nostdin"]. If passing in flags
            with multiple arguments, use the following convention (eg ["flag", "arg1", "arg2]).

    Returns:
        A generator yielding audio chunks of `chunk_length_s` seconds as `bytes` objects of length
        `int(round(sampling_rate * chunk_length_s)) * size_of_sample`.
    r	   Ús16leé   r
   é   úUnhandled format `ú `. Please use `s16le` or `f32le`ÚLinuxÚalsaÚdefaultÚDarwinÚavfoundationz:defaultÚWindowsÚdshowNr   r   r   r   r   z-fflagsÚnobufferr   r   r   r   )r   ÚplatformÚsystemÚ_get_microphone_nameÚextendÚintÚroundÚ_ffmpeg_stream)r   r+   r"   r,   r-   r    r!   Úsize_of_sampler=   Úformat_Úinput_r#   Ú	chunk_lenÚiteratorÚitems                  r)   Úffmpeg_microphonerI   1   sp  è è € ðD Ð	€BØ	€BØ Ò'Ð'ØˆˆØ	 'Ò	)Ð	)ØˆˆåÐeÐ.CÐeÐeÐeÑfÔfÐfåŒ_ÑÔ€Fà�ÒÐØˆØ$Ð1¨	ˆˆØ	�8Ò	Ð	Ø ˆØ$Ð2¨
ˆˆØ	�9Ò	Ð	ØˆØ$Ð>Õ(<Ñ(>Ô(>ˆà#9Ð#A˜R˜RÐG]Ðð 	ØØØØØØ
ØØ
ØØØØØØØØð#€Nð( ×ÒÐ0Ñ1Ô1Ð1å•E˜-¨.Ñ8Ñ9Ô9Ñ:Ô:¸^ÑK€IÝ˜n¨iÑ8Ô8€HØð ð ˆØˆ
ˆ
ˆ
ˆ
ðð ó    Ústream_chunk_sÚstride_length_sc              #   ó€  K  — |�|}n|}t          | ||||€g n|¬¦  «        }|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 a microphone using 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. The default input device will be used unless another input device is
    specified using the `ffmpeg_input_device` argument. Uses 'alsa' on Linux, 'avfoundation' on MacOS and 'dshow' on Windows.

    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*):
            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`, *optional*, defaults 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.
        ffmpeg_input_device (`str`, *optional*):
            The identifier of the input device to be used by ffmpeg (i.e. ffmpeg's '-i' argument). If unset,
            the default input device will be used. See `https://www.ffmpeg.org/ffmpeg-devices.html#Input-Devices`
            for how to specify and list input devices.
        ffmpeg_additional_args (`list[str]`, *optional*):
            Additional arguments to pass to ffmpeg, can include arguments like -nostdin for running as a background
            process. For example, to pass -nostdin to the ffmpeg process, pass in ["-nostdin"]. If passing in flags
            with multiple arguments, use the following convention (eg ["flag", "arg1", "arg2]).

    Return:
        A generator yielding dictionaries of the following form

        `{"sampling_rate": int, "raw": np.array(), "partial" bool}` With optionally 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   r
   r1   r2   r3   é   r   é   )ÚsecondsT)ÚstrideÚstreamÚraw)ÚdtyperQ   r   é
   )rI   r   Úint16r   r   r@   rA   Ú
isinstanceÚfloatÚdatetimeÚnowÚ	timedeltaÚchunk_bytes_iterr   )r   r+   rK   rL   r"   r,   r-   Úchunk_sÚ
microphonerT   rC   rF   Ústride_leftÚstride_rightÚ
audio_timeÚdeltarH   s                    r)   Úffmpeg_microphone_liverc   †   s  è è € ð` Ð!Ø ˆˆà ˆå"ØØØ3Ø/Ø%;Ð%C˜r˜rÐI_ðñ ô €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±*Ñ%<Ò<Ð<àØˆ
ˆ
ˆ
ˆ
ðð rJ   FrF   rQ   rR   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.
    rJ   z5Stride needs to be strictly smaller than chunk_len: (z, z) vs r   NT)rS   rQ   Úpartial)rS   rQ   Fre   )r   Úlen)
rG   rF   rQ   rR   Úaccr_   r`   Ú_stride_leftrS   rH   s
             r)   r\   r\   å   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Øˆ
ˆ
ˆ
ˆ
ˆ
ð	 ÐrJ   Ú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   ÚbufsizeTrJ   NzHffmpeg was not found but is required to stream audio files from filename)r   r   r   r   Úreadr   r   )r#   ri   rk   r$   rS   r&   s         r)   rB   rB     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	c                  óN  — g d¢} 	 t          j        | dt           j        d¬¦  «        }d„ |j                             ¦   «         D ¦   «         }|r8|d                              d¦  «        d         }t          d	|› �¦  «         d
|› �S n# t          $ r t          d¦  «         Y nw xY wdS )z3
    Retrieve the microphone name in Windows .
    )r   z-list_devicesÚtruer   r:   r   Ú Tzutf-8)ÚtextÚstderrÚencodingc                 ó   — g | ]}d |v ¯|‘Œ	S )z(audio)© )Ú.0Úlines     r)   ú
<listcomp>z(_get_microphone_name.<locals>.<listcomp>   s$   € ÐeÐeÐe TÐS\Ð`dÐSdÐSd˜DÐSdÐSdÐSdrJ   r   ú"rO   zUsing microphone: zaudio=zOffmpeg was not found. Please install it or make sure it is in your system PATH.r6   )r   Úrunr   rq   Ú
splitlinesÚsplitÚprintr   )ÚcommandÚffmpeg_devicesÚmicrophone_linesÚmicrophone_names       r)   r>   r>     sà   € ð KÐJÐJ€Gð	aÝ#œ¨°dÅ:Ä?Ð]dÐeÑeÔeˆØeÐe¨^Ô-B×-MÒ-MÑ-OÔ-OÐeÑeÔeÐàð 	.Ø.¨qÔ1×7Ò7¸Ñ<Ô<¸QÔ?ˆOÝÐ8 Ð8Ð8Ñ9Ô9Ð9Ø-˜OÐ-Ð-Ð-ð	.øõ ð að að aÝÐ_Ñ`Ô`Ð`Ð`Ð`ðaøøøð ˆ9s   †A>B ÂB"Â!B")r
   NN)NNr
   NN)F)rY   r<   r   Útypingr   r   Únumpyr   Úbytesr@   Úarrayr*   rX   ÚstrÚlistrI   Útuplerc   Úboolr\   rB   r>   rt   rJ   r)   ú<module>r‰      sð  ðà €€€Ø €€€Ø Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð ð$˜%ð $°ð $¸¼ð $ð $ð $ð $ðT ")Ø)-Ø26ðRð RØðRàðRð ðRð " #œð	Rð
 % T¨#¤YÔ/ðRð Rð Rð Rðp %)ØCGØ!(Ø)-Ø26ð\ð \Øð\àð\ð ˜S”Mð\ð ˜e E¨%°¨,Ô$7¸Ð$>Ô?Ô@ð	\ð
 ð\ð " #œð\ð % T¨#¤YÔ/ð\ð \ð \ð \ð~ ð  ¨#ð  °u¸SÀ#¸X´ð  ÐPTð  ð  ð  ð  ðFp¨3ð pð pð pð pð ð ð ð ð rJ   