






'''simple docstring'''



import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer
class 				__SCREAMING_SNAKE_CASE							(				_lowerCAmelCase  ):
      __a	       ="Wav2Vec2FeatureExtractor"
      __a	       ="AutoTokenizer"




      def __init__(	self			, lowerCamelCase			, lowerCamelCase   )				->List[str]:



         '''simple docstring'''
         super().__init__(lowerCamelCase			, lowerCamelCase   )
         __a					  =     self.feature_extractor
         __a					  =     False




      @classmethod
      def 			__UpperCamelCase				(	cls			, lowerCamelCase			, **lowerCamelCase   )				->Any:



         '''simple docstring'''
         try:
            return super().from_pretrained(lowerCamelCase			, **lowerCamelCase   )
         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: '			, lowerCamelCase			, )

            __a					  =     WavaVecaFeatureExtractor.from_pretrained(lowerCamelCase			, **lowerCamelCase   )
            __a					  =     WavaVecaCTCTokenizer.from_pretrained(lowerCamelCase			, **lowerCamelCase   )

            return cls(feature_extractor=lowerCamelCase			, tokenizer=lowerCamelCase   )




      def __call__(	self			, *lowerCamelCase			, **lowerCamelCase   )				->Optional[Any]:



         '''simple docstring'''
         # For backward compatibility
         if self._in_target_context_manager:
            return self.current_processor(*lowerCamelCase			, **lowerCamelCase   )

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

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




      def 			__UpperCamelCase				(	self			, *lowerCamelCase			, **lowerCamelCase   )				->Tuple:



         '''simple docstring'''
         # For backward compatibility
         if self._in_target_context_manager:
            return self.current_processor.pad(*lowerCamelCase			, **lowerCamelCase   )

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

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

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




      def 			__UpperCamelCase				(	self			, *lowerCamelCase			, **lowerCamelCase   )				->Optional[int]:



         '''simple docstring'''
         return self.tokenizer.batch_decode(*lowerCamelCase			, **lowerCamelCase   )




      def 			__UpperCamelCase				(	self			, *lowerCamelCase			, **lowerCamelCase   )				->int:



         '''simple docstring'''
         return self.tokenizer.decode(*lowerCamelCase			, **lowerCamelCase   )






      @contextmanager
      def 			__UpperCamelCase				(	self   )				->Optional[Any]:



         '''simple docstring'''
         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					  =     True
         __a					  =     self.tokenizer
         yield
         __a					  =     self.feature_extractor
         __a					  =     False







'''simple docstring'''



__UpperCamelCase   :							List[Any]         =   """ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"""



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						bytes     )	->      bytes:

   """simple docstring"""
   # Make sure the supplied data is a bytes-like object
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      __a					  =     f"""a bytes-like object is required, not '{data.__class__.__name__}'"""
      raise TypeError(SCREAMING_SNAKE_CASE__     )

   __a					  =     ''.join(bin(SCREAMING_SNAKE_CASE__     )[2:].zfill(8     ) for byte in data     )

   __a					  =     len(SCREAMING_SNAKE_CASE__     ) % 6 != 0

   if padding_needed:
      # The padding that will be added later
      __a					  =     b'=' * ((6 - len(SCREAMING_SNAKE_CASE__     ) % 6) // 2)

      # Append binary_stream with arbitrary binary digits (0's by default) to make its
      # length a multiple of 6.
      binary_stream += "0" * (6 - len(SCREAMING_SNAKE_CASE__     ) % 6)
   else:
      __a					  =     b''

   # Encode every 6 binary digits to their corresponding Base64 character
   return (
       "".join(
           B64_CHARSET[int(binary_stream[index : index + 6],       2     )]
           for index in range(0,       len(SCREAMING_SNAKE_CASE__     ),       6     )     ).encode()
       + padding
   )



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						str     )	->      bytes:

   """simple docstring"""
   # Make sure encoded_data is either a string or a bytes-like object
   if not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ) and not isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      __a					  =     (
          'argument should be a bytes-like object or ASCII string, '
          f"""not '{encoded_data.__class__.__name__}'"""
      )
      raise TypeError(SCREAMING_SNAKE_CASE__     )

   # In case encoded_data is a bytes-like object, make sure it contains only
   # ASCII characters so we convert it to a string object
   if isinstance(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__     ):
      try:
         __a					  =     encoded_data.decode('utf-8'     )
      except UnicodeDecodeError:
         raise ValueError('base64 encoded data should only contain ASCII characters'     )

   __a					  =     encoded_data.count('='     )

   # Check if the encoded string contains non base64 characters
   if padding:
      assert all(
          char in B64_CHARSET for char in encoded_data[:-padding]     ), "Invalid base64 character(s) found."
   else:
      assert all(
          char in B64_CHARSET for char in encoded_data     ), "Invalid base64 character(s) found."

   # Check the padding
   assert len(SCREAMING_SNAKE_CASE__     ) % 4 == 0 and padding < 3, "Incorrect padding"

   if padding:
      # Remove padding if there is one
      __a					  =     encoded_data[:-padding]

      __a					  =     ''.join(
          bin(B64_CHARSET.index(SCREAMING_SNAKE_CASE__     )     )[2:].zfill(6     ) for char in encoded_data     )[: -padding * 2]
   else:
      __a					  =     ''.join(
          bin(B64_CHARSET.index(SCREAMING_SNAKE_CASE__     )     )[2:].zfill(6     ) for char in encoded_data     )

   __a					  =     [
       int(binary_stream[index : index + 8],       2     )
       for index in range(0,       len(SCREAMING_SNAKE_CASE__     ),       8     )
   ]

   return bytes(SCREAMING_SNAKE_CASE__     )


if __name__ == "__main__":
 import doctest

 doctest.testmod()