





import warnings
from contextlib import contextmanager

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



class     _UpperCAmelCase   (   _UpperCamelCase   ):

  """simple docstring"""


  a_      =			"""Wav2Vec2FeatureExtractor"""
  a_      =			"""AutoTokenizer"""






  def __init__(    self			:		Any ,  lowerCAmelCase_			:		Union[str, Any] ,  lowerCAmelCase_			:		str					)							->						Optional[int]:
     super().__init__(lowerCAmelCase_ ,  lowerCAmelCase_					)
     __lowerCAmelCase							     =     self.feature_extractor
     __lowerCAmelCase							     =     False






  @classmethod
  def     lowercase		(    cls			:		Optional[Any] ,  lowerCAmelCase_			:		Optional[int] ,  **lowerCAmelCase_			:		Union[str, Any]					)							->						int:
     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_ ,  )

        __lowerCAmelCase							     =     WavaVecaFeatureExtractor.from_pretrained(lowerCAmelCase_ ,  **lowerCAmelCase_					)
        __lowerCAmelCase							     =     WavaVecaCTCTokenizer.from_pretrained(lowerCAmelCase_ ,  **lowerCAmelCase_					)

        return cls(feature_extractor=lowerCAmelCase_ ,  tokenizer=lowerCAmelCase_					)






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

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






  def     lowercase		(    self			:		Optional[Any] ,  *lowerCAmelCase_			:		Dict ,  **lowerCAmelCase_			:		Union[str, Any]					)							->						Any:
     # For backward compatibility
     if self._in_target_context_manager:
        return self.current_processor.pad(*lowerCAmelCase_ ,  **lowerCAmelCase_					)

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

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

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






  def     lowercase		(    self			:		List[Any] ,  *lowerCAmelCase_			:		Dict ,  **lowerCAmelCase_			:		Tuple					)							->						str:
     return self.tokenizer.batch_decode(*lowerCAmelCase_ ,  **lowerCAmelCase_					)






  def     lowercase		(    self			:		Optional[Any] ,  *lowerCAmelCase_			:		int ,  **lowerCAmelCase_			:		Tuple					)							->						Any:
     return self.tokenizer.decode(*lowerCAmelCase_ ,  **lowerCAmelCase_					)






  @contextmanager
  def     lowercase		(    self			:		Optional[int]					)							->						Dict:
     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.'					)
     __lowerCAmelCase							     =     True
     __lowerCAmelCase							     =     self.tokenizer
     yield
     __lowerCAmelCase							     =     self.feature_extractor
     __lowerCAmelCase							     =     False








import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


_snake_case  :   Union[str, Any]						   =  False
try:
     _snake_case  :   Tuple						   =  _is_package_available('google.colab')
except ModuleNotFoundError:
     pass



@input.register
class     _UpperCAmelCase   :

  """simple docstring"""


  def __init__(    self			:		Union[str, Any] ,  lowerCAmelCase_			:		str = None ,  lowerCAmelCase_			:		list = []					)							->						Optional[int]:
     __lowerCAmelCase							     =     0
     __lowerCAmelCase							     =     choices
     __lowerCAmelCase							     =     prompt
     if sys.platform == "win32":
        __lowerCAmelCase							     =     '*'
     else:
        __lowerCAmelCase							     =     '➔ '






  def     lowercase		(    self			:		Dict ,  lowerCAmelCase_			:		Dict ,  lowerCAmelCase_			:		str = ""					)							->						Any:
     if sys.platform != "win32":
        writeColor(self.choices[index] ,  3_2 ,  lowerCAmelCase_					)
     else:
        forceWrite(self.choices[index] ,  lowerCAmelCase_					)






  def     lowercase		(    self			:		List[Any] ,  lowerCAmelCase_			:		int					)							->						List[Any]:
     if index == self.position:
        forceWrite(f""" {self.arrow_char} """					)
        self.write_choice(lowerCAmelCase_					)
     else:
        forceWrite(f"""    {self.choices[index]}"""					)
     reset_cursor()






  def     lowercase		(    self			:		Dict ,  lowerCAmelCase_			:		Direction ,  lowerCAmelCase_			:		int = 1					)							->						Union[str, Any]:
     __lowerCAmelCase							     =     self.position
     if direction == Direction.DOWN:
        if self.position + 1 >= len(self.choices					):
           return
        self.position += num_spaces
     else:
        if self.position - 1 < 0:
           return
        self.position -= num_spaces
     clear_line()
     self.print_choice(lowerCAmelCase_					)
     move_cursor(lowerCAmelCase_ ,  direction.name					)
     self.print_choice(self.position					)






  @input.mark(KEYMAP['up']					)
  def     lowercase		(    self			:		Optional[int]					)							->						Tuple:
     self.move_direction(Direction.UP					)






  @input.mark(KEYMAP['down']					)
  def     lowercase		(    self			:		str					)							->						Optional[Any]:
     self.move_direction(Direction.DOWN					)






  @input.mark(KEYMAP['newline']					)
  def     lowercase		(    self			:		str					)							->						Any:
     move_cursor(len(self.choices					) - self.position ,  'DOWN'					)
     return self.position






  @input.mark(KEYMAP['interrupt']					)
  def     lowercase		(    self			:		Dict					)							->						Optional[Any]:
     move_cursor(len(self.choices					) - self.position ,  'DOWN'					)
     raise KeyboardInterrupt






  @input.mark_multiple(*[KEYMAP[str(lowerCAmelCase_					)] for number in range(1_0					)]					)
  def     lowercase		(    self			:		List[Any]					)							->						Optional[int]:
     __lowerCAmelCase							     =     int(chr(self.current_selection					)					)
     __lowerCAmelCase							     =     index - self.position
     if index == self.position:
        return
     if index < len(self.choices					):
        if self.position > index:
           self.move_direction(Direction.UP ,  -movement					)
        elif self.position < index:
           self.move_direction(Direction.DOWN ,  lowerCAmelCase_					)
        else:
           return
     else:
        return






  def     lowercase		(    self			:		Any ,  lowerCAmelCase_			:		int = 0					)							->						int:
     if self.prompt:
        linebreak()
        forceWrite(self.prompt ,  '\n'					)
        if in_colab:
           forceWrite('Please input a choice index (starting from 0), and press enter' ,  '\n'					)
        else:
           forceWrite('Please select a choice using the arrow or number keys, and selecting with enter' ,  '\n'					)
     __lowerCAmelCase							     =     default_choice
     for i in range(len(self.choices					)					):
        self.print_choice(lowerCAmelCase_					)
        forceWrite('\n'					)
     move_cursor(len(self.choices					) - self.position ,  'UP'					)
     with cursor.hide():
        while True:
           if in_colab:
              try:
                 __lowerCAmelCase							     =     int(builtins.input()					)
              except ValueError:
                 __lowerCAmelCase							     =     default_choice
           else:
              __lowerCAmelCase							     =     self.handle_input()
           if choice is not None:
              reset_cursor()
              for _ in range(len(self.choices					) + 1					):
                 move_cursor(1 ,  'UP'					)
                 clear_line()
              self.write_choice(lowerCAmelCase_ ,  '\n'					)
              return choice

