code: 
  
  
  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 TensorType, logging
  
  
  UpperCamelCase__				       =			logging.get_logger(__name__)
  
  class 						UpperCAmelCase__   (      lowerCAmelCase_		):
  
  
  
       '''simple docstring'''
       UpperCAmelCase_         =  ['''input_values''', '''attention_mask''']
  
  
  
  
       def __init__( self       :       Tuple	,      UpperCamelCase       :       Tuple=1	,      UpperCamelCase       :       Any=1_60_00	,      UpperCamelCase       :       Optional[int]=1_28	,      UpperCamelCase       :       Union[str, Any]=10_24	,      UpperCamelCase       :       str=0.0	,      UpperCamelCase       :       str=True	,      UpperCamelCase       :       Union[str, Any]=-4.2677393	,      UpperCamelCase       :       List[Any]=4.5689974	,      UpperCamelCase       :       Dict=False	,      **UpperCamelCase       :       Optional[int]	,      ):
  
  
  
  
  
              """simple docstring"""
  
  
  
              super().__init__(feature_size=__a	,      sampling_rate=__a	,      padding_value=__a	,      **__a		)
              _lowercase					:				List[str]           =			num_mel_bins
              _lowercase					:				Dict           =			max_length
              _lowercase					:				Tuple           =			do_normalize
              _lowercase					:				Optional[Any]           =			mean
              _lowercase					:				Any           =			std
              _lowercase					:				Optional[int]           =			return_attention_mask
  
  
  
  
       def   lowerCAmelCase_   ( self       :       Dict	,      UpperCamelCase       :       str	,      UpperCamelCase       :       Any	,      ):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Optional[int]           =			torch.from_numpy(__a		).unsqueeze(0		)
              _lowercase					:				List[str]           =			ta_kaldi.fbank(
                  __a	,      htk_compat=__a	,      sample_frequency=self.sampling_rate	,      use_energy=__a	,      window_type='''hanning'''	,      num_mel_bins=self.num_mel_bins	,      dither=0.0	,      frame_shift=10	,      )
  
              _lowercase					:				List[str]           =			fbank.shape[0]
              _lowercase					:				Union[str, Any]           =			max_length - n_frames
  
              # pad or truncate, depending on difference
              if difference > 0:
                     _lowercase					:				List[Any]           =			torch.nn.ZeroPadad((0, 0, 0, difference)		)
                     _lowercase					:				Optional[Any]           =			pad_module(__a		)
              elif difference < 0:
                     _lowercase					:				Optional[Any]           =			fbank[0:max_length, :]
  
              _lowercase					:				Tuple           =			fbank.numpy()
  
              return fbank
  
  
  
  
       def   lowerCAmelCase_   ( self       :       Union[str, Any]	,      UpperCamelCase       :       Any		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              return (input_values - (self.mean)) / (self.std * 2)
  
  
  
  
       def __call__( self       :       Optional[Any]	,      UpperCamelCase       :       Any	,      UpperCamelCase       :       List[str] = None	,      UpperCamelCase       :       Dict = None	,      **UpperCamelCase       :       List[str]	,      ):
  
  
  
  
  
              """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.'''		)
  
              _lowercase					:				Optional[Any]           =			isinstance(__a	,      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}'		)
              _lowercase					:				Optional[Any]           =			is_batched_numpy or (
                  isinstance(__a	,      (list, tuple)		) and (isinstance(raw_speech[0]	,      (np.ndarray, tuple, list)		))
              )
  
              if is_batched:
                     _lowercase					:				Union[str, Any]           =			[np.asarray(__a	,      dtype=np.floataa		) for speech in raw_speech]
              elif not is_batched and not isinstance(__a	,      np.ndarray		):
                     _lowercase					:				Optional[int]           =			np.asarray(__a	,      dtype=np.floataa		)
              elif isinstance(__a	,      np.ndarray		) and raw_speech.dtype is np.dtype(np.floataa		):
                     _lowercase					:				str           =			raw_speech.astype(np.floataa		)
  
              # always return batch
              if not is_batched:
                     _lowercase					:				List[str]           =			[raw_speech]
  
              # extract fbank features and pad/truncate to max_length
              _lowercase					:				Tuple           =			[self._extract_fbank_features(__a	,      max_length=self.max_length		) for waveform in raw_speech]
  
              # convert into BatchFeature
              _lowercase					:				Tuple           =			BatchFeature({'''input_values''': features}		)
  
              # make sure list is in array format
              _lowercase					:				Optional[Any]           =			padded_inputs.get('''input_values'''		)
              if isinstance(input_values[0]	,      __a		):
                     _lowercase					:				Union[str, Any]           =			[np.asarray(__a	,      dtype=np.floataa		) for feature in input_values]
  
              # normalization
              if self.do_normalize:
                     _lowercase					:				int           =			[self.normalize(__a		) for feature in input_values]
  
              if return_tensors is not None:
                     _lowercase					:				str           =			padded_inputs.convert_to_tensors(__a		)
  
              return padded_inputs
  
  
  
style_context: 
  
  
  import torch
  import torch.nn as nn
  from transformers.modeling_utils import ModuleUtilsMixin
  from transformers.models.ta.modeling_ta import (
      TaBlock,
      TaConfig,
      TaLayerNorm,
  )
  
  from ...configuration_utils import ConfigMixin, register_to_config
  from ...models import ModelMixin
  
  class 						UpperCAmelCase__   (      A_      ,						A_      ,						A_		):
  
  
  
       '''simple docstring'''
  
  
  
  
       @register_to_config
       def __init__( self       :       Dict	,      UpperCamelCase       :       int	,      UpperCamelCase       :       int	,      UpperCamelCase       :       int	,      UpperCamelCase       :       float	,      UpperCamelCase       :       int	,      UpperCamelCase       :       int	,      UpperCamelCase       :       int	,      UpperCamelCase       :       int	,      UpperCamelCase       :       str	,      UpperCamelCase       :       bool = False	,      ):
  
  
  
  
  
              """simple docstring"""
  
  
  
              super().__init__()
  
              _lowercase					:				Any           =			nn.Linear(UpperCamelCase	,      UpperCamelCase	,      bias=UpperCamelCase		)
  
              _lowercase					:				List[Any]           =			nn.Embedding(UpperCamelCase	,      UpperCamelCase		)
              _lowercase					:				Any           =			False
  
              _lowercase					:				Tuple           =			nn.Dropout(p=UpperCamelCase		)
  
              _lowercase					:				Any           =			TaConfig(
                  d_model=UpperCamelCase	,      num_heads=UpperCamelCase	,      d_kv=UpperCamelCase	,      d_ff=UpperCamelCase	,      feed_forward_proj=UpperCamelCase	,      dropout_rate=UpperCamelCase	,      is_decoder=UpperCamelCase	,      is_encoder_decoder=UpperCamelCase	,      )
              _lowercase					:				Any           =			nn.ModuleList()
              for lyr_num in range(UpperCamelCase		):
                     _lowercase					:				Tuple           =			TaBlock(UpperCamelCase		)
                     self.encoders.append(UpperCamelCase		)
  
              _lowercase					:				List[Any]           =			TaLayerNorm(UpperCamelCase		)
              _lowercase					:				Optional[Any]           =			nn.Dropout(p=UpperCamelCase		)
  
  
  
  
       def   lowerCAmelCase_   ( self       :       int	,      UpperCamelCase       :       Optional[int]	,      UpperCamelCase       :       List[Any]		):
  
  
  
  
  
              """simple docstring"""
  
  
  
              _lowercase					:				Optional[int]           =			self.input_proj(UpperCamelCase		)
  
              # terminal relative positional encodings
              _lowercase					:				Optional[int]           =			encoder_inputs.shape[1]
              _lowercase					:				Optional[int]           =			torch.arange(UpperCamelCase	,      device=encoder_inputs.device		)
  
              _lowercase					:				Any           =			encoder_inputs_mask.sum(-1		)
              _lowercase					:				int           =			torch.roll(input_positions.unsqueeze(0		)	,      tuple(seq_lens.tolist()		)	,      dims=0		)
              x += self.position_encoding(UpperCamelCase		)
  
              _lowercase					:				Optional[int]           =			self.dropout_pre(UpperCamelCase		)
  
              # inverted the attention mask
              _lowercase					:				Optional[int]           =			encoder_inputs.size()
              _lowercase					:				List[Any]           =			self.get_extended_attention_mask(UpperCamelCase	,      UpperCamelCase		)
  
              for lyr in self.encoders:
                     _lowercase					:				Optional[int]           =			lyr(UpperCamelCase	,      UpperCamelCase		)[0]
              _lowercase					:				List[str]           =			self.layer_norm(UpperCamelCase		)
  
              return self.dropout_post(UpperCamelCase		), encoder_inputs_mask