
    sg2                     *    d Z ddlmZ  G d de      Zy)z$
Speech processor class for Whisper
   )ProcessorMixinc                   R     e Zd ZdZdZdZ fdZddZd Zd Z	d Z
dd	efd
Z xZS )WhisperProcessoraz  
    Constructs a Whisper processor which wraps a Whisper feature extractor and a Whisper tokenizer into a single
    processor.

    [`WhisperProcessor`] offers all the functionalities of [`WhisperFeatureExtractor`] and [`WhisperTokenizer`]. See
    the [`~WhisperProcessor.__call__`] and [`~WhisperProcessor.decode`] for more information.

    Args:
        feature_extractor (`WhisperFeatureExtractor`):
            An instance of [`WhisperFeatureExtractor`]. The feature extractor is a required input.
        tokenizer (`WhisperTokenizer`):
            An instance of [`WhisperTokenizer`]. The tokenizer is a required input.
    WhisperFeatureExtractorWhisperTokenizerc                 V    t         |   ||       | j                  | _        d| _        y )NF)super__init__feature_extractorcurrent_processor_in_target_context_manager)selfr   	tokenizer	__class__s      a/var/www/html/venv/lib/python3.12/site-packages/transformers/models/whisper/processing_whisper.pyr
   zWhisperProcessor.__init__(   s)    *I6!%!7!7*/'    c                 >    | j                   j                  |||      S )N)tasklanguageno_timestamps)r   get_decoder_prompt_ids)r   r   r   r   s       r   r   z'WhisperProcessor.get_decoder_prompt_ids-   s    ~~44$an4oor   c                 z   | j                   r | j                  |i |S |j                  dd      }|j                  dd      }|j                  dd      }t        |      dkD  r
|d   }|dd }||t	        d      | | j
                  |g|d|i|}| | j                  |fi |}|S |S d   d	<   |S )
a
  
        Forwards the `audio` argument to WhisperFeatureExtractor's [`~WhisperFeatureExtractor.__call__`] and the `text`
        argument to [`~WhisperTokenizer.__call__`]. Please refer to the doctsring of the above two methods for more
        information.
        audioNsampling_ratetext       zAYou need to specify either an `audio` or `text` input to process.	input_idslabels)r   r   poplen
ValueErrorr   r   )r   argskwargsr   r   r   inputs	encodingss           r   __call__zWhisperProcessor.__call__0   s     **)4))4:6::

7D)

?D9zz&$'t9q=GE8D=T\`aa+T++E`D``Y_`F&t6v6I<M](5F8Mr   c                 :     | j                   j                  |i |S )z
        This method forwards all its arguments to WhisperTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r   batch_decoder   r#   r$   s      r   r)   zWhisperProcessor.batch_decodeR   s     
 +t~~**D;F;;r   c                 :     | j                   j                  |i |S )z
        This method forwards all its arguments to WhisperTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r   decoder*   s      r   r,   zWhisperProcessor.decodeY   s     
 %t~~$$d5f55r   r   c                 <    | j                   j                  ||      S )N)return_tensors)r   get_prompt_ids)r   r   r.   s      r   r/   zWhisperProcessor.get_prompt_ids`   s    ~~,,T.,QQr   )NNT)np)__name__
__module____qualname____doc__feature_extractor_classtokenizer_classr
   r   r'   r)   r,   strr/   __classcell__)r   s   @r   r   r      s>     8(O0
p D<6R3 Rr   r   N)r4   processing_utilsr   r    r   r   <module>r;      s    /KR~ KRr   