code: def torch_spectrogram(
      audio,
      sample_rate,
      device="cpu",
      window_size=0.02,
      window_stride=0.01,
      center=True,
      pad_mode="reflect",
      window="hann",
      n_fft=None,
  ):
      audio = torch.tensor(audio, dtype=torch.float32)
      if device == "gpu":
          audio = audio.cuda()
      win_length, hop_length = win_args(
          sample_rate, window_size, window_stride
      )
      n_fft = n_fft or 2 ** math.ceil(math.log2(win_length))
      window_fn = torch_windows.get(window, None)
      window_tensor = (
          window_fn(win_length, periodic=False) if window_fn else None
      )
      stft_out = torch.stft(
          audio,
          n_fft=n_fft,
          hop_length=hop_length,
          win_length=win_length,
          pad_mode=pad_mode,
          center=center,
          window=window_tensor.to(dtype=torch.float),
          return_complex=True,
      )
      stft_out = torch.view_as_real(stft_out)
      # get power spectrum
      spectrogram = stft_out.pow(2).sum(-1)
      spectrogram = spectrogram.cpu().numpy()
      return spectrogram
  
imports: import nose_utils
  import nvidia.dali.fn
  from nvidia.dali import pipeline_def
  import nvidia.dali.types
  from test_utils import get_files, to_array
  import numpy
  import librosa
  import torch
  import math
  import random
  import os
  from nose.tools import nottest
label_desc: Use image node_id 5 for calling a global function with example usage: torch_spectrogram(audio, sample_rate, device, window_size, window_stride, center, pad_mode, window, n_fft) and returns: spectrogram