class_docstr: Mix in another sound, e.g. a background noise. Useful if your original sound is clean and
  you want to simulate an environment where background noise is present.
  Can also be used for mixup, as in https://arxiv.org/pdf/1710.09412.pdf
  A folder of (background noise) sounds to be mixed in must be specified. These sounds should
  ideally be at least as long as the input sounds to be transformed. Otherwise, the background
  sound will be repeated, which may sound unnatural.
  Note that the gain of the added noise is relative to the amount of signal in the input if the parameter noise_rms
  is set to "relative" (default option). This implies that if the input is completely silent, no noise will be added.
  Here are some examples of datasets that can be downloaded and used as background noise:
  * https://github.com/karolpiczak/ESC-50#download
  * https://github.com/microsoft/DNS-Challenge/
class_docstr_tok: ["Mix","in","another","sound",",","e.g",".","a","background","noise",".","Useful","if","your","original","sound","is","clean","and","you","want","to","simulate","an","environment","where","background","noise","is","present",".","Can","also","be","used","for","mixup",",","as","in","https",":","\/\/arxiv.org\/pdf\/1710.09412.pdf","A","folder","of","(","background","noise",")","sounds","to","be","mixed","in","must","be","specified",".","These","sounds","should","ideally","be","at","least","as","long","as","the","input","sounds","to","be","transformed",".","Otherwise",",","the","background","sound","will","be","repeated",",","which","may","sound","unnatural",".","Note","that","the","gain","of","the","added","noise","is","relative","to","the","amount","of","signal","in","the","input","if","the","parameter","noise_rms","is","set","to","``","relative","''","(","default","option",")",".","This","implies","that","if","the","input","is","completely","silent",",","no","noise","will","be","added",".","Here","are","some","examples","of","datasets","that","can","be","downloaded","and","used","as","background","noise",":","*","https",":","\/\/github.com\/karolpiczak\/ESC-50","#","download","*","https",":","\/\/github.com\/microsoft\/DNS-Challenge\/"]
code: def apply(self, samples: NDArray[np.float32], sample_rate: int):
      noise_sound, _ = self._load_sound(
          self.parameters["noise_file_path"], sample_rate
      )
      noise_sound = noise_sound[
          self.parameters["noise_start_index"] : self.parameters[
              "noise_end_index"
          ]
      ]
  
      if self.noise_transform:
          noise_sound = self.noise_transform(noise_sound, sample_rate)
  
      noise_rms = calculate_rms(noise_sound)
      if noise_rms < 1e-9:
          warnings.warn(
              "The file {} is too silent to be added as noise. Returning the input"
              " unchanged.".format(self.parameters["noise_file_path"])
          )
          return samples
  
      clean_rms = calculate_rms(samples)
  
      if self.noise_rms == "relative":
          desired_noise_rms = calculate_desired_noise_rms(
              clean_rms, self.parameters["snr_db"]
          )
  
          # Adjust the noise to match the desired noise RMS
          noise_sound = noise_sound * (desired_noise_rms / noise_rms)
  
      if self.noise_rms == "absolute":
          desired_noise_rms_db = self.parameters["rms_db"]
          desired_noise_rms_amp = convert_decibels_to_amplitude_ratio(
              desired_noise_rms_db
          )
          gain = desired_noise_rms_amp / noise_rms
          noise_sound = noise_sound * gain
  
      # Repeat the sound if it shorter than the input sound
      num_samples = len(samples)
      while len(noise_sound) < num_samples:
          noise_sound = np.concatenate((noise_sound, noise_sound))
  
      if len(noise_sound) > num_samples:
          noise_sound = noise_sound[0:num_samples]
  
      # Return a mix of the input sound and the background noise sound
      return samples + noise_sound
  
file_path: audiomentations/audiomentations/augmentations/add_background_noise.py
imports: import functools
  import random
  import warnings
  from pathlib import Path
  from typing import Optional, List, Callable, Union
  import numpy
  from numpy.typing import NDArray
  from audiomentations.core.audio_loading_utils import load_sound_file
  from audiomentations.core.transforms_interface import BaseWaveformTransform
  from audiomentations.core.utils import calculate_desired_noise_rms, calculate_rms, convert_decibels_to_amplitude_ratio, find_audio_files_in_paths
label_desc: Use image node_id 4 for calling the AddBackgroundNoise obj's underlying member method code with example usage: obj.apply(samples, sample_rate) and returns: unknown, samples