Ë
    T^(h¢™  ã                   ó  — d dl Z d dlmZ d dlmZmZmZmZ d dlZ	d dl
Z
ddlmZ ddlmZmZmZ ddlmZ dd	lmZ erd d
lmZ ddlmZ ddlmZ  ej6                  e«      Z e«       r
d dlZddlm Z  d„ Z!dd„Z"d„ Z#d„ Z$ G d„ de«      Z%d„ Z&y)é    N)Údefaultdict)ÚTYPE_CHECKINGÚDictÚOptionalÚUnioné   )ÚPreTrainedTokenizer)Úis_torch_availableÚis_torchaudio_availableÚloggingé   )Úffmpeg_read)ÚChunkPipeline)ÚBeamSearchDecoderCTC)ÚSequenceFeatureExtractor)ÚPreTrainedModel)Ú(MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMESc                 óâ   — g }| D ]g  \  }}}t        t        ||z  «      «      }t        t        ||z  |z  «      «      }t        t        ||z  |z  «      «      }|||f}|j                  |«       Œi |S )zŽ
    Rescales the stride values from audio space to tokens/logits space.

    (160_000, 16_000, 16_000) -> (2000, 200, 200) for instance.
    )ÚintÚroundÚappend)ÚstrideÚratioÚnew_stridesÚinput_nÚleftÚrightÚtoken_nÚ
new_strides           úq/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/pipelines/automatic_speech_recognition.pyÚrescale_strider!   )   s„   € ð €KØ &ò 'Ñˆ��uÜ”e˜G e™OÓ,Ó-ˆÜ”5˜ ™¨'Ñ1Ó2Ó3ˆÜ”E˜% '™/¨GÑ3Ó4Ó5ˆØ˜t UÐ+ˆ
Ø×Ñ˜:Õ&ð'ð Ðó    c              #   óR  K  — | j                   d   }||z
  |z
  }t        d||«      D ]|  }||z   }	| ||	 }
 ||
|j                  d¬«      }|�|j                  |¬«      }|dk(  rdn|}|	|k\  }|rdn|}|
j                   d   }|||f}|
j                   d   |kD  r	||dœ|¥–— |sŒ| y  y ­w)Nr   Úpt)Úsampling_rateÚreturn_tensors©Údtype)Úis_lastr   )ÚshapeÚranger%   Úto)ÚinputsÚfeature_extractorÚ	chunk_lenÚstride_leftÚstride_rightr(   Ú
inputs_lenÚstepÚchunk_start_idxÚchunk_end_idxÚchunkÚ	processedÚ_stride_leftr)   Ú_stride_rightr   s                   r    Ú
chunk_iterr:   =   sÜ   è ø€ Ø—‘˜a‘€JØ�{Ñ" \Ñ1€DÜ   J°Ó5ò ˆØ'¨)Ñ3ˆØ� }Ð5ˆÙ% eÐ;L×;ZÑ;ZÐkoÔpˆ	ØÐØ!Ÿ™¨5˜Ó1ˆIØ+¨qÒ0‘q°kˆØ :Ñ-ˆÙ$™¨,ˆà—K‘K ‘Nˆ	Ø˜\¨=Ð9ˆØ�;‰;�q‰>˜LÒ(Ø%°ÑE¸9ÐEÒEÚÙñùs   ‚B B'Â#B'c                 óî  — t        | «      }t        |«      }t        |dz   «      D �cg c]  }dg|dz   z  ‘Œ }}d}t        |«      D ]?  }t        |«      D ]/  }| |   ||   k(  sŒ||   |   dz   }	|	||dz      |dz   <   |	|kD  sŒ.|	}Œ1 ŒA t        j                  |«      }|dk7  r!t        j                  ||k(  «      d   d   |z
  nd}
|dk7  r!t        j                  ||k(  «      d   d   |z
  nd}|
||fS c c}w )Nr   r   éÿÿÿÿ)Úlenr+   ÚnpÚarrayÚargwhere)Úsequence_leftÚsequence_rightÚseq_len_leftÚseq_len_rightÚ_ÚcounterÚlongestÚiÚjÚprevious_counterÚ
index_leftÚindex_rights               r    Ú"_fast_find_longest_common_sequencerM   R   s/  € Ü�}Ó%€LÜ˜Ó'€MÜ27¸ÀqÑ8HÓ2IÖJ¨Q�ˆs�m aÑ'Ó(ÐJ€GÐJØ€GÜ�<Ó ò /ˆÜ�}Ó%ò 	/ˆAØ˜QÑ >°!Ñ#4Ó4Ø#*¨1¡:¨a¡=°1Ñ#4Ð Ø(8�˜˜A™‘˜q 1™uÑ%Ø# gÓ-Ø.‘Gñ	/ð/ô �h‰h�wÓ€GàELÐPQÂ\”—‘˜W¨Ñ/Ó0°Ñ4°QÑ7¸'ÒAÐWY€JØFMÐQRÂl”"—+‘+˜g¨Ñ0Ó1°"Ñ5°aÑ8¸7ÒBÐXZ€KØ�{ GÐ+Ð+ùò Ks   §C2c           
      óD  — | d   d   j                  «       D �cg c]  }||j                  vsŒ|‘Œ }}| dd  D ]È  }|d   j                  «       D �cg c]  }||j                  vsŒ|‘Œ }}d}d}t        dt        |«      dz   «      D ]d  }|dz  }	t	        j
                  t	        j                  || d  «      t	        j                  |d | «      k(  «      }
|
|z  |	z   }|
dkD  sŒ[||kD  sŒa|}|}Œf |j                  ||d  «       ŒÊ t	        j                  |«      S c c}w c c}w )Nr   r   g        g     ˆÃ@)ÚtolistÚall_special_idsr+   r=   r>   Úsumr?   Úextend)Ú	sequencesÚ	tokenizerÚtok_idÚsequenceÚnew_seqÚnew_sequenceÚindexÚmax_rH   ÚepsÚmatchesÚmatchings               r    Ú_find_longest_common_sequencer^   f   s3  € ð &/¨q¡\°!¡_×%;Ñ%;Ó%=Öi˜6ÀÈy×OhÑOhÒAh’Ði€HÐiØ˜Q˜R�=ò .ˆØ-4°Q©Z×->Ñ->Ó-@Öl 6ÀFÐR[×RkÑRkÒDkšÐlˆÐlàˆØˆÜ�qœ#˜lÓ+¨aÑ/Ó0ò 	 ˆAà�g‘+ˆCÜ—f‘fœRŸX™X h°¨r¨s mÓ4¼¿¹ÀÈbÈqÐAQÓ8RÑRÓSˆGØ ‘{ SÑ(ˆHØ˜‹{˜x¨$›Ø�Ø‘ð	 ð 	�‰˜ U VÐ,Õ-ð.ô �8‰8�HÓÐùò jùâls   ™D­DÁDÁ$Dc                   óð   ‡ — e Zd ZdZ	 	 	 	 	 ddddedef   dee   deedef      d	eed
f   deeedf      fˆ fd„Z	dee
j                  eef   fˆ fd„Z	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Z	 ddee   fd„Zˆ xZS )Ú"AutomaticSpeechRecognitionPipelineaŒ  
    Pipeline that aims at extracting spoken text contained within some audio.

    The input can be either a raw waveform or a audio file. In case of the audio file, ffmpeg should be installed for
    to support multiple audio formats

    Example:

    ```python
    >>> from transformers import pipeline

    >>> transcriber = pipeline(model="openai/whisper-base")
    >>> transcriber("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/1.flac")
    {'text': ' He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick, peppered flour-fatten sauce.'}
    ```

    Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)

    Arguments:
        model ([`PreTrainedModel`] or [`TFPreTrainedModel`]):
            The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from
            [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for TensorFlow.
        feature_extractor ([`SequenceFeatureExtractor`]):
            The feature extractor that will be used by the pipeline to encode waveform for the model.
        tokenizer ([`PreTrainedTokenizer`]):
            The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from
            [`PreTrainedTokenizer`].
        decoder (`pyctcdecode.BeamSearchDecoderCTC`, *optional*):
            [PyCTCDecode's
            BeamSearchDecoderCTC](https://github.com/kensho-technologies/pyctcdecode/blob/2fd33dc37c4111417e08d89ccd23d28e9b308d19/pyctcdecode/decoder.py#L180)
            can be passed for language model boosted decoding. See [`Wav2Vec2ProcessorWithLM`] for more information.
        chunk_length_s (`float`, *optional*, defaults to 0):
            The input length for in each chunk. If `chunk_length_s = 0` then chunking is disabled (default).

            <Tip>

            For more information on how to effectively use `chunk_length_s`, please have a look at the [ASR chunking
            blog post](https://huggingface.co/blog/asr-chunking).

            </Tip>

        stride_length_s (`float`, *optional*, defaults to `chunk_length_s / 6`):
            The length of stride on the left and right of each chunk. Used only with `chunk_length_s > 0`. This enables
            the model to *see* more context and infer letters better than without this context but the pipeline
            discards the stride bits at the end to make the final reconstitution as perfect as possible.

            <Tip>

            For more information on how to effectively use `stride_length_s`, please have a look at the [ASR chunking
            blog post](https://huggingface.co/blog/asr-chunking).

            </Tip>

        framework (`str`, *optional*):
            The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
            installed. If no framework is specified, will default to the one currently installed. If no framework is
            specified and both frameworks are installed, will default to the framework of the `model`, or to PyTorch if
            no model is provided.
        device (Union[`int`, `torch.device`], *optional*):
            Device ordinal for CPU/GPU supports. Setting this to `None` will leverage CPU, a positive will run the
            model on the associated CUDA device id.
        torch_dtype (Union[`int`, `torch.dtype`], *optional*):
            The data-type (dtype) of the computation. Setting this to `None` will use float32 precision. Set to
            `torch.float16` or `torch.bfloat16` to use half-precision in the respective dtypes.

    Úmodelr   r.   r   rT   Údecoderr   Údeviceztorch.deviceÚtorch_dtypeztorch.dtypec                 óT  •— |j                   j                  dk(  rd| _        nq|j                  j                  t        j                  «       v rd| _        n?|j                  r,|j                  j                  d«      r|�|| _	        d| _        nd| _        t        ‰| �,  |||f||dœ|¤Ž y )NÚwhisperÚseq2seq_whisperÚseq2seqÚWithLMÚctc_with_lmÚctc)rc   rd   )ÚconfigÚ
model_typeÚtypeÚ	__class__Ú__name__r   ÚvaluesÚ_processor_classÚendswithrb   ÚsuperÚ__init__)	Úselfra   r.   rT   rb   rc   rd   Úkwargsro   s	           €r    ru   z+AutomaticSpeechRecognitionPipeline.__init__Ã   s™   ø€ ð �<‰<×"Ñ" iÒ/Ø)ˆD�IØ�_‰_×%Ñ%Ô)Q×)XÑ)XÓ)ZÑZØ!ˆD�Ià×.Ò.Ø!×2Ñ2×;Ñ;¸HÔEØÐ#à"ˆDŒLØ%ˆD�IàˆDŒIä‰Ñ˜ 	Ð+<ÐoÀVÐYdÑoÐhnÓor"   r-   c                 ó$   •— t        ‰| �  |fi |¤ŽS )ae  
        Transcribe the audio sequence(s) given as inputs to text. See the [`AutomaticSpeechRecognitionPipeline`]
        documentation for more information.

        Args:
            inputs (`np.ndarray` or `bytes` or `str` or `dict`):
                The inputs is either :
                    - `str` that is either the filename of a local audio file, or a public URL address to download the
                      audio file. The file will be read at the correct sampling rate to get the waveform using
                      *ffmpeg*. This requires *ffmpeg* to be installed on the system.
                    - `bytes` it is supposed to be the content of an audio file and is interpreted by *ffmpeg* in the
                      same way.
                    - (`np.ndarray` of shape (n, ) of type `np.float32` or `np.float64`)
                        Raw audio at the correct sampling rate (no further check will be done)
                    - `dict` form can be used to pass raw audio sampled at arbitrary `sampling_rate` and let this
                      pipeline do the resampling. The dict must be in the format `{"sampling_rate": int, "raw":
                      np.array}` with optionally a `"stride": (left: int, right: int)` than can ask the pipeline to
                      treat the first `left` samples and last `right` samples to be ignored in decoding (but used at
                      inference to provide more context to the model). Only use `stride` with CTC models.
            return_timestamps (*optional*, `str` or `bool`):
                Only available for pure CTC models (Wav2Vec2, HuBERT, etc) and the Whisper model. Not available for
                other sequence-to-sequence models.

                For CTC models, timestamps can take one of two formats:
                    - `"char"`: the pipeline will return timestamps along the text for every character in the text. For
                        instance, if you get `[{"text": "h", "timestamp": (0.5, 0.6)}, {"text": "i", "timestamp": (0.7,
                        0.9)}]`, then it means the model predicts that the letter "h" was spoken after `0.5` and before
                        `0.6` seconds.
                    - `"word"`: the pipeline will return timestamps along the text for every word in the text. For
                        instance, if you get `[{"text": "hi ", "timestamp": (0.5, 0.9)}, {"text": "there", "timestamp":
                        (1.0, 1.5)}]`, then it means the model predicts that the word "hi" was spoken after `0.5` and
                        before `0.9` seconds.

                For the Whisper model, timestamps can take one of two formats:
                    - `"word"`: same as above for word-level CTC timestamps. Word-level timestamps are predicted
                        through the *dynamic-time warping (DTW)* algorithm, an approximation to word-level timestamps
                        by inspecting the cross-attention weights.
                    - `True`: the pipeline will return timestamps along the text for *segments* of words in the text.
                        For instance, if you get `[{"text": " Hi there!", "timestamp": (0.5, 1.5)}]`, then it means the
                        model predicts that the segment "Hi there!" was spoken after `0.5` and before `1.5` seconds.
                        Note that a segment of text refers to a sequence of one or more words, rather than individual
                        words as with word-level timestamps.
            generate_kwargs (`dict`, *optional*):
                The dictionary of ad-hoc parametrization of `generate_config` to be used for the generation call. For a
                complete overview of generate, check the [following
                guide](https://huggingface.co/docs/transformers/en/main_classes/text_generation).

        Return:
            `Dict`: A dictionary with the following keys:
                - **text** (`str`): The recognized text.
                - **chunks** (*optional(, `List[Dict]`)
                    When using `return_timestamps`, the `chunks` will become a list containing all the various text
                    chunks identified by the model, *e.g.* `[{"text": "hi ", "timestamp": (0.5, 0.9)}, {"text":
                    "there", "timestamp": (1.0, 1.5)}]`. The original full text can roughly be recovered by doing
                    `"".join(chunk["text"] for chunk in output["chunks"])`.
        )rt   Ú__call__)rv   r-   rw   ro   s      €r    ry   z+AutomaticSpeechRecognitionPipeline.__call__Þ   s   ø€ ôz ‰wÑ Ñ1¨&Ñ1Ð1r"   c	                 ó  — i }	|�+| j                   dk(  r|st        j                  d«       ||	d<   |�||	d<   t        t        «      }
|�t        j                  dt        «       ||
d<   |�"|�d|v rt        d«      ‚|
j                  |«       i }|�||d<   |�‚| j                   dk(  r|rt        d	«      ‚| j                   d
k(  r|dk7  rt        d«      ‚| j                   dk(  r|dvrt        d«      ‚| j                   dk(  r|dk(  rt        d«      ‚||
d<   ||d<   |�| j                   dk7  rt        d«      ‚||d<   | j                  �| j                  |
d<   | j                  �| j                  |
d<   | j                  |
d<   |	|
|fS )Nrh   a  Using `chunk_length_s` is very experimental with seq2seq models. The results will not necessarily be entirely accurate and will have caveats. More information: https://github.com/huggingface/transformers/pull/20104. Ignore this warning with pipeline(..., ignore_warning=True)Úchunk_length_sÚstride_length_sz¬`max_new_tokens` is deprecated and will be removed in version 4.49 of Transformers. To remove this warning, pass `max_new_tokens` as a key inside `generate_kwargs` instead.Úmax_new_tokenszp`max_new_tokens` is defined both as an argument and inside `generate_kwargs` argument, please use only 1 versionÚdecoder_kwargszEWe cannot return_timestamps yet on non-CTC models apart from Whisper!rj   ÚwordzRCTC with LM can only predict word level timestamps, set `return_timestamps='word'`rk   )Úcharr   z–CTC can either predict character level timestamps, or word level timestamps. Set `return_timestamps='char'` or `return_timestamps='word'` as required.rg   r€   zžWhisper cannot return `char` timestamps, only word level or segment level timestamps. Use `return_timestamps='word'` or `return_timestamps=True` respectively.Úreturn_timestampsz)Only Whisper can return language for now.Úreturn_languageÚassistant_modelrT   Úassistant_tokenizer)rn   ÚloggerÚwarningr   ÚdictÚwarningsÚwarnÚFutureWarningÚ
ValueErrorÚupdaterƒ   r„   rT   )rv   r{   r|   Úignore_warningr~   r�   r‚   Úgenerate_kwargsr}   Úpreprocess_paramsÚforward_paramsÚpostprocess_paramss               r    Ú_sanitize_parametersz7AutomaticSpeechRecognitionPipeline._sanitize_parameters  sþ  € ð ÐØÐ%Ø�y‰y˜IÒ%©nÜ—‘ð,ôð 3AÐÐ.Ñ/ØÐ&Ø3BÐÐ/Ñ0ä$¤TÓ*ˆØÐ%Ü�M‰Mð Üôð 0>ˆNÐ+Ñ,ØÐ&ØÐ)Ð.>À/Ñ.QÜ ð&óð ð ×!Ñ! /Ô2àÐØÐ%Ø3AÐÐ/Ñ0ØÐ(à�y‰y˜IÒ%Ñ*;Ü Ð!hÓiÐiØ�y‰y˜MÒ)Ð.?À6Ò.IÜ Ð!uÓvÐvØ�y‰y˜EÒ!Ð&7Ð?OÑ&OÜ ð`óð ð �y‰yÐ-Ò-Ð2CÀvÒ2MÜ ð_óð ð 3DˆNÐ.Ñ/Ø6GÐÐ2Ñ3ØÐ&Ø�y‰yÐ-Ò-Ü Ð!LÓMÐMØ4CÐÐ0Ñ1à×ÑÐ+Ø04×0DÑ0DˆNÐ,Ñ-Ø×#Ñ#Ð/Ø*.¯.©.ˆN˜;Ñ'Ø48×4LÑ4LˆNÐ0Ñ1à  .Ð2DÐDÐDr"   c              #   óÚ	  K  — t        |t        «      rg|j                  d«      s|j                  d«      r t        j                  |«      j
                  }n%t        |d«      5 }|j                  «       }d d d «       t        |t        «      r t        || j                  j                  «      }d }i }t        |t        «      �ry|j                  dd «      }d|v rd|v sd|v st        d«      ‚|j                  dd «      }|€$|j                  d	d «       |j                  dd «      }|j                  d«      }|}|}|| j                  j                  k7  r~t        «       rd
dlm}	 nt%        d«      ‚|	j'                  t)        j*                  |«      || j                  j                  «      j-                  «       }| j                  j                  |z  }
nd}
|�h|d
   |d   z   |j.                  d
   kD  rt        d«      ‚|j.                  d
   t1        t3        |d
   |
z  «      «      t1        t3        |d   |
z  «      «      f}t        |t4        j6                  «      st9        dt;        |«      › d�«      ‚t=        |j.                  «      dk7  rt        d«      ‚|�r |€|dz  }t        |t0        t>        f«      r||g}tA        | jB                  jD                  dd«      }t1        t3        || j                  j                  z  |z  «      |z  «      }t1        t3        |d
   | j                  j                  z  |z  «      |z  «      }t1        t3        |d   | j                  j                  z  |z  «      |z  «      }|||z   k  rt        d«      ‚tG        || j                  |||| jH                  «      D ]
  }i |¥|¥–— Œ y | j:                  dk(  rR|j.                  d
   | j                  jJ                  kD  r,| j                  || j                  j                  dddd¬«      }ny| j:                  dk(  rA|€?| j                  || j                  j                  ddd¬«      }|j                  d«      |d<   n)| j                  || j                  j                  dd¬«      }| jH                  �|jM                  | jH                  ¬«      }|�| j:                  dk(  rt        d «      ‚||d<   d!di|¥|¥–— y # 1 sw Y   �ŒnxY w­w)"Nzhttp://zhttps://Úrbr   r%   Úrawr?   zëWhen passing a dictionary to AutomaticSpeechRecognitionPipeline, the dict needs to contain a "raw" key containing the numpy array representing the audio and a "sampling_rate" key, containing the sampling_rate associated with that arrayÚpathr   )Ú
functionalz¢torchaudio is required to resample audio samples in AutomaticSpeechRecognitionPipeline. The torchaudio package can be installed through: `pip install torchaudio`.r   zStride is too large for inputz)We expect a numpy ndarray as input, got `ú`zMWe expect a single channel audio input for AutomaticSpeechRecognitionPipelineé   Úinputs_to_logits_ratioz.Chunk length must be superior to stride lengthrg   FrG   r$   T)r%   Ú
truncationÚpaddingr&   Úreturn_attention_mask)r%   r&   Úreturn_token_timestampsr�   Ú
num_frames)r%   r&   r�   r'   rh   z8Stride is only usable with CTC models, try removing it !r)   )'Ú
isinstanceÚstrÚ
startswithÚrequestsÚgetÚcontentÚopenÚreadÚbytesr   r.   r%   r‡   Úpopr‹   r   Ú
torchaudior—   ÚImportErrorÚresampleÚtorchÚ
from_numpyÚnumpyr*   r   r   r>   ÚndarrayÚ	TypeErrorrn   r=   ÚfloatÚgetattrra   rl   r:   rd   Ú	n_samplesr,   )rv   r-   r{   r|   Úfr   ÚextraÚ_inputsÚin_sampling_rateÚFr   Úalign_tor/   r0   r1   Úitemr7   s                    r    Ú
preprocessz-AutomaticSpeechRecognitionPipeline.preprocessg  sÙ  è ø€ Ü�fœcÔ"Ø× Ñ  Ô+¨v×/@Ñ/@ÀÔ/Lô "Ÿ™ fÓ-×5Ñ5‘ä˜& $Ó'ð &¨1ØŸV™V›X�F÷&ô �fœeÔ$Ü  ¨×)?Ñ)?×)MÑ)MÓNˆFàˆØˆÜ�fœdÕ#Ø—Z‘Z ¨$Ó/ˆFð $ vÑ-°5¸F±?ÀgÐQWÑFWÜ ðNóð ð —j‘j ¨Ó-ˆGØˆà—
‘
˜6 4Ô(Ø Ÿ*™* W¨dÓ3�Ø%Ÿz™z¨/Ó:ÐØˆEØˆFØ 4×#9Ñ#9×#GÑ#GÒGÜ*Ô,Þ:ä%ðeóð ð
 Ÿ™Ü×$Ñ$ VÓ,Ð.>À×@VÑ@V×@dÑ@dóç‘%“'ð ð ×.Ñ.×<Ñ<Ð?OÑO‘à�ØÐ!Ø˜!‘9˜v a™yÑ(¨6¯<©<¸©?Ò:Ü$Ð%DÓEÐEð !Ÿ,™, q™/¬3¬u°V¸A±YÀÑ5FÓ/GÓ+HÌ#ÌeÐTZÐ[\ÑT]Ð`eÑTeÓNfÓJgÐh�Ü˜&¤"§*¡*Ô-ÜÐGÌÈVËÀ~ÐUVÐWÓXÐXÜˆv�|‰|Ó Ò!ÜÐlÓmÐmâØÐ&Ø"0°1Ñ"4�ä˜/¬C´¨<Ô8Ø#2°OÐ"D�ô
 ˜tŸz™z×0Ñ0Ð2JÈAÓNˆHÜœE .°4×3IÑ3I×3WÑ3WÑ"WÐZbÑ"bÓcÐfnÑnÓoˆIÜœe O°AÑ$6¸×9OÑ9O×9]Ñ9]Ñ$]Ð`hÑ$hÓiÐltÑtÓuˆKÜœu _°QÑ%7¸$×:PÑ:P×:^Ñ:^Ñ%^ÐaiÑ%iÓjÐmuÑuÓvˆLà˜;¨Ñ5Ò5Ü Ð!QÓRÐRä"Ø˜×.Ñ.°	¸;ÈÐVZ×VfÑVfóò (�ð (˜Ð' Ð'Ó'ñ(ð
 �y‰yÐ-Ò-°&·,±,¸q±/ÀD×DZÑDZ×DdÑDdÒ2dØ ×2Ñ2ØØ"&×"8Ñ"8×"FÑ"FØ$Ø%Ø#'Ø*.ð 3ó ‘	ð —9‘9Ð 1Ò1°f°nØ $× 6Ñ 6ØØ&*×&<Ñ&<×&JÑ&JØ'+Ø04Ø.2ð !7ó !�Ið +4¯-©-¸Ó*E�E˜,Ò'à $× 6Ñ 6ØØ&*×&<Ñ&<×&JÑ&JØ'+Ø.2ð	 !7ó !�Ið ×ÑÐ+Ø%ŸL™L¨t×/?Ñ/?˜LÓ@�	ØÐ!Ø—9‘9 	Ò)Ü$Ð%_Ó`Ð`à&,�	˜(Ñ#Ø˜dÐ9 iÐ9°5Ð9Ó9÷a&ñ &üs   ‚AS+Á!SÁ2Q,S+ÓS(Ó#S+c                 ó¾  — |j                  dd «      }|j                  dd «      }|j                  dd «      }|j                  d«      }|�|�t        d«      ‚| j                  dv �r„d|v r|j                  d«      }n2d|v r|j                  d«      }nt        d	|j                  «       › �«      ‚|rˆ| j                  d
k(  ry||d<   |dk(  rod|d<   d|d<   |�^t	        |t
        «      r |d   | j                  j                  z  |d<   n3|D �	cg c]  }	|	d   | j                  j                  z  ‘Œ  c}	|d<   n||d<   d|vr| j                  |d<    | j                  j                  d||dœ|¤Ž}
|dk(  r`| j                  d
k(  rQd|
vr|
d   |
d   dœ}nE|
d   D ��cg c](  }t        j                  |D �cg c]  }|d   ‘Œ	 c}«      ‘Œ* }}}|
d   |dœ}nd|
i}| j                  d
k(  rã|�á||d<   nÛ| j                  j                  |j                  | j                  j                  «      d|i} | j                  di |¤Ž}|j                  }| j                  dk(  rd|i}nd|j                  d¬«      i}|�Vd| j                  j                   j"                  z  }t	        |t
        «      rt%        |g|«      d   |d<   nt%        ||«      |d<   |}d|i|¥|¥S c c}	w c c}w c c}}w )NÚattention_maskr   rŸ   r)   z0num_frames must be used only when stride is None¾   rh   rg   Úinput_featuresÚinput_valueszhSeq2Seq speech recognition model requires either a `input_features` or `input_values` key, but only has rg   r�   r   Trž   Úreturn_segmentsr   Úgeneration_config)r-   r¾   ÚsegmentsrS   Útoken_timestamps)ÚtokensrÅ   rÆ   rj   Úlogitsr<   )Údimr   © )r©   r‹   rn   Úkeysr    Útupler.   Ú
hop_lengthrÃ   ra   Úgenerater­   ÚcatÚmain_input_namerÇ   Úargmaxrl   rš   r!   )rv   Úmodel_inputsr�   rŽ   r¾   r   rŸ   r)   r-   ÚsrÆ   ÚoutÚsegment_listÚsegmentrÅ   ÚoutputsrÇ   r   r¶   s                      r    Ú_forwardz+AutomaticSpeechRecognitionPipeline._forwardà  sP  € Ø%×)Ñ)Ð*:¸DÓAˆØ×!Ñ! (¨DÓ1ˆØ!×%Ñ% l°DÓ9ˆ
Ø×"Ñ" 9Ó-ˆàÐ *Ð"8ÜÐOÓPÐPà�9‰9Ð6Ò6ð   <Ñ/Ø%×)Ñ)Ð*:Ó;‘Ø <Ñ/Ø%×)Ñ)¨.Ó9‘ä ðLØLX×L]ÑL]ÓL_ÐK`ðbóð ñ ! T§Y¡YÐ2CÒ%CØ7H�Ð 3Ñ4Ø$¨Ò.ØAE�OÐ$=Ñ>Ø9=�OÐ$5Ñ6àÐ)Ü% f¬eÔ4Ø<BÀ1¹IÈ×I_ÑI_×IjÑIjÑ<j˜O¨LÒ9àpvÖ<wÐkl¸Q¸q¹TÀT×E[ÑE[×EfÑEfÓ=fÒ<w˜O¨LÒ9à8B˜¨Ñ5ð #¨/Ñ9Ø7;×7MÑ7M�Ð 3Ñ4à(�T—Z‘Z×(Ñ(ð ØØ-ñð "ñˆFð ! FÒ*¨t¯y©yÐ<MÒ/MØ VÑ+Ø%+¨KÑ%8ÈfÐUgÑNhÑi‘Cð -3°:Ñ,>÷(à(ô Ÿ	™	ÈlÖ"[À7 7Ð+=Ó#>Ò"[Õ\ð(Ð$ñ (ð &,¨KÑ%8ÐN^Ñ_‘Cà Ð(�Ø�y‰yÐ-Ò-ØÐ%Ø$*�C˜’Mð —
‘
×*Ñ*¨L×,<Ñ,<¸T¿Z¹Z×=WÑ=WÓ,XØ  .ðˆFð !�d—j‘jÑ* 6Ñ*ˆGØ—^‘^ˆFà�y‰y˜MÒ)Ø Ð(‘à §¡°2 Ó!6Ð7�ØÐ!ð ˜DŸJ™J×-Ñ-×DÑDÑD�Ü˜f¤eÔ,Ü$2°F°8¸UÓ$CÀAÑ$F�C˜’Mä$2°6¸5Ó$A�C˜‘MàˆØ˜7Ð3 cÐ3¨UÐ3Ð3ùòi =xùò& #\ùó(s   Ä	#KÆKÆ.KÆ:	KËKr~   c                 ót  — i }g }| j                   dk(  rdnd}d }|D ]Í  }	| j                  dk(  r`|	|   j                  t        j                  t        j
                  fv r1|	|   j                  t        j                  «      j                  «       }
n|	|   j                  «       }
|	j                  dd «      }|�$| j                   dv r|\  }}}||z
  }|
d d …||…f   }
|j                  |
«       ŒÏ |r&| j                   dk(  rt        || j                  «      }
nÓ| j                   dk(  rœ| j                  j                  | j                  j                   j"                  z  }| j                  j$                  }|D ]'  }d|v sŒ|d   \  }}}||z  }||z  }||z  }|||f|d<   Œ) | j                  j'                  ||||¬	«      \  }}n(t)        j*                  |d
¬«      }
|
j-                  d«      }
| j                   dk(  rX|€i } | j.                  j0                  
fi |¤Ž}|d   d   }|rÀ|d   d   }g }|D ]  \  }\  }}|j                  |||dœ«       Œ n“| j                   dk7  r„| j                   dk7  }| j                  j3                  
|¬«      }|rV| j                  j3                  |
|d¬«      d   }|dk(  r0| j                  j5                  || j                  j6                  «      }|r³| j                   dvr¥g }D ]™  }|d   | j                  j                   j8                  z  }|| j                  j$                  z  }|d   | j                  j                   j8                  z  } | | j                  j$                  z  } |j                  ||   || fdœ«       Œ› ||d<   t;        t<        «      }!|D ]ˆ  }|j?                  dd «       |j?                  dd «       |j?                  dd «       |j?                  dd «       |j?                  dd «       |jA                  «       D ]  \  }"}#|!|"   j                  |#«       Œ ŒŠ di|¥|!¥S )Nrj   rÇ   rÆ   r$   r   >   rk   rj   rh   rg   )r�   r‚   Útime_precisionr   )Úaxisr   r   )r   Ústart_offsetÚ
end_offsetrk   )Úskip_special_tokensT)rÝ   Úoutput_char_offsetsÚchar_offsetsr   r¿   rÛ   rÜ   )ÚtextÚ	timestampÚchunksr)   rÅ   rà   )!rn   Ú	frameworkr(   r­   Úbfloat16Úfloat16r,   Úfloat32r¯   r¤   r   r^   rT   r.   Úchunk_lengthra   rl   Úmax_source_positionsr%   Ú_decode_asrr>   ÚconcatenateÚsqueezerb   Údecode_beamsÚdecodeÚ_get_word_offsetsÚreplace_word_delimiter_charrš   r   Úlistr©   Úitems)$rv   Úmodel_outputsr~   r�   r‚   ÚoptionalÚfinal_itemsÚkeyr   rÖ   rñ   Útotal_nr   r   Úright_nrÙ   r%   Úoutputr/   r0   r1   rà   ÚbeamsÚchunk_offsetÚoffsetsr   rÛ   rÜ   rÝ   râ   r»   ÚstartÚstopr¶   ÚkÚvs$                                       r    Úpostprocessz.AutomaticSpeechRecognitionPipeline.postprocess7  s\  € ð ˆàˆØŸ)™) }Ò4‰h¸(ˆØˆØ$ò 	&ˆGØ�~‰~ Ò%¨'°#©,×*<Ñ*<ÄÇÁÔQV×Q^ÑQ^Ð@_Ñ*_Ø ™Ÿ™¬¯©Ó6×<Ñ<Ó>‘à ™×*Ñ*Ó,�Ø—[‘[ ¨4Ó0ˆFØÐ! d§i¡iÐ3IÑ&IØ'-Ñ$�˜˜uð
 " E™/�Øša  g ˜oÑ.�Ø×Ñ˜uÕ%ð	&ñ  �d—i‘i 9Ò,Ü1°+¸t¿~¹~ÓN‰EØ�Y‰YÐ+Ò+Ø!×3Ñ3×@Ñ@À4Ç:Á:×CTÑCT×CiÑCiÑiˆNà ×2Ñ2×@Ñ@ˆMØ'ò L�Ø˜vÒ%Ø;AÀ(Ñ;KÑ8�I˜{¨Là Ñ.�IØ =Ñ0�KØ  MÑ1�LØ'0°+¸|Ð'K�F˜8Ò$ðLð "Ÿ^™^×7Ñ7ØØ"3Ø /Ø-ð	 8ó ‰NˆD‘(ô —N‘N ;°QÔ7ˆEØ—M‘M !Ó$ˆEà�9‰9˜Ò%ØÐ%Ø!#�Ø-�D—L‘L×-Ñ-¨eÑF°~ÑFˆEØ˜‘8˜A‘;ˆDÙ ð  % Q™x¨™{�Ø�Ø8Dò kÑ4�DÑ4˜<¨Ø—N‘N¨DÀ,Ð^hÑ#iÕjñkà�Y‰YÐ+Ò+Ø"&§)¡)¨uÑ"4ÐØ—>‘>×(Ñ(¨ÐDWÐ(ÓXˆDÙ ØŸ.™.×/Ñ/ØÐ/BÐX\ð 0ó à ñ"�ð %¨Ò.Ø"Ÿn™n×>Ñ>¸wÈÏÉ×HrÑHrÓs�Gá §¡Ð2PÑ!PØˆFØò ]�Ø˜^Ñ,¨t¯z©z×/@Ñ/@×/WÑ/WÑW�Ø˜×/Ñ/×=Ñ=Ñ=�à˜LÑ)¨D¯J©J×,=Ñ,=×,TÑ,TÑT�Ø˜×.Ñ.×<Ñ<Ñ<�à—‘ tÐ,=Ñ'>ÈeÐUYÈ]Ñ[Õ\ð]ð "(ˆH�XÑäœDÓ!ˆØ#ò 	#ˆFØ�J‰J�x Ô&Ø�J‰J�x Ô&Ø�J‰J�y $Ô'Ø�J‰J�x Ô&Ø�J‰JÐ)¨4Ô0ØŸ™›ò #‘��1Ø�a‘—‘ Õ"ñ#ð	#ð ˜Ð2 Ð2¨EÐ2Ð2r"   )NNNNN)NNNNNNNN)r   N)F)NNN)rp   Ú
__module__Ú__qualname__Ú__doc__r   r¡   r   r	   r   ru   r>   r°   r¨   ry   r’   r¼   r×   r   r   Ú__classcell__)ro   s   @r    r`   r`      s  ø„ ñAðL EIØ37Ø@DØ-1Ø;?ñpà ðpð !Ð!;¸SÐ!@ÑAðpð Ð/Ñ0ð	pð
 ˜%Ð 6¸Ð ;Ñ<Ñ=ðpð �c˜>Ð)Ñ*ðpð ˜e C¨Ð$6Ñ7Ñ8õpð6=2à�b—j‘j %¨Ð,Ñ-õ=2ðB ØØØØØØØóHEóTw:órU4ðp mqñ]3Ø-5°d©^÷]3r"   r`   c                 ó  — |j                  d«      dz   }g }|j                  |z  }d}t        | «      D �]™  \  }}	|	\  }
}t        |
t        «      rt        j                  |
«      }
|\  }}}|
j                  d«      }
||
v rt        j                  |
|k(  «      d   d   nd}|
|d }
|
|k\  }|dk7  �rJt        |«      dkD  �r;t        j                  |dd |dd z  «      d   dz   }t        j                  |«      d   d   }||vrt        j                  ||«      n|}|||z   z  }t        ||j                  z  |z  «      }t        ||j                  z  |z  «      }t        j                  |
|   ||z   k\  «      d   }|j                  d   dkD  �rn|d   dkD  r||d   dz
     n|d   }d}g }t        t        |«      «      D �]  \  }}|dd }|d   ||z   |z
  k  r|dk7  r nåt        |«      dkD  sŒ0t!        |
d| |«      \  }}}|dkD  sŒI||kD  sŒO|}|}t        j                  |
|dz   d |k\  «      d   d   dz   }|dz   |z   }|dk(  r7|t        |«      k(  r)t        j"                  |
|dz   | d|d   «      }|d   |d<   Œ¾|dk\  sŒÄ|
|dz   | }|dkD  r|d|dz    n|d   g} t        j"                  |d| «      }|dxx   |z  cc<   �Œ t        |«      dkD  r*||t        |«      z
  dz
  <   |dt        |«      |z
   }|
d }
|
|k\  }t        j                  |dd |dd z  «      d   dz   }t        |«      dkD  r:t        j                  |«      d   d   }||vrt        j                  ||dz   «      n|}t        |«      dkD  rPd}!|D ]I  }"|dk7  s|!dk7  r|d   d   n|
d   }#|
|!|" }$|$d   |$d   z
  }%|#|$d<   |#|%z   |$d<   |j                  |$«       |"}!ŒK ||z  }�Œœ g }&t%        t        |«      «      D ]  }'|&||'   j'                  «       z  }&Œ |&S )aý  
    Computes the final sequences by merging the end of the nth sequence with the beginning of the n+1th sequence. Since
    `WhisperForConditionalGeneration` produces the timestamps pairwise, we filter the consecutive timestamps and only
    iterate over them. We keep track of the `time` which indicates the actual starting time of the chunk that is
    processed. We need to make sure to offset the timestamps tokens by the `time` in order for the tokenizer to
    properly compute the final `offset`.
    z<|notimestamps|>r   r   Nr<   )Úconvert_tokens_to_idsrç   Ú	enumerater    rð   r>   r?   rë   ÚwhererQ   r   r   r%   r*   Úreversedr=   rM   Úinsertr+   rO   )(rS   rT   r.   rè   Útimestamp_beginrñ   rÙ   ÚtimeÚseq_idxr»   rV   r   r/   r0   r1   Ú	begin_idxÚtimestamp_tokensÚconsecutiveÚlast_timestampÚoffsetÚoverlap_timeÚrelevant_timestampÚ
best_matchÚsliced_sequenceÚidxÚprevious_sequenceÚprevious_tokensrK   rL   Úmatch_lengthÚbest_idxÚend_of_curr_sequence_idxÚprevious_sliceÚ
last_sliceÚcurrent_sliceÚactual_offsetÚsliced_tokensÚdurationÚresultrH   s(                                           r    Ú_find_timestamp_sequencer$  —  s7  € ð  ×5Ñ5Ð6HÓIÈAÑM€OØ€Eà&×3Ñ3Ð6JÑJ€NØ€DÜ" 9Ó-ó U‰ˆ�ØÑˆ�&Ü�h¤Ô%Ü—x‘x Ó)ˆHØ/5Ñ,ˆ	�; Ø×#Ñ# AÓ&ˆàCRÐV^ÑC^”B—H‘H˜X¨Ñ8Ó9¸!Ñ<¸QÒ?Ðdeˆ	Ø˜I˜JÐ'ˆà# Ñ6ÐØ�a‹<œCÐ 0Ó1°AÓ5ÜŸ(™(Ð#3°C°RÐ#8Ð;KÈAÈBÐ;OÑ#OÓPÐQRÑSÐVWÑWˆKÜŸX™XÐ&6Ó7¸Ñ:¸2Ñ>ˆNØDRÐZeÑDeœ"Ÿ)™) K°Ô@ÐkvˆKØ�K ,Ñ.Ñ.ˆDÜ˜$Ð!2×!@Ñ!@Ñ@ÀNÑRÓSˆFÜ Ð.?×.MÑ.MÑ MÐQ_Ñ_Ó`ˆLä!#§¡¨(°;Ñ*?À?ÐUaÑCaÑ*aÓ!bÐcdÑ!eÐØ!×'Ñ'¨Ñ*¨QÓ.à>PÐQRÑ>SÐVWÒ>W�KÐ 2°1Ñ 5¸Ñ 9Ò:Ð]hÐijÑ]kð #ð �
Ø"$�Ü.7¼À»Ó.Hó >Ñ*�CÐ*Ø&7¸¸"Ð&=�OØ(¨Ñ+¨ÀÑ/GÈ,Ñ/VÒWÐ\_ÐcdÒ\dÙÜ˜?Ó+¨aÓ/ä@bØ$ QÐ'9Ð:¸OóAÑ=˜
 K°ð (¨!Ó+°¸zÓ0IØ)5˜JØ'*˜Hä "§¡¨°*¸q±.Ð2BÐ)CÀÑ)VÓ WÐXYÑ ZÐ[\Ñ ]Ð`aÑ að 5ð 8PÐRSÑ7SÐV`Ñ7`Ð4à)¨Qš°<Ä3ÀÓCWÒ3WÜ24·)±)Ø$,¨Z¸!©^Ð>VÐ$WÐYZÐ\mÐnoÑ\pó3" ð 7HÈÑ6K °Ò 3à!+¨q£Ø2:¸:È¹>ÐLdÐ2e ð MXÐZ[ÊOÐ$5Ð6G¸Àa¹Ñ$HÐbsÐtuÑbvÐawð !/ô 35·)±)¸OÈQÐP^Ó2_ Ø /°Ó 3°vÑ =Õ 3ð?>ôB �Ó'¨!Ò+Ø7F�Eœ#˜e›* xÑ/°!Ñ3Ñ4Ø!Ð"9¤C¨£J°Ñ$9Ð:�EØ'Ð(@Ð(AÐB�Hð $ Ñ6ÐÜ—h‘hÐ/°°Ð4Ð7GÈÈÐ7KÑKÓLÈQÑOÐRSÑSˆÜÐÓ  1Ò$ÜŸX™XÐ&6Ó7¸Ñ:¸2Ñ>ˆNà>LÐT_Ñ>_”—	‘	˜+ ~¸Ñ'9Ô:Ðepð ô ˆ{Ó˜aÒØˆJØ!,ò +�Ø18¸A²ÀÈqÂ  b¡	¨"¢ÐV^Ð_`ÑVa�Ø (¨°MÐ B�Ø(¨Ñ,¨}¸QÑ/?Ñ?�Ø#0�˜aÑ Ø$1°HÑ$<�˜bÑ!Ø—‘˜]Ô+Ø*‘
ð+ð 	�	ÑŠðkUðl €FÜ”3�u“:Óò $ˆØ�%˜‘(—/‘/Ó#Ñ#‰ð$à€Mr"   )N)'rˆ   Úcollectionsr   Útypingr   r   r   r   r¯   r>   r£   Útokenization_utilsr	   Úutilsr
   r   r   Úaudio_utilsr   Úbaser   Úpyctcdecoder   Ú!feature_extraction_sequence_utilsr   Úmodeling_utilsr   Ú
get_loggerrp   r…   r­   Úmodels.auto.modeling_autor   r!   r:   rM   r^   r`   r$  rÉ   r"   r    ú<module>r0     s}   ðó Ý #ß 7Ó 7ã Û å 4ß HÑ HÝ $Ý ñ Ý0åLÝ0à	ˆ×	Ñ	˜HÓ	%€áÔÛåTòó(ò*,ò(ô2U3¨ô U3ópgr"   