U
    ,-e2                     @   s$   d Z ddlmZ G dd deZdS )z$
Speech processor class for Whisper
   )ProcessorMixinc                       sZ   e Zd ZdZdZdZ fddZddd	Zd
d Zdd Z	dd Z
dedddZ  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.
    ZWhisperFeatureExtractorZWhisperTokenizerc                    s    t  || | j| _d| _d S )NF)super__init__feature_extractorcurrent_processor_in_target_context_manager)selfr   	tokenizer	__class__ o/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/transformers/models/whisper/processing_whisper.pyr   (   s    zWhisperProcessor.__init__NTc                 C   s   | j j|||dS )N)tasklanguageno_timestamps)r
   get_decoder_prompt_ids)r	   r   r   r   r   r   r   r   -   s    z'WhisperProcessor.get_decoder_prompt_idsc                 O   s   | j r| j||S |dd}|dd}|dd}t|dkrV|d }|dd }|dkrn|dkrntd|dk	r| j|f|d|i|}|dk	r| j|f|}|dkr|S |dkr|S |d |d	< |S 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.Z	input_idslabels)r   r   poplen
ValueErrorr   r
   )r	   argskwargsr   r   r   inputs	encodingsr   r   r   __call__0   s(    zWhisperProcessor.__call__c                 O   s   | j j||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   r   r   r   r!   R   s    zWhisperProcessor.batch_decodec                 O   s   | j j||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"   r   r   r   r#   Y   s    zWhisperProcessor.decodenp)r   c                 C   s   | j j||dS )N)return_tensors)r
   get_prompt_ids)r	   r   r%   r   r   r   r&   `   s    zWhisperProcessor.get_prompt_ids)NNT)r$   )__name__
__module____qualname____doc__Zfeature_extractor_classZtokenizer_classr   r   r    r!   r#   strr&   __classcell__r   r   r   r   r      s   
"r   N)r*   Zprocessing_utilsr   r   r   r   r   r   <module>   s   