class_docstr: Compress the audio using an MP3 encoder to lower the audio quality.
  This may help machine learning models deal with compressed, low-quality audio.
  
  This transform depends on either lameenc or pydub/ffmpeg.
  
  Note that bitrates below 32 kbps are only supported for low sample rates (up to 24000 Hz).
  
  Note: When using the lameenc backend, the output may be slightly longer than the input due
  to the fact that the LAME encoder inserts some silence at the beginning of the audio.
  
  Warning: This transform writes to disk, so it may be slow. Ideally, the work should be done
  in memory. Contributions are welcome.
class_docstr_tok: ["Compress","the","audio","using","an","MP3","encoder","to","lower","the","audio","quality",".","This","may","help","machine","learning","models","deal","with","compressed",",","low-quality","audio",".","This","transform","depends","on","either","lameenc","or","pydub\/ffmpeg",".","Note","that","bitrates","below","32","kbps","are","only","supported","for","low","sample","rates","(","up","to","24000","Hz",")",".","Note",":","When","using","the","lameenc","backend",",","the","output","may","be","slightly","longer","than","the","input","due","to","the","fact","that","the","LAME","encoder","inserts","some","silence","at","the","beginning","of","the","audio",".","Warning",":","This","transform","writes","to","disk",",","so","it","may","be","slow",".","Ideally",",","the","work","should","be","done","in","memory",".","Contributions","are","welcome","."]
docstr: :param min_bitrate: Minimum bitrate in kbps
  :param max_bitrate: Maximum bitrate in kbps
  :param backend: "pydub" or "lameenc".
      Pydub may use ffmpeg under the hood.
          Pros: Seems to avoid introducing latency in the output.
          Cons: Slower than lameenc.
      lameenc:
          Pros: You can set the quality parameter in addition to bitrate.
          Cons: Seems to introduce some silence at the start of the audio.
  :param p: The probability of applying this transform
docstr_tok: [":","param","min_bitrate",":","Minimum","bitrate","in","kbps",":","param","max_bitrate",":","Maximum","bitrate","in","kbps",":","param","backend",":","``","pydub","''","or","``","lameenc","''",".","Pydub","may","use","ffmpeg","under","the","hood",".","Pros",":","Seems","to","avoid","introducing","latency","in","the","output",".","Cons",":","Slower","than","lameenc",".","lameenc",":","Pros",":","You","can","set","the","quality","parameter","in","addition","to","bitrate",".","Cons",":","Seems","to","introduce","some","silence","at","the","start","of","the","audio",".",":","param","p",":","The","probability","of","applying","this","transform"]
code: def __init__(
      self,
      min_bitrate: int = 8,
      max_bitrate: int = 64,
      backend: str = "pydub",
      p: float = 0.5,
  ):
      """
      :param min_bitrate: Minimum bitrate in kbps
      :param max_bitrate: Maximum bitrate in kbps
      :param backend: "pydub" or "lameenc".
          Pydub may use ffmpeg under the hood.
              Pros: Seems to avoid introducing latency in the output.
              Cons: Slower than lameenc.
          lameenc:
              Pros: You can set the quality parameter in addition to bitrate.
              Cons: Seems to introduce some silence at the start of the audio.
      :param p: The probability of applying this transform
      """
      super().__init__(p)
      if min_bitrate < self.SUPPORTED_BITRATES[0]:
          raise ValueError(
              "min_bitrate must be greater than or equal to"
              f" {self.SUPPORTED_BITRATES[0]}"
          )
      if max_bitrate > self.SUPPORTED_BITRATES[-1]:
          raise ValueError(
              "max_bitrate must be less than or equal to"
              f" {self.SUPPORTED_BITRATES[-1]}"
          )
      if max_bitrate < min_bitrate:
          raise ValueError("max_bitrate must be >= min_bitrate")
  
      is_any_supported_bitrate_in_range = any(
          min_bitrate <= bitrate <= max_bitrate
          for bitrate in self.SUPPORTED_BITRATES
      )
      if not is_any_supported_bitrate_in_range:
          raise ValueError(
              "There is no supported bitrate in the range between the specified"
              " min_bitrate and max_bitrate. The supported bitrates are:"
              f" {self.SUPPORTED_BITRATES}"
          )
  
      self.min_bitrate = min_bitrate
      self.max_bitrate = max_bitrate
      if backend not in ("pydub", "lameenc"):
          raise ValueError(
              'backend must be set to either "pydub" or "lameenc"'
          )
      self.backend = backend
      self.post_gain_factor = None
  
file_path: audiomentations/audiomentations/augmentations/mp3_compression.py
imports: import os
  import random
  import tempfile
  import uuid
  import librosa
  import numpy
  import sys
  from numpy.typing import NDArray
  from audiomentations.core.transforms_interface import BaseWaveformTransform
  from audiomentations.core.utils import convert_float_samples_to_int16, get_max_abs_amplitude
label_desc: Use image node_id 1 to create a new Mp3Compression object from inherited base classes: BaseWaveformTransform with example: obj = Mp3Compression(min_bitrate, max_bitrate, backend, p)