


import warnings
from contextlib import contextmanager

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






class   __lowercase				(  __snake_case  ):
      UpperCamelCase								=       '''Wav2Vec2FeatureExtractor'''
      UpperCamelCase								=       '''AutoTokenizer'''





      def __init__(		self						:					int					,       __lowerCamelCase						:					List[str]					,       __lowerCamelCase						:					Optional[Any]       )    ->   List[Any]:






         """simple docstring"""







         super().__init__(__lowerCamelCase					,       __lowerCamelCase       )
         UpperCAmelCase							=     self.feature_extractor
         UpperCAmelCase							=     False





      @classmethod
      def        _lowercase				(		cls						:					List[str]					,       __lowerCamelCase						:					List[str]					,       **__lowerCamelCase						:					Dict       )    ->   int:






         """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					,       )

            UpperCAmelCase							=     WavaVecaFeatureExtractor.from_pretrained(__lowerCamelCase					,       **__lowerCamelCase       )
            UpperCAmelCase							=     WavaVecaCTCTokenizer.from_pretrained(__lowerCamelCase					,       **__lowerCamelCase       )

            return cls(feature_extractor=__lowerCamelCase					,       tokenizer=__lowerCamelCase       )





      def __call__(		self						:					Optional[Any]					,       *__lowerCamelCase						:					Tuple					,       **__lowerCamelCase						:					str       )    ->   Tuple:






         """simple docstring"""







         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."""       )
            UpperCAmelCase							=     kwargs.pop("""raw_speech"""       )
         else:
            UpperCAmelCase							=     kwargs.pop("""audio"""					,       __lowerCamelCase       )
         UpperCAmelCase							=     kwargs.pop("""sampling_rate"""					,       __lowerCamelCase       )
         UpperCAmelCase							=     kwargs.pop("""text"""					,       __lowerCamelCase       )
         if len(__lowerCamelCase       ) > 0:
            UpperCAmelCase							=     args[0]
            UpperCAmelCase							=     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							=     self.feature_extractor(__lowerCamelCase					,       *__lowerCamelCase					,       sampling_rate=__lowerCamelCase					,       **__lowerCamelCase       )
         if text is not None:
            UpperCAmelCase							=     self.tokenizer(__lowerCamelCase					,       **__lowerCamelCase       )

         if text is None:
            return inputs
         elif audio is None:
            return encodings
         else:
            UpperCAmelCase							=     encodings["""input_ids"""]
            return inputs





      def        _lowercase				(		self						:					Union[str, Any]					,       *__lowerCamelCase						:					List[str]					,       **__lowerCamelCase						:					Optional[Any]       )    ->   Dict:






         """simple docstring"""







         if self._in_target_context_manager:
            return self.current_processor.pad(*__lowerCamelCase					,       **__lowerCamelCase       )

         UpperCAmelCase							=     kwargs.pop("""input_features"""					,       __lowerCamelCase       )
         UpperCAmelCase							=     kwargs.pop("""labels"""					,       __lowerCamelCase       )
         if len(__lowerCamelCase       ) > 0:
            UpperCAmelCase							=     args[0]
            UpperCAmelCase							=     args[1:]

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

         if labels is None:
            return input_features
         elif input_features is None:
            return labels
         else:
            UpperCAmelCase							=     labels["""input_ids"""]
            return input_features





      def        _lowercase				(		self						:					int					,       *__lowerCamelCase						:					Dict					,       **__lowerCamelCase						:					Optional[int]       )    ->   Optional[int]:






         """simple docstring"""







         return self.tokenizer.batch_decode(*__lowerCamelCase					,       **__lowerCamelCase       )





      def        _lowercase				(		self						:					Any					,       *__lowerCamelCase						:					Tuple					,       **__lowerCamelCase						:					Dict       )    ->   List[Any]:






         """simple docstring"""







         return self.tokenizer.decode(*__lowerCamelCase					,       **__lowerCamelCase       )





      @contextmanager
      def        _lowercase				(		self						:					Optional[Any]       )    ->   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."""       )
         UpperCAmelCase							=     True
         UpperCAmelCase							=     self.tokenizer
         yield
         UpperCAmelCase							=     self.feature_extractor
         UpperCAmelCase							=     False







import pickle
import unittest

import torch

from accelerate import Accelerator
from accelerate.state import AcceleratorState
from accelerate.test_utils import require_cpu






@require_cpu
class   __lowercase				(  unittest.TestCase  ):





      def        _lowercase				(		self						:					Any       )    ->   Union[str, Any]:






         """simple docstring"""







         UpperCAmelCase							=     torch.nn.Linear(1_0					,       1_0       )
         UpperCAmelCase							=     torch.optim.SGD(model.parameters()					,       0.1       )
         UpperCAmelCase							=     Accelerator()
         UpperCAmelCase							=     accelerator.prepare(__lowerCamelCase       )
         try:
            pickle.loads(pickle.dumps(__lowerCamelCase       )       )
         except Exception as e:
            self.fail(F"""Accelerated optimizer pickling failed with {e}"""       )
         AcceleratorState._reset_state()



