

import warnings
from contextlib import contextmanager

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



class   lowercase_   (  __lowercase					):
						UpperCamelCase_      :		Tuple										=    "Wav2Vec2FeatureExtractor"
						UpperCamelCase_      :		List[Any]										=    "AutoTokenizer"



						def __init__(      self				:    Union[str, Any]      , A__				:    Dict      , A__				:    List[Any]		)   ->					Optional[int]:
								super().__init__(A__      , A__		)
								_snake_case						=							self.feature_extractor
								_snake_case						=							False



						@classmethod
						def 						UpperCamelCase_		(      cls				:    Dict      , A__				:    Union[str, Any]      , **A__				:    Dict		)   ->					Tuple:
								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__      , )

										_snake_case						=							WavaVecaFeatureExtractor.from_pretrained(A__      , **A__		)
										_snake_case						=							WavaVecaCTCTokenizer.from_pretrained(A__      , **A__		)

										return cls(feature_extractor=A__      , tokenizer=A__		)



						def __call__(      self				:    Dict      , *A__				:    Optional[Any]      , **A__				:    List[str]		)   ->					Tuple:
								# 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.'''		)
										_snake_case						=							kwargs.pop('''raw_speech'''		)
								else:
										_snake_case						=							kwargs.pop('''audio'''      , A__		)
								_snake_case						=							kwargs.pop('''sampling_rate'''      , A__		)
								_snake_case						=							kwargs.pop('''text'''      , A__		)
								if len(A__		) > 0:
										_snake_case						=							args[0]
										_snake_case						=							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:
										_snake_case						=							self.feature_extractor(A__      , *A__      , sampling_rate=A__      , **A__		)
								if text is not None:
										_snake_case						=							self.tokenizer(A__      , **A__		)

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



						def 						UpperCamelCase_		(      self				:    Optional[int]      , *A__				:    Optional[Any]      , **A__				:    Tuple		)   ->					Optional[int]:
								# For backward compatibility
								if self._in_target_context_manager:
										return self.current_processor.pad(*A__      , **A__		)

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

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

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



						def 						UpperCamelCase_		(      self				:    List[Any]      , *A__				:    List[str]      , **A__				:    Dict		)   ->					Any:
								return self.tokenizer.batch_decode(*A__      , **A__		)



						def 						UpperCamelCase_		(      self				:    Optional[Any]      , *A__				:    Any      , **A__				:    Tuple		)   ->					str:
								return self.tokenizer.decode(*A__      , **A__		)







						@contextmanager
						def 						UpperCamelCase_		(      self				:    Union[str, Any]		)   ->					int:
								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.'''		)
								_snake_case						=							True
								_snake_case						=							self.tokenizer
								yield
								_snake_case						=							self.feature_extractor
								_snake_case						=							False




from ..utils import DummyObject, requires_backends



class   lowercase_   (  metaclass=__lowercase					):
      UpperCamelCase_      :		Optional[int]										=    ["speech"]



      def __init__(      self				:    str      , *A__				:    List[str]      , **A__				:    Tuple		)   ->					Optional[Any]:
        requires_backends(self      , ['''speech''']		)



class   lowercase_   (  metaclass=__lowercase					):
      UpperCamelCase_      :		Optional[Any]										=    ["speech"]



      def __init__(      self				:    Dict      , *A__				:    int      , **A__				:    int		)   ->					Tuple:
        requires_backends(self      , ['''speech''']		)

