class_docstr: This class additively combines a noise signal to the input signal.
  
  Arguments
  ---------
  csv_file : str
      The name of a csv file containing the location of the
      noise audio files. If none is provided, white noise will be used.
  csv_keys : list, None, optional
      Default: None . One data entry for the noise data should be specified.
      If None, the csv file is expected to have only one data entry.
  sorting : str
      The order to iterate the csv file, from one of the
      following options: random, original, ascending, and descending.
  num_workers : int
      Number of workers in the DataLoader (See PyTorch DataLoader docs).
  snr_low : int
      The low end of the mixing ratios, in decibels.
  snr_high : int
      The high end of the mixing ratios, in decibels.
  pad_noise : bool
      If True, copy noise signals that are shorter than
      their corresponding clean signals so as to cover the whole clean
      signal. Otherwise, leave the noise un-padded.
  start_index : int
      The index in the noise waveforms to start from. By default, chooses
      a random index in [0, len(noise) - len(waveforms)].
  normalize : bool
      If True, output noisy signals that exceed [-1,1] will be
      normalized to [-1,1].
  noise_funct: funct object
      function to use to draw a noisy sample. It is enabled if the csv files
      containing the noisy sequences are not provided. By default,
      torch.randn_like is used (to sample white noise). In general, it must
      be a function that takes in input the original waveform and returns
      a tensor with the corresponsing noise to add (e.g., see pink_noise_like).
  replacements : dict
      A set of string replacements to carry out in the
      csv file. Each time a key is found in the text, it will be replaced
      with the corresponding value.
  noise_sample_rate : int
      The sample rate of the noise audio signals, so noise can be resampled
      to the clean sample rate if necessary.
  clean_sample_rate : int
      The sample rate of the clean audio signals, so noise can be resampled
      to the clean sample rate if necessary.
  
  Example
  -------
  >>> import pytest
  >>> from speechbrain.dataio.dataio import read_audio
  >>> signal = read_audio('tests/samples/single-mic/example1.wav')
  >>> clean = signal.unsqueeze(0) # [batch, time, channels]
  >>> noisifier = AddNoise('tests/samples/annotation/noise.csv',
  ...                     replacements={'noise_folder': 'tests/samples/noise'})
  >>> noisy = noisifier(clean, torch.ones(1))
class_docstr_tok: ["This","class","additively","combines","a","noise","signal","to","the","input","signal",".","Arguments","--","--","--","--","-","csv_file",":","str","The","name","of","a","csv","file","containing","the","location","of","the","noise","audio","files",".","If","none","is","provided",",","white","noise","will","be","used",".","csv_keys",":","list",",","None",",","optional","Default",":","None",".","One","data","entry","for","the","noise","data","should","be","specified",".","If","None",",","the","csv","file","is","expected","to","have","only","one","data","entry",".","sorting",":","str","The","order","to","iterate","the","csv","file",",","from","one","of","the","following","options",":","random",",","original",",","ascending",",","and","descending",".","num_workers",":","int","Number","of","workers","in","the","DataLoader","(","See","PyTorch","DataLoader","docs",")",".","snr_low",":","int","The","low","end","of","the","mixing","ratios",",","in","decibels",".","snr_high",":","int","The","high","end","of","the","mixing","ratios",",","in","decibels",".","pad_noise",":","bool","If","True",",","copy","noise","signals","that","are","shorter","than","their","corresponding","clean","signals","so","as","to","cover","the","whole","clean","signal",".","Otherwise",",","leave","the","noise","un-padded",".","start_index",":","int","The","index","in","the","noise","waveforms","to","start","from",".","By","default",",","chooses","a","random","index","in","[","0",",","len","(","noise",")","-","len","(","waveforms",")","]",".","normalize",":","bool","If","True",",","output","noisy","signals","that","exceed","[","-1,1","]","will","be","normalized","to","[","-1,1","]",".","noise_funct",":","funct","object","function","to","use","to","draw","a","noisy","sample",".","It","is","enabled","if","the","csv","files","containing","the","noisy","sequences","are","not","provided",".","By","default",",","torch.randn_like","is","used","(","to","sample","white","noise",")",".","In","general",",","it","must","be","a","function","that","takes","in","input","the","original","waveform","and","returns","a","tensor","with","the","corresponsing","noise","to","add","(","e.g.",",","see","pink_noise_like",")",".","replacements",":","dict","A","set","of","string","replacements","to","carry","out","in","the","csv","file",".","Each","time","a","key","is","found","in","the","text",",","it","will","be","replaced","with","the","corresponding","value",".","noise_sample_rate",":","int","The","sample","rate","of","the","noise","audio","signals",",","so","noise","can","be","resampled","to","the","clean","sample","rate","if","necessary",".","clean_sample_rate",":","int","The","sample","rate","of","the","clean","audio","signals",",","so","noise","can","be","resampled","to","the","clean","sample","rate","if","necessary",".","Example","--","--","--","-",">",">",">","import","pytest",">",">",">","from","speechbrain.dataio.dataio","import","read_audio",">",">",">","signal","=","read_audio","(","'tests\/samples\/single-mic\/example1.wav","'",")",">",">",">","clean","=","signal.unsqueeze","(","0",")","#","[","batch",",","time",",","channels","]",">",">",">","noisifier","=","AddNoise","(","'tests\/samples\/annotation\/noise.csv","'",",","...","replacements=","{","'noise_folder","'",":","'tests\/samples\/noise","'","}",")",">",">",">","noisy","=","noisifier","(","clean",",","torch.ones","(","1",")",")"]
docstr: Arguments
  ---------
  waveforms : tensor
      Shape should be `[batch, time]` or `[batch, time, channels]`.
  lengths : tensor
      Shape should be a single dimension, `[batch]`.
  
  Returns
  -------
  Tensor of shape `[batch, time]` or `[batch, time, channels]`.
docstr_tok: ["Arguments","--","--","--","--","-","waveforms",":","tensor","Shape","should","be","`","[","batch",",","time","]","`","or","`","[","batch",",","time",",","channels","]","`",".","lengths",":","tensor","Shape","should","be","a","single","dimension",",","`","[","batch","]","`",".","Returns","--","--","--","-","Tensor","of","shape","`","[","batch",",","time","]","`","or","`","[","batch",",","time",",","channels","]","`","."]
code: def forward(self, waveforms, lengths):
      """
      Arguments
      ---------
      waveforms : tensor
          Shape should be `[batch, time]` or `[batch, time, channels]`.
      lengths : tensor
          Shape should be a single dimension, `[batch]`.
  
      Returns
      -------
      Tensor of shape `[batch, time]` or `[batch, time, channels]`.
      """
  
      # Copy clean waveform to initialize noisy waveform
      noisy_waveform = waveforms.clone()
      lengths = (lengths * waveforms.shape[1]).unsqueeze(1)
  
      # Compute the average amplitude of the clean waveforms
      clean_amplitude = compute_amplitude(
          waveforms, lengths, amp_type="rms"
      )
  
      # Pick an SNR and use it to compute the mixture amplitude factors
      SNR = torch.rand(len(waveforms), 1, device=waveforms.device)
      SNR = SNR * (self.snr_high - self.snr_low) + self.snr_low
      noise_amplitude_factor = 1 / (dB_to_amplitude(SNR) + 1)
  
      # Support for multichannel waveforms
      if len(noisy_waveform.shape) == 3:
          noise_amplitude_factor = noise_amplitude_factor.unsqueeze(1)
  
      # Scale clean signal appropriately
      new_noise_amplitude = noise_amplitude_factor * clean_amplitude
      noisy_waveform *= 1 - noise_amplitude_factor
  
      # Loop through clean samples and create mixture
      if self.csv_file is None:
          noise_waveform = self.noise_funct(waveforms)
          if noise_waveform.shape[0] == 1:
              noise_waveform = torch.cat(
                  [noise_waveform] * waveforms.shape[0], dim=0
              )
  
          noise_length = lengths
      else:
          tensor_length = waveforms.shape[1]
          noise_waveform, noise_length = self._load_noise(
              lengths, tensor_length
          )
  
      # Rescale and add
      noise_amplitude = compute_amplitude(
          noise_waveform, noise_length, amp_type="rms"
      )
      noise_waveform *= new_noise_amplitude / (noise_amplitude + 1e-14)
  
      noisy_waveform += noise_waveform
      # Normalizing to prevent clipping
      if self.normalize:
          abs_max, _ = torch.max(
              torch.abs(noisy_waveform), dim=1, keepdim=True
          )
          noisy_waveform = noisy_waveform / abs_max.clamp(min=1.0)
  
      return noisy_waveform
  
imports: import math
  import random
  import torch
  import torch.nn.functional
  from speechbrain.dataio.legacy import ExtendedCSVDataset
  from speechbrain.dataio.dataloader import make_dataloader
  from speechbrain.processing.signal_processing import compute_amplitude, dB_to_amplitude, convolve1d, notch_filter, reverberate
label_desc: Use image node_id 2 for calling the AddNoise obj's underlying member method code with example usage: obj.forward(waveforms, lengths) and returns: noisy_waveform