Ë
    ÜÓ^j«Œ  ã                   ó  — d dl mZ d dlmZmZmZ d dlZd dlZddl	m
Z
 ddlmZ ddlmZ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j8                  e«      Z e«       r
d dlZddl m!Z! d„ Z"dd„Z#d„ Z$ G d„ de«      Z%y)é    )Údefaultdict)ÚTYPE_CHECKINGÚAnyÚUnionNé   )ÚGenerationConfig)ÚPreTrainedTokenizer)Úis_torch_availableÚis_torchaudio_availableÚis_torchcodec_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           ú~/var/www/ramen.bs-engineer-server.com/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              #   óT  K  — | j                   d   }||z
  |z
  }t        d||«      D ]}  }||z   }	| ||	 }
 ||
|j                  dd¬«      }|�|j                  |¬«      }|dk(  rdn|}|	|k\  }|rdn|}|
j                   d   }|||f}|
j                   d   |kD  r	||dœ|¥–— |sŒ} y  y ­w)Nr   ÚptT©Úsampling_rateÚreturn_tensorsÚreturn_attention_mask©Ú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ˆÙ%ØØ+×9Ñ9ØØ"&ô	
ˆ	ð ÐØ!Ÿ™¨5˜Ó1ˆIØ+¨qÒ0‘q°kˆØ :Ñ-ˆÙ$™¨,ˆà—K‘K ‘Nˆ	Ø˜\¨=Ð9ˆØ�;‰;�q‰>˜LÒ(Ø%°ÑE¸9ÐEÒEÚÙñ)ùs   ‚B!B(Â$B(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.   ÚlenÚnpÚsumÚarrayÚextend)Ú	sequencesÚ	tokenizerÚtok_idÚsequenceÚnew_seqÚnew_sequenceÚindexÚmax_ÚiÚepsÚmatchesÚmatchings               r!   Ú_find_longest_common_sequencerR   W   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                   ó8  ‡ — e Zd ZdZdZdZdZdZdZ e	dd¬«      Z
	 	 	 	 ddd	d
edef   dz  dedz  dedef   dz  deedf   dz  f
ˆ fd„Zdej"                  ez  ez  ez  dedeeeef      fˆ fd„Z	 	 	 	 	 	 dd„Zed„ «       Zdd„Zdd„Z	 d dedz  fd„Zˆ xZS )!Ú"AutomaticSpeechRecognitionPipelineao  
    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

    Unless the model you're using explicitly sets these generation parameters in its configuration files
    (`generation_config.json`), the following default values will be used:
    - max_new_tokens: 256
    - num_beams: 5

    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`]):
            The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from
            [`PreTrainedModel`].
        feature_extractor ([`SequenceFeatureExtractor`], *optional*):
            The feature extractor that will be used by the pipeline to encode waveform for the model.
        tokenizer ([`PreTrainedTokenizer`], *optional*):
            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.
        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.
    TFé   é   )Úmax_new_tokensÚ	num_beamsNÚmodelr   r1   r   rG   Údecoderr   Údeviceztorch.devicec                 óD  •— |j                   j                  dk(  rd| _        nj|j                  j                  t        j                  «       v rd| _        n8|j                   j                  dv rd| _        n|�|| _        d| _        nd| _        t        ‰| �$  |||fd|i|¤Ž y )	NÚwhisperÚseq2seq_whisperÚseq2seq)Úparakeet_tdtÚparakeet_rnntÚnemotron_asr_streamingÚnemotron3_5_asrÚtdtÚctc_with_lmÚctcr[   )
ÚconfigÚ
model_typeÚtypeÚ	__class__Ú__name__r   ÚvaluesrZ   ÚsuperÚ__init__)ÚselfrY   r1   rG   rZ   r[   Úkwargsrj   s          €r!   rn   z+AutomaticSpeechRecognitionPipeline.__init__¥   s’   ø€ ð �<‰<×"Ñ" iÒ/Ø)ˆD�IØ�_‰_×%Ñ%Ô)Q×)XÑ)XÓ)ZÑZØ!ˆD�IØ�\‰\×$Ñ$Ð(vÑvàˆD�IØÐ Ø"ˆDŒLØ%ˆD�IàˆDŒIä‰Ñ˜ 	Ð+<ÑVÀVÐVÈvÓVr#   r0   rp   Úreturnc                 ó$   •— 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"])`.
        )rm   Ú__call__)ro   r0   rp   rj   s      €r!   rs   z+AutomaticSpeechRecognitionPipeline.__call__¾   s   ø€ ôr ‰wÑ Ñ1¨&Ñ1Ð1r#   c                 ó|  — i }i }	i }
|�@| j                   dv r-|s+d}| j                   dk(  r|dz  }t        j                  |«       ||d<   |�||d<   d|v r |	j                  |j	                  d«      «       |	j                  |«       t        | dd «      �| j                  |	d<   t        | d	d «      �| j                  |	d
<   | j                  |	d	<   |�||
d<   |�$| j                   dk7  rt        d«      ‚||
d<   ||	d<   t        | d«      r0t        | j                  d«      r|xs | j                  j                  }|�‚| 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<   ||	|
fS )N)r_   r^   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).r^   zÕ To use Whisper for long-form transcription, use rather the model's `generate` method directly as the model relies on it's own chunking mechanism (cf. Whisper original paper, section 3.8. Long-form Transcription).Úchunk_length_sÚstride_length_sÚgenerate_kwargsÚassistant_modelÚassistant_tokenizerrG   Údecoder_kwargsz)Only Whisper can return language for now.Úreturn_languageÚgeneration_configÚreturn_timestampsr_   zEWe cannot return_timestamps yet on non-CTC models apart from Whisper!re   ÚwordzRCTC with LM can only predict word level timestamps, set `return_timestamps='word'`rf   )Úcharr~   z–CTC can either predict character level timestamps, or word level timestamps. Set `return_timestamps='char'` or `return_timestamps='word'` as required.r   zžWhisper cannot return `char` timestamps, only word level or segment level timestamps. Use `return_timestamps='word'` or `return_timestamps=True` respectively.)ri   ÚloggerÚwarningÚupdateÚpopÚgetattrrx   rG   ry   Ú
ValueErrorÚhasattrr|   r}   )ro   ru   rv   Úignore_warningrz   r}   r{   rw   Úpreprocess_paramsÚforward_paramsÚpostprocess_paramsÚtype_warnings               r!   Ú_sanitize_parametersz7AutomaticSpeechRecognitionPipeline._sanitize_parametersù   s;  € ð ÐØˆØÐð Ð%Ø�y‰yÐ:Ñ:Á>ð-ð ð —9‘9Ð 1Ò1Ø ð4ñ�Lô
 —‘˜|Ô,Ø2@ÐÐ.Ñ/ØÐ&Ø3BÐÐ/Ñ0ð  Ñ/Ø×!Ñ! /×"5Ñ"5Ð6GÓ"HÔIà×Ñ˜oÔ.ä�4Ð*¨DÓ1Ð=Ø04×0DÑ0DˆNÐ,Ñ-Ü�4Ð.°Ó5ÐAØ*.¯.©.ˆN˜;Ñ'Ø48×4LÑ4LˆNÐ0Ñ1ð Ð%Ø3AÐÐ/Ñ0ØÐ&Ø�y‰yÐ-Ò-Ü Ð!LÓMÐMØ4CÐÐ0Ñ1Ø0?ˆNÐ,Ñ-ô �4Ð,Ô-´'¸$×:PÑ:PÐReÔ2fØ 1Ò ]°T×5KÑ5K×5]Ñ5]ÐàÐ(à�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à  .Ð2DÐDÐDr#   c                 óÀ   — t        | j                  j                  dd«      }| j                  j                  j                  dk(  r|| j                  j
                  z  }|S )zSample stride per output.Úinputs_to_logits_ratior   Úlasr_ctc)r„   rY   rg   rh   r1   Ú
hop_length)ro   Úalign_tos     r!   Ú	_align_toz,AutomaticSpeechRecognitionPipeline._align_toK  sR   € ô ˜4Ÿ:™:×,Ñ,Ð.FÈÓJˆØ�:‰:×Ñ×'Ñ'¨:Ò5ð ˜×.Ñ.×9Ñ9Ñ9ˆHØˆr#   c              #   óœ  K  — t        |t        «      ri|j                  d«      s|j                  d«      r"t        j                  |d¬«      j
                  }n%t        |d«      5 }|j                  «       }d d d «       t        |t        «      r t        || j                  j                  «      }d }i }t        «       r8dd l}t        ||j                  «      r|j                  «       j!                  «       }t#        «       rwdd l}t        ||j&                  j(                  «      rS|j+                  «       }	|	j,                  }
|
j.                  dk(  r|
j0                  d   dk(  r|
d   n|
}
|
|	j2                  d	œ}t        |t4        «      �r’|j7                  d
d «      }d|v rd|v sd|v st9        d«      ‚|j7                  dd «      }|€$|j7                  dd «       |j7                  dd «      }|j7                  d«      }|}|}|| j                  j                  k7  r—t;        «       rddlm} ntA        d«      ‚|jC                  t        |tD        jF                  «      r jH                  |«      n||| j                  j                  «      j!                  «       }| j                  j                  |z  }nd}|�h|d   |d   z   |j0                  d   kD  rt9        d«      ‚|j0                  d   tK        tM        |d   |z  «      «      tK        tM        |d   |z  «      «      f}t        |tD        jF                  j                  f«      stO        dtQ        |«      › d�«      ‚|j.                  dk7  r5tR        jU                  d|j.                  › d�«       |jW                  d¬«      }|�r|€|dz  }t        |tJ        tX        f«      r||g}| jZ                  }tK        tM        || j                  j                  z  |z  «      |z  «      }tK        tM        |d   | j                  j                  z  |z  «      |z  «      }tK        tM        |d   | j                  j                  z  |z  «      |z  «      }|||z   k  rt9        d«      ‚t]        || j                  |||| j^                  «      D ]
  }i |¥|¥–— Œ y | jP                  dk(  rR|j0                  d   | j                  j`                  kD  r,| j                  || j                  j                  dddd¬«      }nd| jP                  dk(  r,|€*| j                  || j                  j                  dd¬«      }n)| j                  || j                  j                  dd¬«      }| j^                  �|jc                  | j^                  ¬ «      }|�| jP                  d!k(  rt9        d"«      ‚||d
<   d#di|¥|¥–— y # 1 sw Y   �ŒMxY w­w)$Nzhttp://zhttps://T)Úfollow_redirectsÚrbr   r   r   )rD   r'   r   r'   ÚrawrD   zûWhen passing a dictionary to AutomaticSpeechRecognitionPipeline, the dict needs to contain a "raw" key containing the numpy array or torch tensor representing the audio and a "sampling_rate" key, containing the sampling_rate associated with that arrayÚpath)Ú
functionalz¢torchaudio is required to resample audio samples in AutomaticSpeechRecognitionPipeline. The torchaudio package can be installed through: `pip install torchaudio`.zStride is too large for inputz9We expect a numpy ndarray or torch tensor as input, got `ú`zSWe expect a single channel audio input for AutomaticSpeechRecognitionPipeline, got z6. Taking the mean of the channels for mono conversion.©Úaxisé   z.Chunk length must be superior to stride lengthr^   FÚlongestr%   )r'   Ú
truncationÚpaddingr(   r)   r&   r*   r_   z8Stride is only usable with CTC models, try removing it !r,   )2Ú
isinstanceÚstrÚ
startswithÚhttpxÚgetÚcontentÚopenÚreadÚbytesr   r1   r'   r
   ÚtorchÚTensorÚcpuÚnumpyr   Ú
torchcodecÚdecodersÚAudioDecoderÚget_all_samplesÚdataÚndimr-   Úsample_rateÚdictrƒ   r…   r   Ú
torchaudior˜   ÚImportErrorÚresamplerB   ÚndarrayÚ
from_numpyr   r   Ú	TypeErrorri   r€   r�   ÚmeanÚfloatr’   r=   r+   Ú	n_samplesr/   )ro   r0   ru   rv   Úfr   Úextrar©   r­   Ú_audio_samplesÚ_arrayÚ_inputsÚin_sampling_rateÚFr   r‘   r2   r3   r4   Úitemr:   s                        r!   Ú
preprocessz-AutomaticSpeechRecognitionPipeline.preprocessY  s’  è ø€ Ü�fœcÔ"Ø× Ñ  Ô+¨v×/@Ñ/@ÀÔ/Lô Ÿ™ 6¸DÔA×IÑI‘ä˜& $Ó'ð &¨1ØŸV™V›X�F÷&ô �fœeÔ$Ü  ¨×)?Ñ)?×)MÑ)MÓNˆFàˆØˆäÔÛä˜& %§,¡,Ô/ØŸ™›×+Ñ+Ó-�ä"Ô$Ûä˜& *×"5Ñ"5×"BÑ"BÔCØ!'×!7Ñ!7Ó!9�ð (×,Ñ,�Ø&,§k¡k°QÒ&6¸6¿<¹<È¹?ÈaÒ;O˜ šÐU[�Ø#)¸N×<VÑ<VÑW�ä�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óð ð
 Ÿ™Ü0:¸6Ä2Ç:Á:Ô0NÐ$�E×$Ñ$ VÔ,ÐTZØ$Ø×*Ñ*×8Ñ8ó÷ ‘%“'ð	 ð
 ×.Ñ.×<Ñ<Ð?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�Ü˜&¤2§:¡:¨u¯|©|Ð"<Ô=ÜÐWÔX\Ð]cÓXdÐWeÐefÐgÓhÐhØ�;‰;˜!ÒÜ�N‰NØeÐfl×fqÑfqÐerð  sið  jôð —[‘[ a�[Ó(ˆFâØÐ&Ø"0°1Ñ"4�ä˜/¬C´¨<Ô8Ø#2°OÐ"D�à—~‘~ˆ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ä" 6¨4×+AÑ+AÀ9ÈkÐ[gÐim×isÑisÓtò (�Ø'˜Ð' Ð'Ó'ñ(ð �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Ø'+Ø.2ð	 !7ó !‘Ið !%× 6Ñ 6ØØ&*×&<Ñ&<×&JÑ&JØ'+Ø.2ð	 !7ó !�Ið �z‰zÐ%Ø%ŸL™L¨t¯z©z˜LÓ:�	ØÐ!Ø—9‘9 	Ò)Ü$Ð%_Ó`Ð`à&,�	˜(Ñ#Ø˜dÐ9 iÐ9°5Ð9Ó9÷C&ñ &üs   ‚A!WÁ#V?Á4UWÖ?W	×Wc                 óÖ  — |j                  dd «      }|j                  dd «      }|j                  dd «      }|j                  d«      }|�|�t        d«      ‚| j                  dv �rtd|v r|j                  d«      }	n2d|v r|j                  d«      }	nt        d	|j                  «       › �«      ‚|xs t	        | j
                  d
d«      }|r,| j                  dk(  rt        |«      |d
<   |dk(  r
d|d<   d|d<   d|vr| j
                  |d<   t        | j                  d«      r| j                  j                  nd}
|
|	d|i|¥}|r| j                  dk(  rd|d<    | j                  j                  d&i |¤Ž}|dk(  r`| j                  dk(  rQd|vr|d   |d   dœ}na|d   D ��cg c](  }t        j                  |D �cg c]  }|d   ‘Œ	 c}«      ‘Œ* }}}|d   |dœ}n t        |t        «      rd|v rd|d   i}nd|i}| j                  dk(  �rO|�||d<   |�rEt        |t        «      �r4d|v �r/|d   }|�r'|d   �r!|d   d   d   }t        |t        «      r|d   n|}|j                  d| j
                  «      }t        |d«      �rÖt!        |j"                  j%                  «       «      }|j'                  «       D ]"  }||v sŒt        j(                  |g«      |d<    �n �n|| j                  dv rÈ| j                  j                  |j                  | j                  j                  «      d|i}	 | j                  d&i |	¤Ž}|j*                  }| j                  dk(  rd|i}nd|j-                  d ¬!«      i}|�éd"| j.                  z  }t        |t0        «      rt3        |g|«      d   |d<   n¶t3        ||«      |d<   n¦| j                  d#k(  r~| j                  j                  |j                  | j                  j                  «      i}	d|v r|j                  d«      |	d<    | j                  j                  d&i |	¤Ž}d|j4                  i}nt        d$| j                  › d%�«      ‚|}d|i|¥|¥S c c}w c c}}w )'NÚattention_maskr   Ú
num_framesr,   z0num_frames must be used only when stride is None¾   r_   r^   Úinput_featuresÚinput_valueszhSeq2Seq speech recognition model requires either a `input_features` or `input_values` key, but only has r}   Fr^   r~   TÚreturn_token_timestampsÚreturn_segmentsr|   Úmain_input_namer0   ÚsegmentsrF   Útoken_timestamps)ÚtokensrÑ   rÒ   r   ÚresultÚ
lang_to_idÚlang_id>   rf   re   re   Úlogitséÿÿÿÿ©Údimr   rd   zUnsupported model type ú.© )rƒ   r…   ri   Úkeysr„   r|   Úboolr†   rY   rÏ   Úgenerater©   Úcatr    r´   r¤   ÚsetrÔ   rl   r?   ÚtensorrÖ   Úargmaxr’   Útupler"   rF   )ro   Úmodel_inputsr}   r{   rw   rÈ   r   rÉ   r,   r0   rÏ   rÒ   ÚoutÚsegment_listÚsegmentrÑ   rÐ   rÓ   Úfull_seqÚ
gen_configÚlang_idsÚtoken_idÚoutputsrÖ   r   r¿   s                             r!   Ú_forwardz+AutomaticSpeechRecognitionPipeline._forwardã  sÌ  € Ø%×)Ñ)Ð*:¸DÓAˆØ×!Ñ! (¨DÓ1ˆØ!×%Ñ% l°DÓ9ˆ
Ø×"Ñ" 9Ó-ˆàÐ *Ð"8ÜÐOÓPÐPà�9‰9Ð6Ò6ð   <Ñ/Ø%×)Ñ)Ð*:Ó;‘Ø <Ñ/Ø%×)Ñ)¨.Ó9‘ä ðLØLX×L]ÑL]ÓL_ÐK`ðbóð ð !2Ò p´W¸T×=SÑ=SÐUhÐjoÓ5pÐÙ  T§Y¡YÐ2CÒ%CÜ7;Ð<MÓ7N�Ð 3Ñ4Ø$¨Ò.ØAE�OÐ$=Ñ>Ø9=�OÐ$5Ñ6ð #¨/Ñ9Ø7;×7MÑ7M�Ð 3Ñ4ä<CÀDÇJÁJÐPaÔ<b˜dŸj™j×8Ò8ÐhpˆOà Ø  .ðð "ðˆOñ  4§9¡9Ð0AÒ#AØ59�Ð 1Ñ2à(�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Ü˜F¤DÔ)¨k¸VÑ.CØ ¨Ñ!4Ð5‘à Ð(�Ø�y‰yÐ-Ó-ØÐ%Ø$*�C˜‘MÚ"¤z°&¼$Õ'?ÀJÐRXÒDXð  & jÑ1�HÚ H¨Q£KØ!)¨!¡¨Q¡°Ñ!9˜Ü:DÀVÌTÔ:R 6¨+Ò#6ÐX^˜Ø%4×%8Ñ%8Ð9LÈd×NdÑNdÓ%e˜
Ü" :¨|Õ<Ü'*¨:×+@Ñ+@×+GÑ+GÓ+IÓ'J˜HØ,4¯O©OÓ,=ò * Ø#+¨xÒ#7Ü5:·\±\À8À*Ó5M C¨	¡NÚ$)ò*ð
 �Y‰YÐ0Ñ0à—
‘
×*Ñ*¨L×,<Ñ,<¸T¿Z¹Z×=WÑ=WÓ,XØ  .ðˆFð !�d—j‘jÑ* 6Ñ*ˆGØ—^‘^ˆFà�y‰y˜MÒ)Ø Ð(‘à §¡°2 Ó!6Ð7�ØÐ!ð ˜DŸN™NÑ*�Ü˜f¤eÔ,Ü$2°F°8¸UÓ$CÀAÑ$F�C˜’Mä$2°6¸5Ó$A�C˜’MØ�Y‰Y˜%Òà—
‘
×*Ñ*¨L×,<Ñ,<¸T¿Z¹Z×=WÑ=WÓ,XðˆFð   <Ñ/Ø+7×+;Ñ+;Ð<LÓ+M�Ð'Ñ(Ø)�d—j‘j×)Ñ)Ñ3¨FÑ3ˆGØ˜W×.Ñ.Ð/‰CäÐ6°t·y±y°kÀÐCÓDÐDð ˆØ˜7Ð3 cÐ3¨UÐ3Ð3ùò{ #\ùó(s   ÆQ%Æ6Q Ç	Q%Ñ Q%rz   c                 óX	  — i }g }| j                   dk(  rdnd}d }|D ]¾  }	|	|   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                  «      }
�nX| j                   dk(  �r | j                  j                  | j                  j                  j                   z  }| j                  j"                  }|D ]'  }d|v sŒ|d   \  }}}||z  }||z  }||z  }|||f|d<   Œ) |r‚|D ]}  }d|v sŒ|d   }|j%                  «       d	k(  r|j'                  d	«      }|j'                  d	«      j                  |d   j                  ¬
«      }t        j(                  ||d   gd¬«      |d<   Œ | j                  j+                  ||||¬«      \  }}n(t-        j.                  |d¬«      }
|
j1                  d	«      }
| j                   dk(  rX|€i } | j2                  j4                  
fi |¤Ž}|d	   d	   }|rÙ|d	   d   }g }|D ]  \  }\  }}|j                  |||dœ«       Œ n¬| j                   dk7  r�| j                   dk7  }| j                   dk(  rddini } | j                  j6                  
fd|i|¤Ž}|rX | j                  j6                  |
f|ddœ|¤Žd   }|dk(  r0| j                  j9                  || j                  j:                  «      }|rƒ| j                   dvrug } | j<                  }!D ]]  }"|"d   |!z  }#|#| j                  j"                  z  }#|"d   |!z  }$|$| j                  j"                  z  }$| j                  |"|   |#|$fdœ«       Œ_ | |d<   t?        t@        «      }%|D ]š  }|jC                  dd «       |jC                  dd «       |jC                  d d «       |jC                  dd «       |jC                  d!d «       |jC                  dd «       |jE                  «       D ]  \  }&}'|%|&   j                  |'«       Œ Œœ d"i|¥|%¥S )#Nre   rÖ   rÒ   r   >   rf   re   r_   r^   rÕ   r   r*   r×   rØ   )r}   r{   Útime_precisionr   rš   r   )r~   Ústart_offsetÚ
end_offsetrf   rd   Úgroup_tokensFÚskip_special_tokensT)ró   Úoutput_char_offsetsÚchar_offsetsr~   rÊ   rð   rñ   )ÚtextÚ	timestampÚchunksr,   rÑ   rö   )#ri   r+   r©   Úbfloat16Úfloat16r/   Úfloat32r¬   r¤   r   rR   rG   r1   Úchunk_lengthrY   rg   Úmax_source_positionsr'   rÙ   Ú	unsqueezerß   Ú_decode_asrrB   ÚconcatenateÚsqueezerZ   Údecode_beamsÚdecodeÚ_get_word_offsetsÚreplace_word_delimiter_charr’   r   Úlistrƒ   Úitems)(ro   Úmodel_outputsrz   r}   r{   ÚoptionalÚfinal_itemsÚkeyr   rì   r  Útotal_nr   r   Úright_nrï   r'   Úoutputr2   r3   r4   rÕ   Ú
lang_tokenrö   ÚbeamsÚchunk_offsetÚoffsetsr~   rð   rñ   ró   Údecode_kwargsrø   r‘   rÅ   ÚstartÚstopr¿   ÚkÚvs(                                           r!   Úpostprocessz.AutomaticSpeechRecognitionPipeline.postprocessX  sÿ  € ð ˆàˆØŸ)™) }Ò4‰h¸(ˆØˆØ$ò 	&ˆGØ�s‰|×!Ñ!¤e§n¡n´e·m±mÐ%DÑDØ ™Ÿ™¬¯©Ó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ñ Ø+ò ]�FØ  FÒ*Ø"(¨Ñ"3˜Ø"Ÿ;™;›=¨AÒ-Ø&-×&7Ñ&7¸Ó&:˜GØ%,×%6Ñ%6°qÓ%9×%<Ñ%<À6È(ÑCS×CYÑCYÐ%<Ó%Z˜
Ü+0¯9©9°jÀ&ÈÑBRÐ5SÐY[Ô+\˜˜xÒ(ð]ð "Ÿ^™^×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Ðð 8<·y±yÀEÒ7I˜^¨UÑ3ÈrˆMØ(�4—>‘>×(Ñ(¨ÑiÐDWÐiÐ[hÑiˆDÙ Ø/˜$Ÿ.™.×/Ñ/ØðØ/BÐX\ñØ`mñà ñ"�ð %¨Ò.Ø"Ÿn™n×>Ñ>¸wÈÏÉ×HrÑHrÓs�Gá §¡Ð2PÑ!PØˆFØ—~‘~ˆHØò ]�Ø˜^Ñ,¨xÑ7�Ø˜×/Ñ/×=Ñ=Ñ=�à˜LÑ)¨HÑ4�Ø˜×.Ñ.×<Ñ<Ñ<�à—‘ tÐ,=Ñ'>ÈeÐUYÈ]Ñ[Õ\ð]ð "(ˆH�XÑäœDÓ!ˆØ#ò 	#ˆFØ�J‰J�x Ô&Ø�J‰J�x Ô&Ø�J‰J�y $Ô'Ø�J‰J�x Ô&Ø�J‰JÐ)¨4Ô0Ø�J‰J�y $Ô'ØŸ™›ò #‘��1Ø�a‘—‘ Õ"ñ#ð	#ð ˜Ð2 Ð2¨EÐ2Ð2r#   )NNNN)NNNNNN)r   N)FN)NNN)rk   Ú
__module__Ú__qualname__Ú__doc__Ú_pipeline_calls_generateÚ_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   Ú_default_generation_configr   r¡   r	   r   rn   rB   r¸   r¨   r´   r   r  rs   rŒ   Úpropertyr’   rÆ   rí   r  Ú__classcell__)rj   s   @r!   rT   rT   p   sP  ø„ ñ'ðR  $ÐØ€OØ!ÐØ"ÐØ€Oá!1ØØô"Ðð LPØ04Ø=AØ48ñWà ðWð !Ð!;¸SÐ!@ÑAÀDÑHðWð '¨Ñ-ð	Wð
 Ð-¨sÐ2Ñ3°dÑ:ðWð �c˜>Ð)Ñ*¨TÑ1õWð292˜rŸz™z¨EÑ1°CÑ7¸$Ñ>ð 92È#ð 92ÐRVÐW[Ð\_ÐadÐ\dÑWeÑRfõ 92ðz ØØØØØóPEðd ñó ðóH:óTs4ðl jnñn3Ø-1°D©[÷n3r#   rT   )N)&Úcollectionsr   Útypingr   r   r   r£   r¬   rB   Ú
generationr   Útokenization_pythonr	   Úutilsr
   r   r   r   Úaudio_utilsr   Úbaser   Úpyctcdecoder   Ú!feature_extraction_sequence_utilsr   Úmodeling_utilsr   Ú
get_loggerrk   r€   r©   Úmodels.auto.modeling_autor   r"   r=   rR   rT   rÛ   r#   r!   ú<module>r0     sq   ðõ $ß ,Ñ ,ã Û å )Ý 5ß aÓ aÝ $Ý ñ Ý0åLÝ0à	ˆ×	Ñ	˜HÓ	%€áÔÛåTòó(ò4ô2V	3¨õ V	3r#   