


import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin




class 							lowerCamelCase   (  _UpperCamelCase ):
	_lowerCAmelCase     :		Tuple										=						'''MCTCTFeatureExtractor'''
	_lowerCAmelCase     :		Optional[Any]										=						'''AutoTokenizer'''


	def __init__(    self				,     lowercase__				,     lowercase__):
							super().__init__(lowercase__				,     lowercase__)
							__UpperCAmelCase			:							Dict	    =	self.feature_extractor
							__UpperCAmelCase			:							int	    =	False


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

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

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


	def  A(    self				,     *lowercase__				,     **lowercase__):
							return self.tokenizer.batch_decode(*lowercase__				,     **lowercase__)


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

							__UpperCAmelCase			:							Optional[int]	    =	kwargs.pop('''input_features'''				,     lowercase__)
							__UpperCAmelCase			:							List[str]	    =	kwargs.pop('''labels'''				,     lowercase__)
							if len(lowercase__) > 0:
													__UpperCAmelCase			:							Any	    =	args[0]
													__UpperCAmelCase			:							Optional[int]	    =	args[1:]

							if input_features is not None:
													__UpperCAmelCase			:							Optional[Any]	    =	self.feature_extractor.pad(lowercase__				,     *lowercase__				,     **lowercase__)
							if labels is not None:
													__UpperCAmelCase			:							List[Any]	    =	self.tokenizer.pad(lowercase__				,     **lowercase__)

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


	def  A(    self				,     *lowercase__				,     **lowercase__):
							return self.tokenizer.decode(*lowercase__				,     **lowercase__)


	@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.''')
							__UpperCAmelCase			:							Optional[int]	    =	True
							__UpperCAmelCase			:							List[str]	    =	self.tokenizer
							yield
							__UpperCAmelCase			:							Optional[Any]	    =	self.feature_extractor
							__UpperCAmelCase			:							Union[str, Any]	    =	False





import inspect
import os
import sys
import unittest

import accelerate
from accelerate.test_utils import execute_subprocess_async, require_tpu




class 							lowerCamelCase   (  unittest.TestCase ):


	def  A(    self):
							__UpperCAmelCase			:							List[Any]	    =	inspect.getfile(accelerate.test_utils)
							__UpperCAmelCase			:							Dict	    =	os.path.sep.join(mod_file.split(os.path.sep)[:-1] + ['''scripts''', '''test_script.py'''])
							__UpperCAmelCase			:							Union[str, Any]	    =	os.path.sep.join(inspect.getfile(self.__class__).split(os.path.sep)[:-1])


	@require_tpu
	def  A(    self):
							__UpperCAmelCase			:							Dict	    =	F"\n            {self.test_dir}/xla_spawn.py\n            --num_cores 8\n            {self.test_file_path}\n        ".split()
							__UpperCAmelCase			:							Union[str, Any]	    =	[sys.executable] + distributed_args
							execute_subprocess_async(lowercase__				,     env=os.environ.copy())

