



import warnings
from contextlib import contextmanager

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




class 							lowerCAmelCase__  (	UpperCamelCase						):
     __A     :    Any           =						'Wav2Vec2FeatureExtractor'
     __A     :    Any           =						'AutoTokenizer'







     def __init__(       self      :     str			,		_A      :     Optional[int]			,		_A      :     Tuple):
           super().__init__(_A			,		_A)
           A__	:							Optional[Any]						    = self.feature_extractor
           A__	:							str						    = False







     @classmethod
     def  _lowercase			(       cls      :     Dict			,		_A      :     Any			,		**_A      :     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			,		)

                 A__	:							Dict						    = WavaVecaFeatureExtractor.from_pretrained(_A			,		**_A)
                 A__	:							List[str]						    = WavaVecaCTCTokenizer.from_pretrained(_A			,		**_A)

                 return cls(feature_extractor=_A			,		tokenizer=_A)







     def __call__(       self      :     List[Any]			,		*_A      :     List[Any]			,		**_A      :     List[Any]):
           # 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__	:							Optional[int]						    = kwargs.pop("raw_speech")
           else:
                 A__	:							List[Any]						    = kwargs.pop("audio"			,		_A)
           A__	:							List[Any]						    = kwargs.pop("sampling_rate"			,		_A)
           A__	:							List[str]						    = kwargs.pop("text"			,		_A)
           if len(_A) > 0:
                 A__	:							List[str]						    = args[0]
                 A__	:							Optional[int]						    = 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__	:							Any						    = 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  _lowercase			(       self      :     Tuple			,		*_A      :     List[Any]			,		**_A      :     str):
           # For backward compatibility
           if self._in_target_context_manager:
                 return self.current_processor.pad(*_A			,		**_A)

           A__	:							Dict						    = kwargs.pop("input_features"			,		_A)
           A__	:							Optional[Any]						    = kwargs.pop("labels"			,		_A)
           if len(_A) > 0:
                 A__	:							List[Any]						    = args[0]
                 A__	:							Any						    = args[1:]

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

           if labels is None:
                 return input_features
           elif input_features is None:
                 return labels
           else:
                 A__	:							List[Any]						    = labels["input_ids"]
                 return input_features







     def  _lowercase			(       self      :     int			,		*_A      :     Union[str, Any]			,		**_A      :     Tuple):
           return self.tokenizer.batch_decode(*_A			,		**_A)







     def  _lowercase			(       self      :     Optional[Any]			,		*_A      :     Union[str, Any]			,		**_A      :     Any):
           return self.tokenizer.decode(*_A			,		**_A)







     @contextmanager
     def  _lowercase			(       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__	:							int						    = True
           A__	:							Any						    = self.tokenizer
           yield
           A__	:							str						    = self.feature_extractor
           A__	:							Dict						    = False




from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset




class 							lowerCAmelCase__  (	UpperCamelCase						):







					def  _lowercase			(       self      :     List[Any]):
											return [
											    {"col_1": 3, "col_2": "a"},
											    {"col_1": 2, "col_2": "b"},
											    {"col_1": 1, "col_2": "c"},
											    {"col_1": 0, "col_2": "d"},
											]







					def  _lowercase			(       self      :     Tuple):
											A__	:							Any						    = {"col_1": [3, 2, 1, 0], "col_2": ["a", "b", "c", "d"]}
											return Dataset.from_dict(_A)







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							str						    = self._create_example_records()
											A__	:							Dict						    = Dataset.from_list(_A)
											self.assertListEqual(dset.column_names			,		["col_1", "col_2"])
											for i, r in enumerate(_A):
																	self.assertDictEqual(_A			,		example_records[i])







					def  _lowercase			(       self      :     List[str]):
											A__	:							List[str]						    = self._create_example_records()
											A__	:							Any						    = Dataset.from_list(_A)
											A__	:							Optional[int]						    = Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]})
											self.assertEqual(dset.info			,		dset_from_dict.info)







					def  _lowercase			(       self      :     Any):  # checks what happens with missing columns
											A__	:							Dict						    = [{"col_1": 1}, {"col_2": "x"}]
											A__	:							Any						    = Dataset.from_list(_A)
											self.assertDictEqual(dset[0]			,		{"col_1": 1})
											self.assertDictEqual(dset[1]			,		{"col_1": None})  # NB: first record is used for columns







					def  _lowercase			(       self      :     str):  # checks if the type can be inferred from the second record
											A__	:							Dict						    = [{"col_1": []}, {"col_1": [1, 2]}]
											A__	:							Dict						    = Dataset.from_list(_A)
											self.assertEqual(dset.info.features["col_1"]			,		Sequence(Value("int64")))







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							Dict						    = Dataset.from_list([])
											self.assertEqual(len(_A)			,		0)
											self.assertListEqual(dset.column_names			,		[])