code: def audio_write(
      stem_name: tp.Union[str, Path],
      wav: torch.Tensor,
      sample_rate: int,
      format: str = "wav",
      mp3_rate: int = 320,
      ogg_rate: tp.Optional[int] = None,
      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 = True,
      make_parent_dir: bool = True,
      add_suffix: bool = True,
  ) -> Path:
      """Convenience function for saving audio to disk. Returns the filename the audio was written to.
  
      Args:
          stem_name (str or Path): Filename without extension which will be added automatically.
          wav (torch.Tensor): Audio data to save.
          sample_rate (int): Sample rate of audio data.
          format (str): Either "wav", "mp3", "ogg", or "flac".
          mp3_rate (int): kbps when using mp3s.
          ogg_rate (int): kbps when using ogg/vorbis. If not provided, let ffmpeg decide for itself.
          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): Uses tanh for soft clipping when strategy is 'loudness'.
           when strategy is 'loudness' log_clipping (bool): If True, basic logging on stderr when clipping still
              occurs despite strategy (only for 'rms').
          make_parent_dir (bool): Make parent directory if it doesn't exist.
      Returns:
          Path: Path of the saved audio.
      """
      assert wav.dtype.is_floating_point, "wav is not floating point"
      if wav.dim() == 1:
          wav = wav[None]
      elif wav.dim() > 2:
          raise ValueError("Input wav should be at most 2 dimension.")
      assert wav.isfinite().all()
      wav = normalize_audio(
          wav,
          normalize,
          strategy,
          peak_clip_headroom_db,
          rms_headroom_db,
          loudness_headroom_db,
          loudness_compressor,
          log_clipping=log_clipping,
          sample_rate=sample_rate,
          stem_name=str(stem_name),
      )
      if format == "mp3":
          suffix = ".mp3"
          flags = [
              "-f",
              "mp3",
              "-c:a",
              "libmp3lame",
              "-b:a",
              f"{mp3_rate}k",
          ]
      elif format == "wav":
          suffix = ".wav"
          flags = ["-f", "wav", "-c:a", "pcm_s16le"]
      elif format == "ogg":
          suffix = ".ogg"
          flags = ["-f", "ogg", "-c:a", "libvorbis"]
          if ogg_rate is not None:
              flags += ["-b:a", f"{ogg_rate}k"]
      elif format == "flac":
          suffix = ".flac"
          flags = ["-f", "flac"]
      else:
          raise RuntimeError(
              f"Invalid format {format}. Only wav or mp3 are supported."
          )
      if not add_suffix:
          suffix = ""
      path = Path(str(stem_name) + suffix)
      if make_parent_dir:
          path.parent.mkdir(exist_ok=True, parents=True)
      try:
          _piping_to_ffmpeg(path, wav, sample_rate, flags)
      except Exception:
          if path.exists():
              # we do not want to leave half written files around.
              path.unlink()
          raise
      return path
  
file_path: audiocraft/audiocraft/data/audio.py
imports: from dataclasses import dataclass
  from pathlib import Path
  import logging
  import typing
  import numpy
  import soundfile
  import torch
  from torch.nn import functional
  import av
  import subprocess
  from .audio_utils import f32_pcm, normalize_audio
label_desc: Use image node_id 8 for calling a global function with example usage: audio_write(stem_name, wav, sample_rate, format, mp3_rate, ogg_rate, normalize, strategy, peak_clip_headroom_db, rms_headroom_db, loudness_headroom_db, loudness_compressor, log_clipping, make_parent_dir, add_suffix) and returns: path