


'''simple docstring'''





from math import ceil
from typing import List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, spectrogram, window_function
from ...feature_extraction_sequence_utils import BatchFeature, SequenceFeatureExtractor
from ...utils import TensorType, logging


__lowerCamelCase												=						logging.get_logger(__name__)




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					["audio_values", "audio_mask"]


 def __init__(      self							:	str			,       __lowerCamelCase							:	Optional[Any]=2_0_4_8			,       __lowerCamelCase							:	Union[str, Any]=1			,       __lowerCamelCase							:	Dict=[1_6, 1_6]			,       __lowerCamelCase							:	Optional[Any]=1_2_8			,       __lowerCamelCase							:	Optional[Any]=4_4_1_0_0			,       __lowerCamelCase							:	Union[str, Any]=8_6			,       __lowerCamelCase							:	List[str]=2_0_4_8			,       __lowerCamelCase							:	str=0.0			,       **__lowerCamelCase							:	str			,       ):
    super().__init__(
        feature_size=__lowerCamelCase			,       sampling_rate=__lowerCamelCase			,       padding_value=__lowerCamelCase			,       **__lowerCamelCase			,       )

    UpperCAmelCase__	:Optional[Any]      =      spectrogram_length
    UpperCAmelCase__	:int      =      num_channels
    UpperCAmelCase__	:Union[str, Any]      =      patch_size
    UpperCAmelCase__	:List[Any]      =      feature_size // self.patch_size[1]
    UpperCAmelCase__	:Tuple      =      n_fft
    UpperCAmelCase__	:List[Any]      =      sampling_rate // hop_length_to_sampling_rate
    UpperCAmelCase__	:Optional[Any]      =      sampling_rate
    UpperCAmelCase__	:Dict      =      padding_value
    UpperCAmelCase__	:str      =      mel_filter_bank(
        num_frequency_bins=1 + n_fft // 2			,       num_mel_filters=__lowerCamelCase			,       min_frequency=0.0			,       max_frequency=2_20_50.0			,       sampling_rate=__lowerCamelCase			,       norm='''slaney'''			,       mel_scale='''slaney'''			,       ).T


 def        __SCREAMING_SNAKE_CASE					(      self							:	Any			,       __lowerCamelCase							:	np.array ):
    UpperCAmelCase__	:str      =      spectrogram(
        __lowerCamelCase			,       window_function(self.n_fft			,       '''hann''' )			,       frame_length=self.n_fft			,       hop_length=self.hop_length			,       power=2.0			,       mel_filters=self.mel_filters.T			,       log_mel='''dB'''			,       db_range=80.0			,       )
    UpperCAmelCase__	:Optional[int]      =      log_spec[:, :-1]
    UpperCAmelCase__	:str      =      log_spec - 20.0
    UpperCAmelCase__	:Optional[Any]      =      np.clip(log_spec / 40.0			,       -2.0			,       0.0 ) + 1.0
    return log_spec





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

    if sampling_rate is not None:
       if sampling_rate != self.sampling_rate:
          raise ValueError(
              '''This feature extractor is set to support sampling rate'''
              f''' of {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled'''
              f''' with {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__	:Dict      =      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}''' )
    UpperCAmelCase__	:List[Any]      =      is_batched_numpy or (
        isinstance(__lowerCamelCase			,       (list, tuple) ) and (isinstance(raw_speech[0]			,       (np.ndarray, tuple, list) ))
    )
    if is_batched:
       UpperCAmelCase__	:List[Any]      =      [np.asarray([speech]			,       dtype=np.floataa ).T for speech in raw_speech]
    elif not is_batched and not isinstance(__lowerCamelCase			,       np.ndarray ):
       UpperCAmelCase__	:Dict      =      np.asarray(__lowerCamelCase			,       dtype=np.floataa )
    elif isinstance(__lowerCamelCase			,       np.ndarray ) and raw_speech.dtype is np.dtype(np.floataa ):
       UpperCAmelCase__	:str      =      raw_speech.astype(np.floataa )
    # always return batch
    if not is_batched:
       UpperCAmelCase__	:List[Any]      =      [np.asarray([raw_speech] ).T]

    # Convert audio signals to log mel spectrograms, truncate by time axis
    UpperCAmelCase__	:Union[str, Any]      =      [
        self._np_extract_fbank_features(waveform.squeeze() ).T[: self.spectrogram_length] for waveform in raw_speech
    ]
    if isinstance(audio_features[0]			,       __lowerCamelCase ):
       UpperCAmelCase__	:str      =      [np.asarray(__lowerCamelCase			,       dtype=np.floataa ) for feature in audio_features]

    # Create audio attention mask
    UpperCAmelCase__	:Dict      =      max(
        [ceil(feature.shape[0] / self.patch_size[0] ) * self.freq_len for feature in audio_features] )  # The maximum number of audio patches in a batch
    if return_attention_mask:
       UpperCAmelCase__	:str      =      [
           (ceil(feature.shape[0] / self.patch_size[0] ) * self.freq_len) * [1]
           + (max_patch_len - ceil(feature.shape[0] / self.patch_size[0] ) * self.freq_len) * [0]
           for feature in audio_features
       ]
       UpperCAmelCase__	:Tuple      =      np.array(__lowerCamelCase ).astype(np.floataa )

    # convert into correct format for padding
    UpperCAmelCase__	:List[Any]      =      max_patch_len // self.freq_len * self.patch_size[0]  # The maximum audio size in a batch
    UpperCAmelCase__	:str      =      np.ones([len(__lowerCamelCase ), 1, max_time_len, self.feature_size] ).astype(np.floataa )
    UpperCAmelCase__	:Union[str, Any]      =      padded_audio_features * self.padding_value
    for i in range(len(__lowerCamelCase ) ):
       UpperCAmelCase__	:Optional[Any]      =      audio_features[i]
       UpperCAmelCase__	:Tuple      =      feature

    # return as BatchFeature
    if return_attention_mask:
       UpperCAmelCase__	:Union[str, Any]      =      {'''audio_values''': padded_audio_features, '''audio_mask''': audio_mask}
    else:
       UpperCAmelCase__	:List[Any]      =      {'''audio_values''': padded_audio_features}

    UpperCAmelCase__	:Dict      =      BatchFeature(data=__lowerCamelCase			,       tensor_type=__lowerCamelCase )
    return encoded_inputs







'''simple docstring'''





from functools import reduce

__lowerCamelCase												=						(
    '''73167176531330624919225119674426574742355349194934'''
    '''96983520312774506326239578318016984801869478851843'''
    '''85861560789112949495459501737958331952853208805511'''
    '''12540698747158523863050715693290963295227443043557'''
    '''66896648950445244523161731856403098711121722383113'''
    '''62229893423380308135336276614282806444486645238749'''
    '''30358907296290491560440772390713810515859307960866'''
    '''70172427121883998797908792274921901699720888093776'''
    '''65727333001053367881220235421809751254540594752243'''
    '''52584907711670556013604839586446706324415722155397'''
    '''53697817977846174064955149290862569321978468622482'''
    '''83972241375657056057490261407972968652414535100474'''
    '''82166370484403199890008895243450658541227588666881'''
    '''16427171479924442928230863465674813919123162824586'''
    '''17866458359124566529476545682848912883142607690042'''
    '''24219022671055626321111109370544217506941658960408'''
    '''07198403850962455444362981230987879927244284909188'''
    '''84580156166097919133875499200524063689912560717606'''
    '''05886116467109405077541002256983155200055935729725'''
    '''71636269561882670428252483600823257530420752963450'''
)


def        a__     (					UpperCamelCase_						:      str = N						):
   return max(
       # mypy cannot properly interpret reduce
       int(reduce(lambda UpperCamelCase_,   UpperCamelCase_						: str(int(UpperCamelCase_						) * int(UpperCamelCase_						)						),   n[i : i + 13]						)						)
       for i in range(len(UpperCamelCase_						) - 12						)						)


if __name__ == "__main__":
    print(F'''{solution() = }''')



