o
    ZhS                     @   s*   d Z ddlmZ G dd deZdg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def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__ ]/var/www/auris/lib/python3.10/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|i |S |dd}|dd}|dd}t|dkr-|d }|dd }|du r9|du r9td|durK| j|g|R d|i|}|durX| j|fi |}|du r^|S |du rd|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 docstring 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   Zinputs	encodingsr   r   r   __call__0   s(   zWhisperProcessor.__call__c                 O      | 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   r   r   r   r!   R      zWhisperProcessor.batch_decodec                 O   r    )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   r#   zWhisperProcessor.decodenpr   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   __all__r   r   r   r   <module>   s   
N