






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


snake_case__      :	int       	=      logging.get_logger(__name__)


class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  A_						=   ["""input_features""", """attention_mask"""]




  def __init__(     self		,		_UpperCAmelCase=80		,		_UpperCAmelCase=16000		,		_UpperCAmelCase=80		,		_UpperCAmelCase=0.0		,		_UpperCAmelCase=True		,		_UpperCAmelCase=True		,		_UpperCAmelCase=True		,		**_UpperCAmelCase		,		)			-> Optional[Any]:
     super().__init__(feature_size=_UpperCAmelCase		,		sampling_rate=_UpperCAmelCase		,		padding_value=_UpperCAmelCase		,		**_UpperCAmelCase )
     UpperCamelCase_									=     num_mel_bins
     UpperCamelCase_									=     do_ceptral_normalize
     UpperCamelCase_									=     normalize_means
     UpperCamelCase_									=     normalize_vars
     UpperCamelCase_									=     True




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		)			-> np.ndarray:
     UpperCamelCase_									=     waveform * (2**15)  # Kaldi compliance: 16-bit signed integers
     UpperCamelCase_									=     torch.from_numpy(_UpperCAmelCase ).unsqueeze(0 )
     UpperCamelCase_									=     ta_kaldi.fbank(_UpperCAmelCase		,		num_mel_bins=self.num_mel_bins		,		sample_frequency=self.sampling_rate )
     return features.numpy()




  @staticmethod
  def    _UpperCAmelCase     (     _UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase = True		,		_UpperCAmelCase = True		,		_UpperCAmelCase = 0.0		,		)			-> np.ndarray:
     # make sure we normalize float32 arrays
     if normalize_means:
        UpperCamelCase_									=     x[:input_length].mean(axis=0 )
        UpperCamelCase_									=     np.subtract(_UpperCAmelCase		,		_UpperCAmelCase )
     if normalize_vars:
        UpperCamelCase_									=     x[:input_length].std(axis=0 )
        UpperCamelCase_									=     np.divide(_UpperCAmelCase		,		_UpperCAmelCase )

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

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

     return x




  def    _UpperCAmelCase     (     self		,		_UpperCAmelCase		,		_UpperCAmelCase = None )			-> List[np.ndarray]:
     UpperCamelCase_									=     attention_mask.sum(-1 ) if attention_mask is not None else [x.shape[0] for x in input_features]
     return [
         self.utterance_cmvn(_UpperCAmelCase		,		_UpperCAmelCase		,		self.normalize_means		,		self.normalize_vars		,		self.padding_value )
         for x, n in zip(_UpperCAmelCase		,		_UpperCAmelCase )
     ]




  def __call__(     self		,		_UpperCAmelCase		,		_UpperCAmelCase = False		,		_UpperCAmelCase = None		,		_UpperCAmelCase = False		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		**_UpperCAmelCase		,		)			-> BatchFeature:

     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.' )

     UpperCamelCase_									=     isinstance(_UpperCAmelCase		,		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}""" )
     UpperCamelCase_									=     is_batched_numpy or (
         isinstance(_UpperCAmelCase		,		(list, tuple) ) and (isinstance(raw_speech[0]		,		(np.ndarray, tuple, list) ))
     )

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

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

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

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

     UpperCamelCase_									=     self.pad(
         _UpperCAmelCase		,		padding=_UpperCAmelCase		,		max_length=_UpperCAmelCase		,		truncation=_UpperCAmelCase		,		pad_to_multiple_of=_UpperCAmelCase		,		return_attention_mask=_UpperCAmelCase		,		**_UpperCAmelCase		,		)

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

     UpperCamelCase_									=     padded_inputs.get('attention_mask' )
     if attention_mask is not None:
        UpperCamelCase_									=     [np.asarray(_UpperCAmelCase		,		dtype=np.intaa ) for array in attention_mask]

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

     if return_tensors is not None:
        UpperCamelCase_									=     padded_inputs.convert_to_tensors(_UpperCAmelCase )

     return padded_inputs













import warnings

from ...utils import logging
from .image_processing_videomae import VideoMAEImageProcessor


snake_case__      :	List[str]       	=      logging.get_logger(__name__)


class 						_a       (  UpperCAmelCase__    ):






  """simple docstring"""





  def __init__(     self		,		*_UpperCAmelCase		,		**_UpperCAmelCase )			-> None:
     warnings.warn(
         'The class VideoMAEFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
         ' Please use VideoMAEImageProcessor instead.'		,		_UpperCAmelCase		,		)
     super().__init__(*_UpperCAmelCase		,		**_UpperCAmelCase )





