code: def plot_spectrogram(
      spectrogram, ap=None, fig_size=(16, 10), output_fig=False
  ):
      """Returns the matplotlib sprctrogram if available
      or None if it is not - optional dependency"""
      try:
          import matplotlib
  
          matplotlib.use("Agg")
          import matplotlib.pyplot as plt
  
      except ImportError:
          logger.warning(
              "matplotlib is not available - cannot log figures"
          )
          return None
  
      spectrogram = spectrogram.detach().cpu().numpy().squeeze()
      fig = plt.figure(figsize=fig_size)
      plt.imshow(spectrogram, aspect="auto", origin="lower")
      plt.colorbar()
      plt.tight_layout()
      if not output_fig:
          plt.close()
      return fig
  
imports: import logging
  import torch
  import os
  from speechbrain.utils.distributed import main_process_only, if_main_process
label_desc: Use image node_id 2 for calling a global function with example usage: plot_spectrogram(spectrogram, ap, fig_size, output_fig) and returns: fig, None