

import warnings
from contextlib import contextmanager

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



class   lowercase_   (  __lowercase					):
      UpperCamelCase_      :		Tuple										=    "Wav2Vec2FeatureExtractor"
      UpperCamelCase_      :		List[Any]										=    "AutoTokenizer"



      def __init__(      self				:    Union[str, Any]      , A__				:    Dict      , A__				:    List[Any]		)   ->					Optional[int]:
        super().__init__(A__      , A__		)
        _snake_case						=							self.feature_extractor
        _snake_case						=							False



      @classmethod
      def 						UpperCamelCase_		(      cls				:    Dict      , A__				:    Union[str, Any]      , **A__				:    Dict		)   ->					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__      , )

          _snake_case						=							WavaVecaFeatureExtractor.from_pretrained(A__      , **A__		)
          _snake_case						=							WavaVecaCTCTokenizer.from_pretrained(A__      , **A__		)

          return cls(feature_extractor=A__      , tokenizer=A__		)



      def __call__(      self				:    Dict      , *A__				:    Optional[Any]      , **A__				:    List[str]		)   ->					Tuple:
        # 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.'''		)
          _snake_case						=							kwargs.pop('''raw_speech'''		)
        else:
          _snake_case						=							kwargs.pop('''audio'''      , A__		)
        _snake_case						=							kwargs.pop('''sampling_rate'''      , A__		)
        _snake_case						=							kwargs.pop('''text'''      , A__		)
        if len(A__		) > 0:
          _snake_case						=							args[0]
          _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:
          _snake_case						=							self.feature_extractor(A__      , *A__      , sampling_rate=A__      , **A__		)
        if text is not None:
          _snake_case						=							self.tokenizer(A__      , **A__		)

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



      def 						UpperCamelCase_		(      self				:    Optional[int]      , *A__				:    Optional[Any]      , **A__				:    Tuple		)   ->					Optional[int]:
        # For backward compatibility
        if self._in_target_context_manager:
          return self.current_processor.pad(*A__      , **A__		)

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

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

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



      def 						UpperCamelCase_		(      self				:    List[Any]      , *A__				:    List[str]      , **A__				:    Dict		)   ->					Any:
        return self.tokenizer.batch_decode(*A__      , **A__		)



      def 						UpperCamelCase_		(      self				:    Optional[Any]      , *A__				:    Any      , **A__				:    Tuple		)   ->					str:
        return self.tokenizer.decode(*A__      , **A__		)







      @contextmanager
      def 						UpperCamelCase_		(      self				:    Union[str, Any]		)   ->					int:
        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.'''		)
        _snake_case						=							True
        _snake_case						=							self.tokenizer
        yield
        _snake_case						=							self.feature_extractor
        _snake_case						=							False




__A      		=     {
    '''Pillow''': '''Pillow<10.0.0''',
    '''accelerate''': '''accelerate>=0.20.3''',
    '''av''': '''av==9.2.0''',
    '''beautifulsoup4''': '''beautifulsoup4''',
    '''black''': '''black~=23.1''',
    '''codecarbon''': '''codecarbon==1.2.0''',
    '''cookiecutter''': '''cookiecutter==1.7.3''',
    '''dataclasses''': '''dataclasses''',
    '''datasets''': '''datasets!=2.5.0''',
    '''decord''': '''decord==0.6.0''',
    '''deepspeed''': '''deepspeed>=0.9.3''',
    '''diffusers''': '''diffusers''',
    '''dill''': '''dill<0.3.5''',
    '''evaluate''': '''evaluate>=0.2.0''',
    '''fairscale''': '''fairscale>0.3''',
    '''faiss-cpu''': '''faiss-cpu''',
    '''fastapi''': '''fastapi''',
    '''filelock''': '''filelock''',
    '''flax''': '''flax>=0.4.1,<=0.7.0''',
    '''ftfy''': '''ftfy''',
    '''fugashi''': '''fugashi>=1.0''',
    '''GitPython''': '''GitPython<3.1.19''',
    '''hf-doc-builder''': '''hf-doc-builder>=0.3.0''',
    '''huggingface-hub''': '''huggingface-hub>=0.14.1,<1.0''',
    '''importlib_metadata''': '''importlib_metadata''',
    '''ipadic''': '''ipadic>=1.0.0,<2.0''',
    '''isort''': '''isort>=5.5.4''',
    '''jax''': '''jax>=0.2.8,!=0.3.2,<=0.4.13''',
    '''jaxlib''': '''jaxlib>=0.1.65,<=0.4.13''',
    '''jieba''': '''jieba''',
    '''kenlm''': '''kenlm''',
    '''keras-nlp''': '''keras-nlp>=0.3.1''',
    '''librosa''': '''librosa''',
    '''nltk''': '''nltk''',
    '''natten''': '''natten>=0.14.6''',
    '''numpy''': '''numpy>=1.17''',
    '''onnxconverter-common''': '''onnxconverter-common''',
    '''onnxruntime-tools''': '''onnxruntime-tools>=1.4.2''',
    '''onnxruntime''': '''onnxruntime>=1.4.0''',
    '''opencv-python''': '''opencv-python''',
    '''optuna''': '''optuna''',
    '''optax''': '''optax>=0.0.8,<=0.1.4''',
    '''packaging''': '''packaging>=20.0''',
    '''parameterized''': '''parameterized''',
    '''phonemizer''': '''phonemizer''',
    '''protobuf''': '''protobuf''',
    '''psutil''': '''psutil''',
    '''pyyaml''': '''pyyaml>=5.1''',
    '''pydantic''': '''pydantic<2''',
    '''pytest''': '''pytest>=7.2.0''',
    '''pytest-timeout''': '''pytest-timeout''',
    '''pytest-xdist''': '''pytest-xdist''',
    '''python''': '''python>=3.8.0''',
    '''ray[tune]''': '''ray[tune]''',
    '''regex''': '''regex!=2019.12.17''',
    '''requests''': '''requests''',
    '''rhoknp''': '''rhoknp>=1.1.0,<1.3.1''',
    '''rjieba''': '''rjieba''',
    '''rouge-score''': '''rouge-score!=0.0.7,!=0.0.8,!=0.1,!=0.1.1''',
    '''ruff''': '''ruff>=0.0.241,<=0.0.259''',
    '''sacrebleu''': '''sacrebleu>=1.4.12,<2.0.0''',
    '''sacremoses''': '''sacremoses''',
    '''safetensors''': '''safetensors>=0.3.1''',
    '''sagemaker''': '''sagemaker>=2.31.0''',
    '''scikit-learn''': '''scikit-learn''',
    '''sentencepiece''': '''sentencepiece>=0.1.91,!=0.1.92''',
    '''sigopt''': '''sigopt''',
    '''starlette''': '''starlette''',
    '''sudachipy''': '''sudachipy>=0.6.6''',
    '''sudachidict_core''': '''sudachidict_core>=20220729''',
    '''tensorflow-cpu''': '''tensorflow-cpu>=2.6,<2.14''',
    '''tensorflow''': '''tensorflow>=2.6,<2.14''',
    '''tensorflow-text''': '''tensorflow-text<2.14''',
    '''tf2onnx''': '''tf2onnx''',
    '''timeout-decorator''': '''timeout-decorator''',
    '''timm''': '''timm''',
    '''tokenizers''': '''tokenizers>=0.11.1,!=0.11.3,<0.14''',
    '''torch''': '''torch>=1.9,!=1.12.0''',
    '''torchaudio''': '''torchaudio''',
    '''torchvision''': '''torchvision''',
    '''pyctcdecode''': '''pyctcdecode>=0.4.0''',
    '''tqdm''': '''tqdm>=4.27''',
    '''unidic''': '''unidic>=1.0.2''',
    '''unidic_lite''': '''unidic_lite>=1.0.7''',
    '''urllib3''': '''urllib3<2.0.0''',
    '''uvicorn''': '''uvicorn''',
}

