
from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__snake_case								=  logging.get_logger(__name__)


__snake_case								=  TypeVar("""DatasetType""", Dataset, IterableDataset)






def 							_lowercase							(     UpperCamelCase_	,	UpperCamelCase_ = None	,	UpperCamelCase_ = None	,	UpperCamelCase_ = None	,	UpperCamelCase_ = None	,	UpperCamelCase_ = "first_exhausted"	,	)		->		DatasetType:
					'''simple docstring'''


					from .arrow_dataset import Dataset
					from .iterable_dataset import IterableDataset

					if not datasets:
										raise ValueError('Unable to interleave an empty list of datasets.'		)
					for i, dataset in enumerate(UpperCamelCase_		):
										if not isinstance(UpperCamelCase_	,	(Dataset, IterableDataset)		):
															if isinstance(UpperCamelCase_	,	(DatasetDict, IterableDatasetDict)		):
																				if not dataset:
																									raise ValueError(
																									    F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '
																									    'is an empty dataset dictionary.'		)
																				raise ValueError(
																				    F'Dataset at position {i} has at least one split: {list(UpperCamelCase_		)}\n'
																				    F'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(UpperCamelCase_		)		)}\']'		)
															raise ValueError(
															    F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(UpperCamelCase_		).__name__}.'		)
										if i == 0:
															SCREAMING_SNAKE_CASE__						, SCREAMING_SNAKE_CASE__													= (
															    (Dataset, IterableDataset) if isinstance(UpperCamelCase_	,	UpperCamelCase_		) else (IterableDataset, Dataset)
															)
										elif not isinstance(UpperCamelCase_	,	UpperCamelCase_		):
															raise ValueError(
															    F'Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'		)
					if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
										raise ValueError(F'{stopping_strategy} is not supported. Please enter a valid stopping_strategy.'		)
					if dataset_type is Dataset:
										return _interleave_map_style_datasets(
										    UpperCamelCase_	,	UpperCamelCase_	,	UpperCamelCase_	,	info=UpperCamelCase_	,	split=UpperCamelCase_	,	stopping_strategy=UpperCamelCase_		)
					else:
										return _interleave_iterable_datasets(
										    UpperCamelCase_	,	UpperCamelCase_	,	UpperCamelCase_	,	info=UpperCamelCase_	,	split=UpperCamelCase_	,	stopping_strategy=UpperCamelCase_		)






def 							_lowercase							(     UpperCamelCase_	,	UpperCamelCase_ = None	,	UpperCamelCase_ = None	,	UpperCamelCase_ = 0	,	)		->		DatasetType:
					'''simple docstring'''


					if not dsets:
										raise ValueError('Unable to concatenate an empty list of datasets.'		)
					for i, dataset in enumerate(UpperCamelCase_		):
										if not isinstance(UpperCamelCase_	,	(Dataset, IterableDataset)		):
															if isinstance(UpperCamelCase_	,	(DatasetDict, IterableDatasetDict)		):
																				if not dataset:
																									raise ValueError(
																									    F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} '
																									    'is an empty dataset dictionary.'		)
																				raise ValueError(
																				    F'Dataset at position {i} has at least one split: {list(UpperCamelCase_		)}\n'
																				    F'Please pick one to interleave with the other datasets, for example: dataset[\'{next(iter(UpperCamelCase_		)		)}\']'		)
															raise ValueError(
															    F'Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(UpperCamelCase_		).__name__}.'		)
										if i == 0:
															SCREAMING_SNAKE_CASE__						, SCREAMING_SNAKE_CASE__													= (
															    (Dataset, IterableDataset) if isinstance(UpperCamelCase_	,	UpperCamelCase_		) else (IterableDataset, Dataset)
															)
										elif not isinstance(UpperCamelCase_	,	UpperCamelCase_		):
															raise ValueError(
															    F'Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects.'		)
					if dataset_type is Dataset:
										return _concatenate_map_style_datasets(UpperCamelCase_	,	info=UpperCamelCase_	,	split=UpperCamelCase_	,	axis=UpperCamelCase_		)
					else:
										return _concatenate_iterable_datasets(UpperCamelCase_	,	info=UpperCamelCase_	,	split=UpperCamelCase_	,	axis=UpperCamelCase_		)







import warnings
from contextlib import contextmanager

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




class 						lowercase__  (						_UpperCAmelCase  ):
	A__    :   Union[str, Any]				       ="""Wav2Vec2FeatureExtractor"""
	A__    :   Any				       ="""AutoTokenizer"""
	def __init__(			self							:   List[Any]       ,   UpperCAmelCase_							:   List[str]       ,   UpperCAmelCase_							:   str							):
						super().__init__(UpperCAmelCase_       ,   UpperCAmelCase_							)
						SCREAMING_SNAKE_CASE__													= self.feature_extractor
						SCREAMING_SNAKE_CASE__													= False
	@classmethod
	def      A_				(			cls							:   Union[str, Any]       ,   UpperCAmelCase_							:   Any       ,   **UpperCAmelCase_							:   Optional[Any]							):
						try:
											return super().from_pretrained(UpperCAmelCase_       ,   **UpperCAmelCase_							)
						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: '       ,   UpperCAmelCase_       ,   )

											SCREAMING_SNAKE_CASE__													= WavaVecaFeatureExtractor.from_pretrained(UpperCAmelCase_       ,   **UpperCAmelCase_							)
											SCREAMING_SNAKE_CASE__													= WavaVecaCTCTokenizer.from_pretrained(UpperCAmelCase_       ,   **UpperCAmelCase_							)

											return cls(feature_extractor=UpperCAmelCase_       ,   tokenizer=UpperCAmelCase_							)
	def __call__(			self							:   Any       ,   *UpperCAmelCase_							:   Dict       ,   **UpperCAmelCase_							:   Any							):
						# For backward compatibility
						if self._in_target_context_manager:
											return self.current_processor(*UpperCAmelCase_       ,   **UpperCAmelCase_							)

						if "raw_speech" in kwargs:
											warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'							)
											SCREAMING_SNAKE_CASE__													= kwargs.pop('raw_speech'							)
						else:
											SCREAMING_SNAKE_CASE__													= kwargs.pop('audio'       ,   UpperCAmelCase_							)
						SCREAMING_SNAKE_CASE__													= kwargs.pop('sampling_rate'       ,   UpperCAmelCase_							)
						SCREAMING_SNAKE_CASE__													= kwargs.pop('text'       ,   UpperCAmelCase_							)
						if len(UpperCAmelCase_							) > 0:
											SCREAMING_SNAKE_CASE__													= args[0]
											SCREAMING_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:
											SCREAMING_SNAKE_CASE__													= self.feature_extractor(UpperCAmelCase_       ,   *UpperCAmelCase_       ,   sampling_rate=UpperCAmelCase_       ,   **UpperCAmelCase_							)
						if text is not None:
											SCREAMING_SNAKE_CASE__													= self.tokenizer(UpperCAmelCase_       ,   **UpperCAmelCase_							)

						if text is None:
											return inputs
						elif audio is None:
											return encodings
						else:
											SCREAMING_SNAKE_CASE__													= encodings['input_ids']
											return inputs
	def      A_				(			self							:   List[str]       ,   *UpperCAmelCase_							:   List[Any]       ,   **UpperCAmelCase_							:   Optional[int]							):
						# For backward compatibility
						if self._in_target_context_manager:
											return self.current_processor.pad(*UpperCAmelCase_       ,   **UpperCAmelCase_							)

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

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

						if labels is None:
											return input_features
						elif input_features is None:
											return labels
						else:
											SCREAMING_SNAKE_CASE__													= labels['input_ids']
											return input_features
	def      A_				(			self							:   List[Any]       ,   *UpperCAmelCase_							:   List[str]       ,   **UpperCAmelCase_							:   List[str]							):
						return self.tokenizer.batch_decode(*UpperCAmelCase_       ,   **UpperCAmelCase_							)
	def      A_				(			self							:   Tuple       ,   *UpperCAmelCase_							:   int       ,   **UpperCAmelCase_							:   List[str]							):
						return self.tokenizer.decode(*UpperCAmelCase_       ,   **UpperCAmelCase_							)





	@contextmanager
	def      A_				(			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.'							)
						SCREAMING_SNAKE_CASE__													= True
						SCREAMING_SNAKE_CASE__													= self.tokenizer
						yield
						SCREAMING_SNAKE_CASE__													= self.feature_extractor
						SCREAMING_SNAKE_CASE__													= False





