

import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer






class      lowerCamelCase_      (	_lowercase	):
	_lowercase		:   Union[str, Any]     					=				'''Wav2Vec2FeatureExtractor'''
	_lowercase		:   Any     					=				'''AutoTokenizer'''




	def __init__(     self						:     List[str]					,      __A						:     List[Any]					,      __A						:     Optional[Any]							):
		super().__init__(__A					,      __A							)
		__A :			Optional[Any]		    =			self.feature_extractor
		__A :			str		    =			False




	@classmethod
	def        lowerCAmelCase_       (     cls						:     Dict					,      __A						:     List[str]					,      **__A						:     Optional[Any]							):
		try:
			return super().from_pretrained(__A					,      **__A							)
		except OSError:
			warnings.warn(
			    F"""Loading a tokenizer inside {cls.__name__} 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: """					,      __A					,      )

			__A :			Any		    =			WavaVecaFeatureExtractor.from_pretrained(__A					,      **__A							)
			__A :			List[str]		    =			WavaVecaCTCTokenizer.from_pretrained(__A					,      **__A							)

			return cls(feature_extractor=__A					,      tokenizer=__A							)




	def __call__(     self						:     Optional[int]					,      *__A						:     Optional[Any]					,      **__A						:     List[str]							):
		# For backward compatibility
		if self._in_target_context_manager:
			return self.current_processor(*__A					,      **__A							)

		if "raw_speech" in kwargs:
			warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""							)
			__A :			Any		    =			kwargs.pop("""raw_speech"""							)
		else:
			__A :			List[str]		    =			kwargs.pop("""audio"""					,      __A							)
		__A :			int		    =			kwargs.pop("""sampling_rate"""					,      __A							)
		__A :			Tuple		    =			kwargs.pop("""text"""					,      __A							)
		if len(__A							) > 0:
			__A :			Union[str, Any]		    =			args[0]
			__A :			Optional[Any]		    =			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 :			Tuple		    =			self.feature_extractor(__A					,      *__A					,      sampling_rate=__A					,      **__A							)
		if text is not None:
			__A :			Any		    =			self.tokenizer(__A					,      **__A							)

		if text is None:
			return inputs
		elif audio is None:
			return encodings
		else:
			__A :			List[str]		    =			encodings["""input_ids"""]
			return inputs




	def        lowerCAmelCase_       (     self						:     List[str]					,      *__A						:     int					,      **__A						:     Tuple							):
		# For backward compatibility
		if self._in_target_context_manager:
			return self.current_processor.pad(*__A					,      **__A							)

		__A :			Any		    =			kwargs.pop("""input_features"""					,      __A							)
		__A :			Tuple		    =			kwargs.pop("""labels"""					,      __A							)
		if len(__A							) > 0:
			__A :			Any		    =			args[0]
			__A :			Union[str, Any]		    =			args[1:]

		if input_features is not None:
			__A :			str		    =			self.feature_extractor.pad(__A					,      *__A					,      **__A							)
		if labels is not None:
			__A :			Union[str, Any]		    =			self.tokenizer.pad(__A					,      **__A							)

		if labels is None:
			return input_features
		elif input_features is None:
			return labels
		else:
			__A :			Optional[Any]		    =			labels["""input_ids"""]
			return input_features




	def        lowerCAmelCase_       (     self						:     List[Any]					,      *__A						:     List[Any]					,      **__A						:     List[str]							):
		return self.tokenizer.batch_decode(*__A					,      **__A							)




	def        lowerCAmelCase_       (     self						:     Optional[Any]					,      *__A						:     Dict					,      **__A						:     Optional[int]							):
		return self.tokenizer.decode(*__A					,      **__A							)




	@contextmanager
	def        lowerCAmelCase_       (     self						:     str							):
		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 :			Dict		    =			True
		__A :			List[str]		    =			self.tokenizer
		yield
		__A :			Tuple		    =			self.feature_extractor
		__A :			int		    =			False












import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCamelCase 					=      logging.get_logger(__name__)




class 	UpperCamelCase_							(  UpperCamelCase__     ):
							lowerCamelCase_							     =       "encoder-decoder"
							lowerCamelCase_							     =       True


							def __init__(				self     :Optional[int]				,					**__A     :str		) -> int:



									"""simple docstring"""



									super().__init__(**__A		)
									assert (
									    "encoder" in kwargs and "decoder" in kwargs
									), "Config has to be initialized with encoder and decoder config"
									SCREAMING_SNAKE_CASE__								=   kwargs.pop("""encoder"""		)
									SCREAMING_SNAKE_CASE__								=   encoder_config.pop("""model_type"""		)
									SCREAMING_SNAKE_CASE__								=   kwargs.pop("""decoder"""		)
									SCREAMING_SNAKE_CASE__								=   decoder_config.pop("""model_type"""		)

									from ..auto.configuration_auto import AutoConfig

									SCREAMING_SNAKE_CASE__								=   AutoConfig.for_model(__A				,					**__A		)
									SCREAMING_SNAKE_CASE__								=   AutoConfig.for_model(__A				,					**__A		)
									SCREAMING_SNAKE_CASE__								=   True


							@classmethod
							def   _snake_case	(				cls     :str				,					__A     :PretrainedConfig				,					__A     :PretrainedConfig				,					**__A     :List[str]		) -> PretrainedConfig:



									"""simple docstring"""



									logger.info("""Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""		)
									SCREAMING_SNAKE_CASE__								=   True
									SCREAMING_SNAKE_CASE__								=   True

									return cls(encoder=encoder_config.to_dict()				,					decoder=decoder_config.to_dict()				,					**__A		)


							def   _snake_case	(				self     :str		) -> Union[str, Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   copy.deepcopy(self.__dict__		)
									SCREAMING_SNAKE_CASE__								=   self.encoder.to_dict()
									SCREAMING_SNAKE_CASE__								=   self.decoder.to_dict()
									SCREAMING_SNAKE_CASE__								=   self.__class__.model_type
									return output