






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin



class 				_UpperCamelCase      (a_      ):
      snake_case_	=				"""Speech2TextFeatureExtractor"""
      snake_case_	=				"""Speech2TextTokenizer"""


      def __init__(						self       ,    __UpperCamelCase       ,    __UpperCamelCase						)->						str:
           super().__init__(__UpperCamelCase       ,    __UpperCamelCase						)
           __lowerCAmelCase             =       self.feature_extractor
           __lowerCAmelCase             =       False


      def __call__(						self       ,    *__UpperCamelCase       ,    **__UpperCamelCase						)->						Dict:
           # For backward compatibility
           if self._in_target_context_manager:
                return self.current_processor(*__UpperCamelCase       ,    **__UpperCamelCase						)

           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"       ,    __UpperCamelCase						)
           __lowerCAmelCase             =       kwargs.pop("sampling_rate"       ,    __UpperCamelCase						)
           __lowerCAmelCase             =       kwargs.pop("text"       ,    __UpperCamelCase						)
           if len(__UpperCamelCase						) > 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(__UpperCamelCase       ,    *__UpperCamelCase       ,    sampling_rate=__UpperCamelCase       ,    **__UpperCamelCase						)
           if text is not None:
                __lowerCAmelCase             =       self.tokenizer(__UpperCamelCase       ,    **__UpperCamelCase						)

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


      def 			__UpperCAmelCase		(						self       ,    *__UpperCamelCase       ,    **__UpperCamelCase						)->						Optional[int]:
           return self.tokenizer.batch_decode(*__UpperCamelCase       ,    **__UpperCamelCase						)


      def 			__UpperCAmelCase		(						self       ,    *__UpperCamelCase       ,    **__UpperCamelCase						)->						int:
           return self.tokenizer.decode(*__UpperCamelCase       ,    **__UpperCamelCase						)


      @contextmanager
      def 			__UpperCAmelCase		(						self						)->						Optional[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."						)
           __lowerCAmelCase             =       True
           __lowerCAmelCase             =       self.tokenizer
           yield
           __lowerCAmelCase             =       self.feature_extractor
           __lowerCAmelCase             =       False














lowerCamelCase      :       List[Any]    =						{
    '''meter''': '''m''',
    '''kilometer''': '''km''',
    '''megametre''': '''Mm''',
    '''gigametre''': '''Gm''',
    '''terametre''': '''Tm''',
    '''petametre''': '''Pm''',
    '''exametre''': '''Em''',
    '''zettametre''': '''Zm''',
    '''yottametre''': '''Ym''',
}
# Exponent of the factor(meter)
lowerCamelCase      :       Union[str, Any]    =						{
    '''m''': 0,
    '''km''': 3,
    '''Mm''': 6,
    '''Gm''': 9,
    '''Tm''': 12,
    '''Pm''': 15,
    '''Em''': 18,
    '''Zm''': 21,
    '''Ym''': 24,
}





def    __lowerCAmelCase   (    __snake_case       ,			__snake_case       ,			__snake_case							):
     __lowerCAmelCase             =       from_type.lower().strip("s"							)
     __lowerCAmelCase             =       to_type.lower().strip("s"							)

     __lowerCAmelCase             =       UNIT_SYMBOL.get(__snake_case       ,			__snake_case							)
     __lowerCAmelCase             =       UNIT_SYMBOL.get(__snake_case       ,			__snake_case							)

     if from_sanitized not in METRIC_CONVERSION:
          __lowerCAmelCase             =       (
              F"""Invalid 'from_type' value: {from_type!r}.\n"""
              F"""Conversion abbreviations are: {", ".join(__snake_case							)}"""
          )
          raise ValueError(__snake_case							)
     if to_sanitized not in METRIC_CONVERSION:
          __lowerCAmelCase             =       (
              F"""Invalid 'to_type' value: {to_type!r}.\n"""
              F"""Conversion abbreviations are: {", ".join(__snake_case							)}"""
          )
          raise ValueError(__snake_case							)
     __lowerCAmelCase             =       METRIC_CONVERSION[from_sanitized]
     __lowerCAmelCase             =       METRIC_CONVERSION[to_sanitized]
     __lowerCAmelCase             =       1

     if from_exponent > to_exponent:
          __lowerCAmelCase             =       from_exponent - to_exponent
     else:
          __lowerCAmelCase             =       -(to_exponent - from_exponent)

     return value * pow(10       ,			__snake_case							)


if __name__ == "__main__":
 from doctest import testmod

 testmod()






