import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin





class      lowerCAmelCase						(					_a			):
     _SCREAMING_SNAKE_CASE     :     Tuple		="""MCTCTFeatureExtractor"""
     _SCREAMING_SNAKE_CASE     :     int		="""AutoTokenizer"""



     def __init__(					self				,      lowerCAmelCase__				,      lowerCAmelCase__       ):
            super().__init__(lowerCAmelCase__				,      lowerCAmelCase__       )
            _A=	self.feature_extractor
            _A=	False



     def __call__(					self				,      *lowerCAmelCase__				,      **lowerCAmelCase__       ):
            # For backward compatibility
            if self._in_target_context_manager:
                   return self.current_processor(*lowerCAmelCase__				,      **lowerCAmelCase__       )

            if "raw_speech" in kwargs:
                   warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'       )
                   _A=	kwargs.pop('raw_speech'       )
            else:
                   _A=	kwargs.pop('audio'				,      lowerCAmelCase__       )
            _A=	kwargs.pop('sampling_rate'				,      lowerCAmelCase__       )
            _A=	kwargs.pop('text'				,      lowerCAmelCase__       )
            if len(lowerCAmelCase__       ) > 0:
                   _A=	args[0]
                   _A=	args[1:]

            if audio is None and text is None:
                   raise ValueError('You need to specify either an `audio` or `text` input to process.'       )

            if audio is not None:
                   _A=	self.feature_extractor(lowerCAmelCase__				,      *lowerCAmelCase__				,      sampling_rate=lowerCAmelCase__				,      **lowerCAmelCase__       )
            if text is not None:
                   _A=	self.tokenizer(lowerCAmelCase__				,      **lowerCAmelCase__       )

            if text is None:
                   return inputs
            elif audio is None:
                   return encodings
            else:
                   _A=	encodings['input_ids']
                   return inputs



     def 			a__  (					self				,      *lowerCAmelCase__				,      **lowerCAmelCase__       ):
            return self.tokenizer.batch_decode(*lowerCAmelCase__				,      **lowerCAmelCase__       )



     def 			a__  (					self				,      *lowerCAmelCase__				,      **lowerCAmelCase__       ):
            # For backward compatibility
            if self._in_target_context_manager:
                   return self.current_processor.pad(*lowerCAmelCase__				,      **lowerCAmelCase__       )

            _A=	kwargs.pop('input_features'				,      lowerCAmelCase__       )
            _A=	kwargs.pop('labels'				,      lowerCAmelCase__       )
            if len(lowerCAmelCase__       ) > 0:
                   _A=	args[0]
                   _A=	args[1:]

            if input_features is not None:
                   _A=	self.feature_extractor.pad(lowerCAmelCase__				,      *lowerCAmelCase__				,      **lowerCAmelCase__       )
            if labels is not None:
                   _A=	self.tokenizer.pad(lowerCAmelCase__				,      **lowerCAmelCase__       )

            if labels is None:
                   return input_features
            elif input_features is None:
                   return labels
            else:
                   _A=	labels['input_ids']
                   return input_features



     def 			a__  (					self				,      *lowerCAmelCase__				,      **lowerCAmelCase__       ):
            return self.tokenizer.decode(*lowerCAmelCase__				,      **lowerCAmelCase__       )





     @contextmanager
     def 			a__  (					self       ):
            warnings.warn(
                '`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.'       )
            _A=	True
            _A=	self.tokenizer
            yield
            _A=	self.feature_extractor
            _A=	False
from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase_								=							logging.get_logger(__name__)

UpperCAmelCase_								=							{
    '''facebook/s2t-wav2vec2-large-en-de''': (
        '''https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'''
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}





class      lowerCAmelCase						(					_a			):
     _SCREAMING_SNAKE_CASE     :     Optional[Any]		="""speech_to_text_2"""
     _SCREAMING_SNAKE_CASE     :     str		=["""past_key_values"""]
     _SCREAMING_SNAKE_CASE     :     Tuple		={"""num_attention_heads""": """decoder_attention_heads""", """hidden_size""": """d_model"""}



     def __init__(					self				,      lowerCAmelCase__=10000				,      lowerCAmelCase__=6				,      lowerCAmelCase__=2048				,      lowerCAmelCase__=4				,      lowerCAmelCase__=0.0				,      lowerCAmelCase__=True				,      lowerCAmelCase__="relu"				,      lowerCAmelCase__=256				,      lowerCAmelCase__=0.1				,      lowerCAmelCase__=0.0				,      lowerCAmelCase__=0.0				,      lowerCAmelCase__=0.02				,      lowerCAmelCase__=2				,      lowerCAmelCase__=True				,      lowerCAmelCase__=1				,      lowerCAmelCase__=0				,      lowerCAmelCase__=2				,      lowerCAmelCase__=1024				,      **lowerCAmelCase__				,      ):
            _A=	vocab_size
            _A=	d_model
            _A=	decoder_ffn_dim
            _A=	decoder_layers
            _A=	decoder_attention_heads
            _A=	dropout
            _A=	attention_dropout
            _A=	activation_dropout
            _A=	activation_function
            _A=	init_std
            _A=	decoder_layerdrop
            _A=	use_cache
            _A=	decoder_layers
            _A=	scale_embedding  # scale factor will be sqrt(d_model) if True
            _A=	max_target_positions

            super().__init__(
                pad_token_id=lowerCAmelCase__				,      bos_token_id=lowerCAmelCase__				,      eos_token_id=lowerCAmelCase__				,      decoder_start_token_id=lowerCAmelCase__				,      **lowerCAmelCase__				,      )