





from typing import List, Optional, Union

import numpy as np
import torch
import torchaudio.compliance.kaldi as ta_kaldi

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


A   : Any			=				logging.get_logger(__name__)


class   A      (snake_case_   ):
			'''simple docstring'''




			__lowerCamelCase     :	Any          =   ['''input_features''', '''attention_mask''']






			def __init__(      self       :   Any							,     __lowerCAmelCase       :   List[Any]=80							,     __lowerCAmelCase       :   int=1_60_00							,     __lowerCAmelCase       :   Any=80							,     __lowerCAmelCase       :   List[Any]=0.0							,     __lowerCAmelCase       :   int=True							,     __lowerCAmelCase       :   Union[str, Any]=True							,     __lowerCAmelCase       :   Optional[int]=True							,     **__lowerCAmelCase       :   Union[str, Any]							,     )     ->     List[str]:







					"""simple docstring"""






					super().__init__(feature_size=__lowerCAmelCase							,     sampling_rate=__lowerCAmelCase							,     padding_value=__lowerCAmelCase							,     **__lowerCAmelCase       )
					A__  				=       num_mel_bins
					A__  				=       do_ceptral_normalize
					A__  				=       normalize_means
					A__  				=       normalize_vars
					A__  				=       True






			def        a_	(      self       :   int							,     __lowerCAmelCase       :   Tuple							,     )     ->     np.ndarray:







					"""simple docstring"""






					A__  				=       waveform * (2**15)  # Kaldi compliance: 16-bit signed integers
					A__  				=       torch.from_numpy(__lowerCAmelCase       ).unsqueeze(0       )
					A__  				=       ta_kaldi.fbank(__lowerCAmelCase							,     num_mel_bins=self.num_mel_bins							,     sample_frequency=self.sampling_rate       )
					return features.numpy()






			@staticmethod
			def        a_	(      __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   List[Any] = True							,     __lowerCAmelCase       :   Dict = True							,     __lowerCAmelCase       :   Dict = 0.0							,     )     ->     np.ndarray:







					"""simple docstring"""






					if normalize_means:
							A__  				=       x[:input_length].mean(axis=0       )
							A__  				=       np.subtract(__lowerCAmelCase							,     __lowerCAmelCase       )
					if normalize_vars:
							A__  				=       x[:input_length].std(axis=0       )
							A__  				=       np.divide(__lowerCAmelCase							,     __lowerCAmelCase       )

					if input_length < x.shape[0]:
							A__  				=       padding_value

					# make sure array is in float32
					A__  				=       x.astype(np.floataa       )

					return x






			def        a_	(      self       :   Dict							,     __lowerCAmelCase       :   Tuple							,     __lowerCAmelCase       :   Dict = None       )     ->     List[np.ndarray]:







					"""simple docstring"""






					A__  				=       attention_mask.sum(-1       ) if attention_mask is not None else [x.shape[0] for x in input_features]
					return [
					    self.utterance_cmvn(__lowerCAmelCase							,     __lowerCAmelCase							,     self.normalize_means							,     self.normalize_vars							,     self.padding_value       )
					    for x, n in zip(__lowerCAmelCase							,     __lowerCAmelCase       )
					]







			def __call__(      self       :   Tuple							,     __lowerCAmelCase       :   Dict							,     __lowerCAmelCase       :   List[Any] = False							,     __lowerCAmelCase       :   Tuple = None							,     __lowerCAmelCase       :   Optional[int] = False							,     __lowerCAmelCase       :   Dict = None							,     __lowerCAmelCase       :   Union[str, Any] = None							,     __lowerCAmelCase       :   Optional[Any] = None							,     __lowerCAmelCase       :   Optional[Any] = None							,     **__lowerCAmelCase       :   Optional[Any]							,     )     ->     BatchFeature:







					"""simple docstring"""






					if sampling_rate is not None:
							if sampling_rate != self.sampling_rate:
									raise ValueError(
									    f'The model corresponding to this feature extractor: {self} was trained using a sampling rate of'
									    f' {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with'
									    f' {self.sampling_rate} and not {sampling_rate}.'       )
					else:
							logger.warning(
							    """It is strongly recommended to pass the `sampling_rate` argument to this function. """
							    """Failing to do so can result in silent errors that might be hard to debug."""       )

					A__  				=       isinstance(__lowerCAmelCase							,     np.ndarray       ) and len(raw_speech.shape       ) > 1
					if is_batched_numpy and len(raw_speech.shape       ) > 2:
							raise ValueError(f'Only mono-channel audio is supported for input to {self}'       )
					A__  				=       is_batched_numpy or (
					    isinstance(__lowerCAmelCase							,     (list, tuple)       ) and (isinstance(raw_speech[0]							,     (np.ndarray, tuple, list)       ))
					)

					if is_batched:
							A__  				=       [np.asarray(__lowerCAmelCase							,     dtype=np.floataa       ) for speech in raw_speech]
					elif not is_batched and not isinstance(__lowerCAmelCase							,     np.ndarray       ):
							A__  				=       np.asarray(__lowerCAmelCase							,     dtype=np.floataa       )
					elif isinstance(__lowerCAmelCase							,     np.ndarray       ) and raw_speech.dtype is np.dtype(np.floataa       ):
							A__  				=       raw_speech.astype(np.floataa       )

					# always return batch
					if not is_batched:
							A__  				=       [raw_speech]

					# extract fbank features
					A__  				=       [self._extract_fbank_features(__lowerCAmelCase       ) for waveform in raw_speech]

					# convert into correct format for padding
					A__  				=       BatchFeature({"""input_features""": features}       )

					A__  				=       self.pad(
					    __lowerCAmelCase							,     padding=__lowerCAmelCase							,     max_length=__lowerCAmelCase							,     truncation=__lowerCAmelCase							,     pad_to_multiple_of=__lowerCAmelCase							,     return_attention_mask=__lowerCAmelCase							,     **__lowerCAmelCase							,     )

					# make sure list is in array format
					A__  				=       padded_inputs.get("""input_features"""       )
					if isinstance(input_features[0]							,     __lowerCAmelCase       ):
							A__  				=       [np.asarray(__lowerCAmelCase							,     dtype=np.floataa       ) for feature in input_features]

					A__  				=       padded_inputs.get("""attention_mask"""       )
					if attention_mask is not None:
							A__  				=       [np.asarray(__lowerCAmelCase							,     dtype=np.intaa       ) for array in attention_mask]

					# Utterance-level cepstral mean and variance normalization
					if self.do_ceptral_normalize:
							A__  				=       (
							    np.array(__lowerCAmelCase							,     dtype=np.intaa       )
							    if self._get_padding_strategies(__lowerCAmelCase							,     max_length=__lowerCAmelCase       ) is not PaddingStrategy.DO_NOT_PAD
							    else None
							)
							A__  				=       self.normalize(
							    padded_inputs["""input_features"""]							,     attention_mask=__lowerCAmelCase       )

					if return_tensors is not None:
							A__  				=       padded_inputs.convert_to_tensors(__lowerCAmelCase       )

					return padded_inputs













from string import ascii_uppercase

A   : List[str]			=				{str(ord(c) - 5_5): c for c in ascii_uppercase}







def        __lowerCamelCase (							__a       :int   ,					__a       :int   )		->    str:






		"""simple docstring"""

		if isinstance(__a   ,					__a   ):
				raise TypeError("""int() can't convert non-string with explicit base"""   )
		if num < 0:
				raise ValueError("""parameter must be positive int"""   )
		if isinstance(__a   ,					__a   ):
				raise TypeError("""'str' object cannot be interpreted as an integer"""   )
		if isinstance(__a   ,					__a   ):
				raise TypeError("""'float' object cannot be interpreted as an integer"""   )
		if base in (0, 1):
				raise ValueError("""base must be >= 2"""   )
		if base > 3_6:
				raise ValueError("""base must be <= 36"""   )
		A__  				=       """"""
		A__  				=       0
		A__  				=       0
		while div != 1:
				A__				,      A__  				=       divmod(__a   ,					__a   )
				if base >= 1_1 and 9 < mod < 3_6:
						A__  				=       ALPHABET_VALUES[str(__a   )]
				else:
						A__  				=       str(__a   )
				new_value += actual_value
				A__  				=       num // base
				A__  				=       div
				if div == 0:
						return str(new_value[::-1]   )
				elif div == 1:
						new_value += str(__a   )
						return str(new_value[::-1]   )

		return new_value[::-1]


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					for base in range(2, 3_7):
										for num in range(1_0_0_0):
															assert int(decimal_to_any(num, base), base) == num, (
															    num,
															    base,
															    decimal_to_any(num, base),
															    int(decimal_to_any(num, base), base),
															)



