code: 
  
  
  
  
  
  
  from typing import Dict, List, Optional, Union
  
  import numpy as np
  
  from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
  from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
  from ...image_utils import (
      IMAGENET_STANDARD_MEAN,
      IMAGENET_STANDARD_STD,
      ChannelDimension,
      ImageInput,
      PILImageResampling,
      make_list_of_images,
      to_numpy_array,
      valid_images,
  )
  from ...utils import TensorType, is_vision_available, logging
  
  
  if is_vision_available():
   import PIL
  
  
  lowerCamelCase			:							Union[str, Any]       =logging.get_logger(__name__)
  
  
  
  
  
  class     __a						(					A__ ):
   _lowerCAmelCase : str 				=				['''pixel_values''']
  
  
  
  
  
  
  
   def __init__(	self      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     bool = True							,     SCREAMING_SNAKE_CASE      :     Dict[str, int] = None							,     SCREAMING_SNAKE_CASE      :     PILImageResampling = PIL.Image.NEAREST							,     SCREAMING_SNAKE_CASE      :     bool = False							,     SCREAMING_SNAKE_CASE      :     Dict[str, int] = None							,     SCREAMING_SNAKE_CASE      :     Union[int, float] = 1 / 2_55							,     SCREAMING_SNAKE_CASE      :     bool = False							,     SCREAMING_SNAKE_CASE      :     bool = True							,     SCREAMING_SNAKE_CASE      :     bool = True							,     SCREAMING_SNAKE_CASE      :     Optional[Union[float, List[float]]] = None							,     SCREAMING_SNAKE_CASE      :     Optional[Union[float, List[float]]] = None							,     SCREAMING_SNAKE_CASE      :     bool = True							,     **SCREAMING_SNAKE_CASE      :     List[Any]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        super().__init__(**SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     List[str]        =						size if size is not None else {"height": 3_46, "width": 3_46}
        UpperCamelCase__    :     Dict        =						get_size_dict(SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Optional[int]        =						crop_size if crop_size is not None else {"height": 2_89, "width": 2_89}
        UpperCamelCase__    :     Union[str, Any]        =						get_size_dict(SCREAMING_SNAKE_CASE							,     param_name="crop_size"		)
  
        UpperCamelCase__    :     Tuple        =						do_resize
        UpperCamelCase__    :     Any        =						size
        UpperCamelCase__    :     str        =						resample
        UpperCamelCase__    :     Union[str, Any]        =						do_center_crop
        UpperCamelCase__    :     List[str]        =						crop_size
        UpperCamelCase__    :     List[Any]        =						do_rescale
        UpperCamelCase__    :     Dict        =						rescale_factor
        UpperCamelCase__    :     Optional[Any]        =						rescale_offset
        UpperCamelCase__    :     Dict        =						do_normalize
        UpperCamelCase__    :     List[Any]        =						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        UpperCamelCase__    :     Optional[Any]        =						image_std if image_std is not None else IMAGENET_STANDARD_STD
        UpperCamelCase__    :     List[Any]        =						include_top
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str							,     SCREAMING_SNAKE_CASE      :     np.ndarray							,     SCREAMING_SNAKE_CASE      :     Dict[str, int]							,     SCREAMING_SNAKE_CASE      :     PILImageResampling = PIL.Image.NEAREST							,     SCREAMING_SNAKE_CASE      :     Optional[Union[str, ChannelDimension]] = None							,     **SCREAMING_SNAKE_CASE      :     Optional[int]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[int]        =						get_size_dict(SCREAMING_SNAKE_CASE		)
        if "height" not in size or "width" not in size:
             raise ValueError(F'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'		)
        return resize(
            SCREAMING_SNAKE_CASE							,     size=(size["height"], size["width"])							,     resample=SCREAMING_SNAKE_CASE							,     data_format=SCREAMING_SNAKE_CASE							,     **SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int							,     SCREAMING_SNAKE_CASE      :     np.ndarray							,     SCREAMING_SNAKE_CASE      :     Dict[str, int]							,     SCREAMING_SNAKE_CASE      :     Optional[Union[str, ChannelDimension]] = None							,     **SCREAMING_SNAKE_CASE      :     Dict							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						get_size_dict(SCREAMING_SNAKE_CASE		)
        if "height" not in size or "width" not in size:
             raise ValueError(F'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'		)
        return center_crop(SCREAMING_SNAKE_CASE							,     size=(size["height"], size["width"])							,     data_format=SCREAMING_SNAKE_CASE							,     **SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[Any]							,     SCREAMING_SNAKE_CASE      :     np.ndarray							,     SCREAMING_SNAKE_CASE      :     Union[int, float]							,     SCREAMING_SNAKE_CASE      :     bool = True							,     SCREAMING_SNAKE_CASE      :     Optional[Union[str, ChannelDimension]] = None							,     **SCREAMING_SNAKE_CASE      :     List[Any]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        if offset:
             UpperCamelCase__    :     Optional[Any]        =						(image - 1_2_7.5) * scale
             if data_format is not None:
                  UpperCamelCase__    :     int        =						to_channel_dimension_format(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Any        =						rescaled_image.astype(np.floataa		)
        else:
             UpperCamelCase__    :     str        =						rescale(SCREAMING_SNAKE_CASE							,     scale=SCREAMING_SNAKE_CASE							,     data_format=SCREAMING_SNAKE_CASE							,     **SCREAMING_SNAKE_CASE		)
        return rescaled_image
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Dict							,     SCREAMING_SNAKE_CASE      :     np.ndarray							,     SCREAMING_SNAKE_CASE      :     Union[float, List[float]]							,     SCREAMING_SNAKE_CASE      :     Union[float, List[float]]							,     SCREAMING_SNAKE_CASE      :     Optional[Union[str, ChannelDimension]] = None							,     **SCREAMING_SNAKE_CASE      :     str							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return normalize(SCREAMING_SNAKE_CASE							,     mean=SCREAMING_SNAKE_CASE							,     std=SCREAMING_SNAKE_CASE							,     data_format=SCREAMING_SNAKE_CASE							,     **SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int							,     SCREAMING_SNAKE_CASE      :     ImageInput							,     SCREAMING_SNAKE_CASE      :     bool = None							,     SCREAMING_SNAKE_CASE      :     Dict[str, int] = None							,     SCREAMING_SNAKE_CASE      :     Any=None							,     SCREAMING_SNAKE_CASE      :     bool = None							,     SCREAMING_SNAKE_CASE      :     Dict[str, int] = None							,     SCREAMING_SNAKE_CASE      :     bool = None							,     SCREAMING_SNAKE_CASE      :     float = None							,     SCREAMING_SNAKE_CASE      :     bool = None							,     SCREAMING_SNAKE_CASE      :     bool = None							,     SCREAMING_SNAKE_CASE      :     Optional[Union[float, List[float]]] = None							,     SCREAMING_SNAKE_CASE      :     Optional[Union[float, List[float]]] = None							,     SCREAMING_SNAKE_CASE      :     bool = None							,     SCREAMING_SNAKE_CASE      :     Optional[Union[str, TensorType]] = None							,     SCREAMING_SNAKE_CASE      :     ChannelDimension = ChannelDimension.FIRST							,     **SCREAMING_SNAKE_CASE      :     Tuple							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						do_resize if do_resize is not None else self.do_resize
        UpperCamelCase__    :     List[str]        =						resample if resample is not None else self.resample
        UpperCamelCase__    :     str        =						do_center_crop if do_center_crop is not None else self.do_center_crop
        UpperCamelCase__    :     Any        =						do_rescale if do_rescale is not None else self.do_rescale
        UpperCamelCase__    :     int        =						rescale_factor if rescale_factor is not None else self.rescale_factor
        UpperCamelCase__    :     Tuple        =						rescale_offset if rescale_offset is not None else self.rescale_offset
        UpperCamelCase__    :     Any        =						do_normalize if do_normalize is not None else self.do_normalize
        UpperCamelCase__    :     Any        =						image_mean if image_mean is not None else self.image_mean
        UpperCamelCase__    :     List[Any]        =						image_std if image_std is not None else self.image_std
        UpperCamelCase__    :     int        =						include_top if include_top is not None else self.include_top
  
        UpperCamelCase__    :     Optional[int]        =						size if size is not None else self.size
        UpperCamelCase__    :     int        =						get_size_dict(SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Optional[int]        =						crop_size if crop_size is not None else self.crop_size
        UpperCamelCase__    :     Dict        =						get_size_dict(SCREAMING_SNAKE_CASE							,     param_name="crop_size"		)
  
        UpperCamelCase__    :     int        =						make_list_of_images(SCREAMING_SNAKE_CASE		)
  
        if not valid_images(SCREAMING_SNAKE_CASE		):
             raise ValueError(
                 "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
                 "torch.Tensor, tf.Tensor or jax.ndarray."		)
  
        if do_resize and size is None or resample is None:
             raise ValueError("Size and resample must be specified if do_resize is True."		)
  
        if do_center_crop and crop_size is None:
             raise ValueError("Crop size must be specified if do_center_crop is True."		)
  
        if do_rescale and rescale_factor is None:
             raise ValueError("Rescale factor must be specified if do_rescale is True."		)
  
        if do_normalize and (image_mean is None or image_std is None):
             raise ValueError("Image mean and std must be specified if do_normalize is True."		)
  
        # All transformations expect numpy arrays.
        UpperCamelCase__    :     List[str]        =						[to_numpy_array(SCREAMING_SNAKE_CASE		) for image in images]
  
        if do_resize:
             UpperCamelCase__    :     int        =						[self.resize(image=SCREAMING_SNAKE_CASE							,     size=SCREAMING_SNAKE_CASE							,     resample=SCREAMING_SNAKE_CASE		) for image in images]
  
        if do_center_crop:
             UpperCamelCase__    :     List[Any]        =						[self.center_crop(image=SCREAMING_SNAKE_CASE							,     size=SCREAMING_SNAKE_CASE		) for image in images]
  
        if do_rescale:
             UpperCamelCase__    :     str        =						[self.rescale(image=SCREAMING_SNAKE_CASE							,     scale=SCREAMING_SNAKE_CASE							,     offset=SCREAMING_SNAKE_CASE		) for image in images]
  
        if do_normalize:
             UpperCamelCase__    :     Any        =						[self.normalize(image=SCREAMING_SNAKE_CASE							,     mean=SCREAMING_SNAKE_CASE							,     std=SCREAMING_SNAKE_CASE		) for image in images]
  
        if include_top:
             UpperCamelCase__    :     str        =						[self.normalize(image=SCREAMING_SNAKE_CASE							,     mean=[0, 0, 0]							,     std=SCREAMING_SNAKE_CASE		) for image in images]
  
        UpperCamelCase__    :     List[Any]        =						[to_channel_dimension_format(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		) for image in images]
  
        UpperCamelCase__    :     List[Any]        =						{"pixel_values": images}
        return BatchFeature(data=SCREAMING_SNAKE_CASE							,     tensor_type=SCREAMING_SNAKE_CASE		)
style_context: 
  
  
  
  
  
  
  import numpy as np  # noqa: E402
  
  from ...configuration_utils import ConfigMixin, register_to_config
  from ...schedulers.scheduling_utils import SchedulerMixin
  
  
  try:
   import librosa  # noqa: E402
  
   lowerCamelCase			:							List[str]       =True
   lowerCamelCase			:							Dict       =''''''
  except Exception as e:
   lowerCamelCase			:							str       =False
   lowerCamelCase			:							List[Any]       =(
       F"""Cannot import librosa because {e}. Make sure to correctly install librosa to be able to install it."""
   )
  
  
  from PIL import Image  # noqa: E402
  
  
  
  
  
  class     __a						(					A__ ,     A__ ):
   _lowerCAmelCase : Optional[Any] 				=				'''mel_config.json'''
  
  
  
  
  
  
  
   @register_to_config
   def __init__(	self      :     Any							,     SCREAMING_SNAKE_CASE      :     int = 2_56							,     SCREAMING_SNAKE_CASE      :     int = 2_56							,     SCREAMING_SNAKE_CASE      :     int = 2_20_50							,     SCREAMING_SNAKE_CASE      :     int = 20_48							,     SCREAMING_SNAKE_CASE      :     int = 5_12							,     SCREAMING_SNAKE_CASE      :     int = 80							,     SCREAMING_SNAKE_CASE      :     int = 32							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     str        =						hop_length
        UpperCamelCase__    :     Optional[Any]        =						sample_rate
        UpperCamelCase__    :     Dict        =						n_fft
        UpperCamelCase__    :     str        =						top_db
        UpperCamelCase__    :     Optional[Any]        =						n_iter
        self.set_resolution(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     str        =						None
  
        if not _librosa_can_be_imported:
             raise ValueError(_import_error		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple							,     SCREAMING_SNAKE_CASE      :     int							,     SCREAMING_SNAKE_CASE      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Dict        =						x_res
        UpperCamelCase__    :     Dict        =						y_res
        UpperCamelCase__    :     Dict        =						self.y_res
        UpperCamelCase__    :     Any        =						self.x_res * self.hop_length - 1
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str							,     SCREAMING_SNAKE_CASE      :     str = None							,     SCREAMING_SNAKE_CASE      :     np.ndarray = None		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        if audio_file is not None:
             UpperCamelCase__       ,  UpperCamelCase__    :     int        =						librosa.load(SCREAMING_SNAKE_CASE							,     mono=SCREAMING_SNAKE_CASE							,     sr=self.sr		)
        else:
             UpperCamelCase__    :     List[Any]        =						raw_audio
  
        # Pad with silence if necessary.
        if len(self.audio		) < self.x_res * self.hop_length:
             UpperCamelCase__    :     List[Any]        =						np.concatenate([self.audio, np.zeros((self.x_res * self.hop_length - len(self.audio		),)		)]		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return len(self.audio		) // self.slice_size
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int							,     SCREAMING_SNAKE_CASE      :     int = 0		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return self.audio[self.slice_size * slice : self.slice_size * (slice + 1)]
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return self.sr
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[int]        =						librosa.feature.melspectrogram(
            y=self.get_audio_slice(SCREAMING_SNAKE_CASE		)							,     sr=self.sr							,     n_fft=self.n_fft							,     hop_length=self.hop_length							,     n_mels=self.n_mels		)
        UpperCamelCase__    :     Tuple        =						librosa.power_to_db(SCREAMING_SNAKE_CASE							,     ref=np.max							,     top_db=self.top_db		)
        UpperCamelCase__    :     Optional[Any]        =						(((log_S + self.top_db) * 2_55 / self.top_db).clip(0							,     2_55		) + 0.5).astype(np.uinta		)
        UpperCamelCase__    :     Optional[Any]        =						Image.fromarray(SCREAMING_SNAKE_CASE		)
        return image
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     Image.Image		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						np.frombuffer(image.tobytes()							,     dtype="uint8"		).reshape((image.height, image.width)		)
        UpperCamelCase__    :     str        =						bytedata.astype("float"		) * self.top_db / 2_55 - self.top_db
        UpperCamelCase__    :     Any        =						librosa.db_to_power(SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Tuple        =						librosa.feature.inverse.mel_to_audio(
            SCREAMING_SNAKE_CASE							,     sr=self.sr							,     n_fft=self.n_fft							,     hop_length=self.hop_length							,     n_iter=self.n_iter		)
        return audio