'''simple docstring'''




from typing import List, Optional, Union

import numpy as np

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


_UpperCamelCase				:		Any       			=		logging.get_logger(__name__)

class   _lowercase(     _lowerCamelCase				):



   """simple docstring"""





   __lowerCamelCase    =  ['''input_values''', '''attention_mask''']





   def __init__(							self:    int			,a:    Any=1			,a:    Optional[Any]=16000			,a:    Optional[Any]=0.0			,a:    Optional[int]=False			,a:    Dict=True			,**a:    Optional[Any]			,):
    super().__init__(feature_size=a			,sampling_rate=a			,padding_value=a			,**a	)
    __UpperCAmelCase         =					return_attention_mask
    __UpperCAmelCase         =					do_normalize





   @staticmethod
   def 			snake_case	(							a:    List[np.ndarray]			,a:    List[np.ndarray]			,a:    float = 0.0	):
    if attention_mask is not None:
     __UpperCAmelCase         =					np.array(a			,np.intaa	)
     __UpperCAmelCase         =					[]

     for vector, length in zip(a			,attention_mask.sum(-1	)	):
      __UpperCAmelCase         =					(vector - vector[:length].mean()) / np.sqrt(vector[:length].var() + 1e-7	)
      if length < normed_slice.shape[0]:
       __UpperCAmelCase         =					padding_value

      normed_input_values.append(a	)
    else:
     __UpperCAmelCase         =					[(x - x.mean()) / np.sqrt(x.var() + 1e-7	) for x in input_values]

    return normed_input_values





   def __call__(							self:    Optional[int]			,a:    Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]			,a:    Union[bool, str, PaddingStrategy] = False			,a:    Optional[int] = None			,a:    bool = False			,a:    Optional[int] = None			,a:    Optional[bool] = None			,a:    Optional[Union[str, TensorType]] = None			,a:    Optional[int] = None			,**a:    Tuple			,):

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

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

    # convert into correct format for padding
    __UpperCAmelCase         =					BatchFeature({'input_values': raw_speech}	)

    __UpperCAmelCase         =					self.pad(
        a			,padding=a			,max_length=a			,truncation=a			,pad_to_multiple_of=a			,return_attention_mask=a			,)

    # convert input values to correct format
    __UpperCAmelCase         =					padded_inputs['input_values']
    if not isinstance(input_values[0]			,np.ndarray	):
     __UpperCAmelCase         =					[np.asarray(a			,dtype=np.floataa	) for array in input_values]
    elif (
        not isinstance(a			,np.ndarray	)
        and isinstance(input_values[0]			,np.ndarray	)
        and input_values[0].dtype is np.dtype(np.floataa	)
    ):
     __UpperCAmelCase         =					[array.astype(np.floataa	) for array in input_values]
    elif isinstance(a			,np.ndarray	) and input_values.dtype is np.dtype(np.floataa	):
     __UpperCAmelCase         =					input_values.astype(np.floataa	)

    # convert attention_mask to correct format
    __UpperCAmelCase         =					padded_inputs.get('attention_mask'	)
    if attention_mask is not None:
     __UpperCAmelCase         =					[np.asarray(a			,dtype=np.intaa	) for array in attention_mask]

    # zero-mean and unit-variance normalization
    if self.do_normalize:
     __UpperCAmelCase         =					(
         attention_mask
         if self._get_padding_strategies(a			,max_length=a	) is not PaddingStrategy.DO_NOT_PAD
         else None
     )
     __UpperCAmelCase         =					self.zero_mean_unit_var_norm(
         padded_inputs['input_values']			,attention_mask=a			,padding_value=self.padding_value	)

    if return_tensors is not None:
     __UpperCAmelCase         =					padded_inputs.convert_to_tensors(a	)

    return padded_inputs




'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_UpperCamelCase				:		int       			=		{
    'configuration_align': [
        'ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'AlignConfig',
        'AlignTextConfig',
        'AlignVisionConfig',
    ],
    'processing_align': ['AlignProcessor'],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _UpperCamelCase				:		Optional[Any]       			=		[
         'ALIGN_PRETRAINED_MODEL_ARCHIVE_LIST',
         'AlignModel',
         'AlignPreTrainedModel',
         'AlignTextModel',
         'AlignVisionModel',
     ]

if TYPE_CHECKING:
     from .configuration_align import (
         ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP,
         AlignConfig,
         AlignTextConfig,
         AlignVisionConfig,
     )
     from .processing_align import AlignProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_align import (
              ALIGN_PRETRAINED_MODEL_ARCHIVE_LIST,
              AlignModel,
              AlignPreTrainedModel,
              AlignTextModel,
              AlignVisionModel,
          )

else:
     import sys

     _UpperCamelCase				:		str       			=		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



