code: def normalize_audio(
      wav: torch.Tensor,
      normalize: bool = True,
      strategy: str = "peak",
      peak_clip_headroom_db: float = 1,
      rms_headroom_db: float = 18,
      loudness_headroom_db: float = 14,
      loudness_compressor: bool = False,
      log_clipping: bool = False,
      sample_rate: tp.Optional[int] = None,
      stem_name: tp.Optional[str] = None,
  ) -> torch.Tensor:
      """Normalize the audio according to the prescribed strategy (see after).
  
      Args:
          wav (torch.Tensor): Audio data.
          normalize (bool): if `True` (default), normalizes according to the prescribed
              strategy (see after). If `False`, the strategy is only used in case clipping
              would happen.
          strategy (str): Can be either 'clip', 'peak', or 'rms'. Default is 'peak',
              i.e. audio is normalized by its largest value. RMS normalizes by root-mean-square
              with extra headroom to avoid clipping. 'clip' just clips.
          peak_clip_headroom_db (float): Headroom in dB when doing 'peak' or 'clip' strategy.
          rms_headroom_db (float): Headroom in dB when doing 'rms' strategy. This must be much larger
              than the `peak_clip` one to avoid further clipping.
          loudness_headroom_db (float): Target loudness for loudness normalization.
          loudness_compressor (bool): If True, uses tanh based soft clipping.
          log_clipping (bool): If True, basic logging on stderr when clipping still
              occurs despite strategy (only for 'rms').
          sample_rate (int): Sample rate for the audio data (required for loudness).
          stem_name (str, optional): Stem name for clipping logging.
      Returns:
          torch.Tensor: Normalized audio.
      """
      scale_peak = 10 ** (-peak_clip_headroom_db / 20)
      scale_rms = 10 ** (-rms_headroom_db / 20)
      if strategy == "peak":
          rescaling = scale_peak / wav.abs().max()
          if normalize or rescaling < 1:
              wav = wav * rescaling
      elif strategy == "clip":
          wav = wav.clamp(-scale_peak, scale_peak)
      elif strategy == "rms":
          mono = wav.mean(dim=0)
          rescaling = scale_rms / mono.pow(2).mean().sqrt()
          if normalize or rescaling < 1:
              wav = wav * rescaling
          _clip_wav(wav, log_clipping=log_clipping, stem_name=stem_name)
      elif strategy == "loudness":
          assert (
              sample_rate is not None
          ), "Loudness normalization requires sample rate."
          wav = normalize_loudness(
              wav,
              sample_rate,
              loudness_headroom_db,
              loudness_compressor,
          )
          _clip_wav(wav, log_clipping=log_clipping, stem_name=stem_name)
      else:
          assert wav.abs().max() < 1
          assert (
              strategy == "" or strategy == "none"
          ), f"Unexpected strategy: '{strategy}'"
      return wav
  
file_path: audiocraft/audiocraft/data/audio_utils.py
imports: import sys
  import typing
  import julius
  import torch
  import torchaudio
label_desc: Use image node_id 5 for calling a global function with example usage: normalize_audio(wav, normalize, strategy, peak_clip_headroom_db, rms_headroom_db, loudness_headroom_db, loudness_compressor, log_clipping, sample_rate, stem_name) and returns: wav