code: def rescale(
      waveforms, lengths, target_lvl, amp_type="avg", scale="linear"
  ):
      """This functions performs signal rescaling to a target level.
  
      Arguments
      ---------
      waveforms : tensor
          The waveforms to normalize.
          Shape should be `[batch, time]` or `[batch, time, channels]`.
      lengths : tensor
          The lengths of the waveforms excluding the padding.
          Shape should be a single dimension, `[batch]`.
      target_lvl : float
          Target lvl in dB or linear scale.
      amp_type : str
          Whether one wants to rescale with respect to "avg" or "peak" amplitude.
          Choose between ["avg", "peak"].
      scale : str
          whether target_lvl belongs to linear or dB scale.
          Choose between ["linear", "dB"].
  
      Returns
      -------
      waveforms : tensor
          Rescaled waveforms.
      """
  
      assert amp_type in ["peak", "avg"]
      assert scale in ["linear", "dB"]
  
      batch_added = False
      if len(waveforms.shape) == 1:
          batch_added = True
          waveforms = waveforms.unsqueeze(0)
  
      waveforms = normalize(waveforms, lengths, amp_type)
  
      if scale == "linear":
          out = target_lvl * waveforms
      elif scale == "dB":
          out = dB_to_amplitude(target_lvl) * waveforms
  
      else:
          raise NotImplementedError(
              "Invalid scale, choose between dB and linear"
          )
  
      if batch_added:
          out = out.squeeze(0)
  
      return out
  
file_path: speechbrain/speechbrain/processing/signal_processing.py
imports: import torch
  import math
  from packaging import version
label_desc: Use image node_id 4 for calling a global function with example usage: rescale(waveforms, lengths, target_lvl, amp_type, scale) and returns: out