



'''simple docstring'''





import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class 					lowerCamelCase_    (				SCREAMING_SNAKE_CASE_     ):
  """simple docstring"""




  a_												="""Speech2TextFeatureExtractor"""
  a_												="""Speech2TextTokenizer"""




  def __init__( self      :	Optional[int]			,	_a      :	Union[str, Any]			,	_a      :	Union[str, Any]   )					->					List[str]:
    super().__init__(_a			,	_a   )
    __lowerCamelCase       :       Optional[int]           = self.feature_extractor
    __lowerCamelCase       :       Tuple           = False




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

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




  def 						_lowercase     ( self      :	int			,	*_a      :	Dict			,	**_a      :	List[str]   )					->					int:
    return self.tokenizer.batch_decode(*_a			,	**_a   )




  def 						_lowercase     ( self      :	Tuple			,	*_a      :	Any			,	**_a      :	Any   )					->					str:
    return self.tokenizer.decode(*_a			,	**_a   )




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











'''simple docstring'''





import inspect
import warnings
from typing import Any, Dict, Optional, Union

from packaging import version

def        a_     (							*_lowerCAmelCase       ,_lowerCAmelCase = None       ,_lowerCAmelCase=True       ,_lowerCAmelCase=2       )      ->      List[str]:
  from .. import __version__

  __lowerCamelCase       :       Any           = take_from
  __lowerCamelCase       :       Optional[int]           = ()
  if not isinstance(args[0]       ,_lowerCAmelCase       ):
    __lowerCamelCase       :       Optional[Any]           = (args,)

  for attribute, version_name, message in args:
    if version.parse(version.parse(_lowerCAmelCase       ).base_version       ) >= version.parse(_lowerCAmelCase       ):
      raise ValueError(
          F'The deprecation tuple {(attribute, version_name, message)} should be removed since diffusers\''
          F' version {__version__} is >= {version_name}'       )

    __lowerCamelCase       :       Union[str, Any]           = None
    if isinstance(_lowerCAmelCase       ,_lowerCAmelCase       ) and attribute in deprecated_kwargs:
      values += (deprecated_kwargs.pop(_lowerCAmelCase       ),)
      __lowerCamelCase       :       Optional[Any]           = F'The `{attribute}` argument is deprecated and will be removed in version {version_name}.'
    elif hasattr(_lowerCAmelCase       ,_lowerCAmelCase       ):
      values += (getattr(_lowerCAmelCase       ,_lowerCAmelCase       ),)
      __lowerCamelCase       :       List[str]           = F'The `{attribute}` attribute is deprecated and will be removed in version {version_name}.'
    elif deprecated_kwargs is None:
      __lowerCamelCase       :       Optional[Any]           = F'`{attribute}` is deprecated and will be removed in version {version_name}.'

    if warning is not None:
      __lowerCamelCase       :       Optional[int]           = warning + ' ' if standard_warn else ''
      warnings.warn(warning + message       ,_lowerCAmelCase       ,stacklevel=_lowerCAmelCase       )

  if isinstance(_lowerCAmelCase       ,_lowerCAmelCase       ) and len(_lowerCAmelCase       ) > 0:
    __lowerCamelCase       :       Optional[Any]           = inspect.getouterframes(inspect.currentframe()       )[1]
    __lowerCamelCase       :       List[str]           = call_frame.filename
    __lowerCamelCase       :       int           = call_frame.lineno
    __lowerCamelCase       :       Union[str, Any]           = call_frame.function
    __lowerCamelCase       ,__lowerCamelCase       :       Union[str, Any]           = next(iter(deprecated_kwargs.items()       )       )
    raise TypeError(F'{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`'       )

  if len(_lowerCAmelCase       ) == 0:
    return
  elif len(_lowerCAmelCase       ) == 1:
    return values[0]
  return values






