code: def ret_and_save_audio(
      audio: np.ndarray,
      output_path: Optional[str],
      sample_rate: int = utils.DEFAULT_SAMPLE_RATE,
  ) -> Tuple[np.ndarray, int]:
      if output_path is not None:
          utils.validate_output_path(output_path)
  
          try:
              # Note: librosa reads in audio data as (num_channels, num_samples),
              # but soundfile expects it to be (num_samples, num_channels) when
              # writing it out, so we have to swap axes here.
              saved_audio = (
                  np.swapaxes(audio, 0, 1) if audio.ndim > 1 else audio
              )
              sf.write(output_path, saved_audio, sample_rate)
          except TypeError:
              saved_audio = (
                  audio
                  if audio.ndim > 1
                  else audio.reshape(1, audio.shape[-1])
              )
              torchaudio.backend.sox_io_backend.save(
                  output_path,
                  torch.Tensor(saved_audio),
                  sample_rate,
                  channels_first=True,
              )
  
      return audio, sample_rate
  
file_path: AugLy/augly/audio/utils.py
imports: import numbers
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from augly import utils
  from augly.audio import intensity
  from augly.utils.libsndfile import install_libsndfile
  import librosa
  import soundfile
  import torchaudio
label_desc: Use image node_id 2 for calling a global function with example usage: ret_and_save_audio(audio, output_path, sample_rate) and returns: audio,  sample_rate