
    g                         d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZ ddlmZmZmZ dd	lmZ dd
lmZ  G d de	d          Z G d de
          ZdS )z%
Speech processor class for Wav2Vec2
    N)contextmanager)ListOptionalUnion   )ProcessingKwargsProcessorMixinUnpack)
AudioInputPreTokenizedInput	TextInput   )Wav2Vec2FeatureExtractor)Wav2Vec2CTCTokenizerc                       e Zd Zi ZdS )Wav2Vec2ProcessorKwargsN)__name__
__module____qualname__	_defaults     l/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/wav2vec2/processing_wav2vec2.pyr   r      s        IIIr   r   F)totalc            
            e Zd ZdZdZdZ fdZe fd            Z	 	 	 	 dde	de
eeee         eef                  d	ee         fd
Zd Zd Zd Zed             Z xZS )Wav2Vec2Processora  
    Constructs a Wav2Vec2 processor which wraps a Wav2Vec2 feature extractor and a Wav2Vec2 CTC tokenizer into a single
    processor.

    [`Wav2Vec2Processor`] offers all the functionalities of [`Wav2Vec2FeatureExtractor`] and [`PreTrainedTokenizer`].
    See the docstring of [`~Wav2Vec2Processor.__call__`] and [`~Wav2Vec2Processor.decode`] for more information.

    Args:
        feature_extractor (`Wav2Vec2FeatureExtractor`):
            An instance of [`Wav2Vec2FeatureExtractor`]. The feature extractor is a required input.
        tokenizer ([`PreTrainedTokenizer`]):
            An instance of [`PreTrainedTokenizer`]. The tokenizer is a required input.
    r   AutoTokenizerc                 r    t                                          ||           | j        | _        d| _        d S )NF)super__init__feature_extractorcurrent_processor_in_target_context_manager)selfr!   	tokenizer	__class__s      r   r    zWav2Vec2Processor.__init__3   s7    *I666!%!7*/'''r   c                    	  t                      j        |fi |S # t          t          f$ rW t	          j        d| j         dt                     t          j        |fi |}t          j        |fi |} | ||          cY S w xY w)NzLoading a tokenizer inside a   from a config that does not include a `tokenizer_class` attribute is deprecated and will be removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'` attribute to either your `config.json` or `tokenizer_config.json` file to suppress this warning: )r!   r%   )
r   from_pretrainedOSError
ValueErrorwarningswarnr   FutureWarningr   r   )clspretrained_model_name_or_pathkwargsr!   r%   r&   s        r   r(   z!Wav2Vec2Processor.from_pretrained8   s    	Q*577*+HSSFSSS$ 	Q 	Q 	QM2cl 2 2 2
    !9 HIf q qjp q q,<=Zee^deeI3):iPPPPPP	Qs    A%BBNaudiotextr0   c                    d|v r)t          j        d           |                    d          }||t          d           | j        t
          fd| j        j        i|}| j        r$ | j	        |fi |d         |d         |d         S | | j
        |fi |d         }| | j        |fi |d         }||S ||S |d	         |d
<   |S )a  
        When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
        [`~Wav2Vec2FeatureExtractor.__call__`] and returns its output. If used in the context
        [`~Wav2Vec2Processor.as_target_processor`] this method forwards all its arguments to PreTrainedTokenizer's
        [`~PreTrainedTokenizer.__call__`]. Please refer to the docstring of the above two methods for more information.
        
raw_speechzLUsing `raw_speech` as a keyword argument is deprecated. Use `audio` instead.NzAYou need to specify either an `audio` or `text` input to process.tokenizer_init_kwargsaudio_kwargstext_kwargscommon_kwargs	input_idslabels)r+   r,   popr*   _merge_kwargsr   r%   init_kwargsr#   r"   r!   )	r$   r1   r2   imagesvideosr0   output_kwargsinputs	encodingss	            r   __call__zWav2Vec2Processor.__call__K   sG    6!!MhiiiJJ|,,E=T\`aaa**#
 
"&."<
 
 
 * 	)4) /  .  0	   +T+ESS]>5RSSF&tLL}]/KLLI<M](5F8Mr   c                 Z   | j         r | j        j        |i |S |                    dd          }|                    dd          }t	          |          dk    r|d         }|dd         }| | j        j        |g|R i |}| | j        j        |fi |}||S ||S |d         |d<   |S )a  
        When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
        [`~Wav2Vec2FeatureExtractor.pad`] and returns its output. If used in the context
        [`~Wav2Vec2Processor.as_target_processor`] this method forwards all its arguments to PreTrainedTokenizer's
        [`~PreTrainedTokenizer.pad`]. Please refer to the docstring of the above two methods for more information.
        input_featuresNr:   r   r   r9   )r#   r"   padr;   lenr!   r%   )r$   argsr0   rE   r:   s        r   rF   zWav2Vec2Processor.pad|   s     * 	?-4)-t>v>>>$4d;;Hd++t99q==!!WN8D%7T37XXXXQWXXN'T^'99&99F>!!#M'-k':N8$!!r   c                 &     | j         j        |i |S )z
        This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r%   batch_decoder$   rH   r0   s      r   rJ   zWav2Vec2Processor.batch_decode   s    
 +t~*D;F;;;r   c                 &     | j         j        |i |S )z
        This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer
        to the docstring of this method for more information.
        )r%   decoderK   s      r   rM   zWav2Vec2Processor.decode   s    
 %t~$d5f555r   c              #      K   t          j        d           d| _        | j        | _        dV  | j        | _        d| _        dS )z
        Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning
        Wav2Vec2.
        z`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your labels by using the argument `text` of the regular `__call__` method (either in the same call as your audio inputs, or in a separate call.TNF)r+   r,   r#   r%   r"   r!   )r$   s    r   as_target_processorz%Wav2Vec2Processor.as_target_processor   sW       	8	
 	
 	

 +/'!%!%!7*/'''r   )NNNN)r   r   r   __doc__feature_extractor_classtokenizer_classr    classmethodr(   r   r   r   strr   r   r   r
   r   rC   rF   rJ   rM   r   rO   __classcell__)r&   s   @r   r   r   !   s#         9%O0 0 0 0 0
 Q Q Q Q [Q( !NR/ // uS$s)Y8IIJK/ 01/ / / /b" " "<< < <6 6 6 0 0 ^0 0 0 0 0r   r   )rP   r+   
contextlibr   typingr   r   r   processing_utilsr   r	   r
   tokenization_utils_baser   r   r   feature_extraction_wav2vec2r   tokenization_wav2vec2r   r   r   r   r   r   <module>r\      s     % % % % % % ( ( ( ( ( ( ( ( ( ( H H H H H H H H H H O O O O O O O O O O A A A A A A 7 7 7 7 7 7    .e    V0 V0 V0 V0 V0 V0 V0 V0 V0 V0r   