Ë
    T^(hô/  ã                   ó*  — 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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y)é    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 }|j                  | «      }ddd«       d   }	t        j                  |	t        j                  «      }
|
j                  d   dk(  rt        d«      ‚|
S # 1 sw Y   ŒQxY w# t        $ r}t        d«      |‚d}~ww xY w)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/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/pipelines/audio_utils.pyÚffmpeg_readr+   
   sú   € ð ˆ?€BØ	€BØ#ÐàØØØØ
ØØ
ØØØØØØð€Nð nÜ×Ñ˜n´J·O±OÌJÏOÉOÔ\ð 	AÐ`nØ*×6Ñ6°xÓ@ˆM÷	Að ˜aÑ €IÜ�M‰M˜)¤R§Z¡ZÓ0€EØ‡{�{�1�~˜ÒÜð[ó
ð 	
ð
 €L÷	Að 	Aûäò nÜÐaÓbÐhmÐmûðnús/   ˜4B: ÁB.ÁB: Â.B7Â3B: Â:	CÃCÃCÚ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	}	|xs d
}
n#|dk(  r	d}	|xs d}
n|dk(  rd}	|xs
 t        «       }
|€g n|}dd	d
d|d|d|ddddddg}|j	                  |«       t        t        | |z  «      «      |z  }t        ||«      }|D ]  }|–— Œ y­w)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_microphonerJ   1   s0  è ø€ ðD ˆ?€BØ	€BØ Ò'Ø‰Ø	 'Ò	)Ø‰äÐ-Ð.CÐ-DÐDdÐeÓfÐfä�_‰_Ó€Fà�ÒØˆØ$Ò1¨	‰Ø	�8Ò	Ø ˆØ$Ò2¨
‰Ø	�9Ò	ØˆØ$Ò>Ô(<Ó(>ˆà#9Ð#A™RÐG]Ðð 	ØØØØØØ
ØØ
ØØØØØØØØð#€Nð( ×ÑÐ0Ô1ä”E˜-¨.Ñ8Ó9Ó:¸^ÑK€IÜ˜n¨iÓ8€HØò ˆØ‹
ñùs   ‚CCÚ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                  j                  «       }t        j                  |¬«      }t        ||||fd¬«      D ]n  }t        j                  |d   |	¬«      |d<   |d   d
   |
z  |d   d   |
z  f|d<   | |d<   ||z  }t        j                  j                  «       |d|z  z   kD  rŒk|–— Œp y­w)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.   r0   r1   r   r2   r3   r4   é   r   é   )ÚsecondsT)ÚstrideÚstreamÚraw)ÚdtyperQ   r   é
   )rJ   r   Úint16r   r   rA   rB   Ú
isinstanceÚfloatÚdatetimeÚnowÚ	timedeltaÚchunk_bytes_iterr   )r   r,   rK   rL   r#   r-   r.   Úchunk_sÚ
microphonerT   rD   rG   Ústride_leftÚstride_rightÚ
audio_timeÚdeltarI   s                    r*   Úffmpeg_microphone_liverc   †   sÄ  è ø€ ð` Ð!Ø ‰à ˆä"ØØØ3Ø/Ø%;Ð%C™rÐI_ô€Jð  Ò'Ü—‘ˆØ‰Ø	 'Ò	)Ü—
‘
ˆØ‰äÐ-Ð.CÐ-DÐDdÐeÓfÐfàÐØ(¨1Ñ,ˆÜ”E˜-¨.Ñ8Ó9Ó:¸^ÑK€IÜ�/¤C¬ <Ô0Ø*¨OÐ<ˆä”e˜M¨O¸AÑ,>Ñ>Ó?Ó@À>ÑQ€KÜ”u˜]¨_¸QÑ-?Ñ?Ó@ÓAÀNÑR€LÜ×"Ñ"×&Ñ&Ó(€JÜ×Ñ wÔ/€EÜ  ¨YÀÈ\Ð?ZÐcgÔhò ˆä—m‘m D¨¡K°uÔ=ˆˆU‰à�‰N˜1Ñ Ñ/Ø�‰N˜1Ñ Ñ/ð
ˆˆX‰ð !.ˆˆ_ÑØ�eÑˆ
Ü×Ñ× Ñ Ó" Z°"°u±*Ñ%<Ò<àØ‹
ñùs   ‚FF	rG   rQ   rR   c              #   ót  K  — d}|\  }}||z   |k\  rt        d|› d|› d|› �«      ‚d}| D ]i  }||z  }|rt        |«      |k  r|df}|d| |ddœ–— Œ(t        |«      |k\  sŒ7||f}|d| |d	œ}	|rd
|	d<   |	–— |}|||z
  |z
  d }t        |«      |k\  rŒ3Œk t        |«      |kD  r||dfd	œ}	|rd
|	d<   |	–— yy­w)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.
    ó    z5Stride needs to be strictly smaller than chunk_len: (z, z) vs r   NT)rS   rQ   Úpartial)rS   rQ   Frf   )r   Úlen)
rH   rG   rQ   rR   Úaccr_   r`   Ú_stride_leftrS   rI   s
             r*   r\   r\   å   s-  è ø€ ð
 €CØ &Ñ€K�Ø�\Ñ! YÒ.ÜØCÀKÀ=ÐPRÐS_ÐR`Ð`eÐfoÐepÐqó
ð 	
ð €LØò DˆØˆs‰
ˆÙ”c˜#“h Ò*Ø" AÐ&ˆFØ˜j˜y˜/°VÈÑMÓMä�c“(˜iÓ'à&¨Ð5�Ø" : I˜¸&ÑA�ÙØ&+�D˜‘OØ’
Ø*�Ø˜) kÑ1°LÑ@ÐBÐC�ô �c“(˜iÔ'ðDô  ˆ3ƒx�+ÒØ |°QÐ&7Ñ8ˆÙØ#ˆD�‰OØ‹
ð	 ùs   ‚AB8Á!2B8Â$B8Úbuflenc              #   ó  K  — d}	 t        j                  | t         j                  |¬«      5 }	 |j                  j	                  |«      }|dk(  rn|–— Œ&	 ddd«       y# 1 sw Y   yxY w# t
        $ r}t        d«      |‚d}~ww xY w­w)zJ
    Internal function to create the generator of data through ffmpeg
    i   )r   Úbufsizere   NzHffmpeg was not found but is required to stream audio files from filename)r   r   r   r   Úreadr   r   )r$   rj   rl   r%   rS   r'   s         r*   rC   rC     s”   è ø€ ð €GðpÜ×Ñ˜n´Z·_±_ÈgÔVð 	ÐZhØØ$×+Ñ+×0Ñ0°Ó8�Ø˜#’:ØØ’	ð	 ð ÷		÷ 	ñ 	ûô ò pÜÐcÓdÐjoÐoûðpüsK   ‚B†&A* ¬(AÁA* ÁBÁA'Á#A* Á&BÁ'A* Á*	BÁ3A?Á?BÂBc                  óL  — g d¢} 	 t        j                  | dt         j                  d¬«      }|j                  j	                  «       D �cg c]	  }d|v sŒ|‘Œ }}|r*|d   j                  d«      d   }t        d	|› �«       d
|› �S 	 yc c}w # t        $ r t        d«       Y yw xY w)z3
    Retrieve the microphone name in Windows .
    )r   z-list_devicesÚtruer   r;   r   Ú Tzutf-8)ÚtextÚstderrÚencodingz(audio)r   ú"rO   zUsing microphone: zaudio=zOffmpeg was not found. Please install it or make sure it is in your system PATH.r7   )r   Úrunr   rr   Ú
splitlinesÚsplitÚprintr   )ÚcommandÚffmpeg_devicesÚlineÚmicrophone_linesÚmicrophone_names        r*   r?   r?     sÀ   € ò K€Gð	aÜ#Ÿ™¨°dÄ:Ç?Á?Ð]dÔeˆØ-;×-BÑ-B×-MÑ-MÓ-OÖe TÐS\Ð`dÒSdšDÐeÐÐeáØ.¨qÑ1×7Ñ7¸Ó<¸QÑ?ˆOÜÐ& Ð&7Ð8Ô9Ø˜OÐ,Ð-Ð-ð ð ùò føô ò aÜÐ_Õ`àðaús*   †AB Á		BÁBÁ-B ÂB ÂB#Â"B#)r   NN)NNr   NN)F)rY   r=   r   Útypingr   r   r   Únumpyr   ÚbytesrA   Úarrayr+   rX   ÚstrÚlistrJ   rc   Úboolr\   rC   r?   © re   r*   ú<module>r†      sI  ðã Û Û ß )Ñ )ã ð$˜%ð $°ð $¸¿¹ó $ðT ")Ø)-Ø26ñRØðRàðRð ðRð " #™ð	Rð
 % T¨#¡YÑ/óRðp %)ØCGØ!(Ø)-Ø26ñ\Øð\àð\ð ˜S‘Mð\ð ˜e E¨%°¨,Ñ$7¸Ð$>Ñ?Ñ@ð	\ð
 ð\ð " #™ð\ð % T¨#¡YÑ/ó\ñ~ ¨#ð  °u¸SÀ#¸X±ð  ÐPTó  ðFp¨3ó pó re   