code: def _spectrogram(
      *,
      y: Optional[np.ndarray] = None,
      S: Optional[np.ndarray] = None,
      n_fft: Optional[int] = 2048,
      hop_length: Optional[int] = 512,
      power: float = 1,
      win_length: Optional[int] = None,
      window: _WindowSpec = "hann",
      center: bool = True,
      pad_mode: _PadModeSTFT = "constant",
  ) -> Tuple[np.ndarray, int]:
      """Retrieve a magnitude spectrogram.
  
      This is primarily used in feature extraction functions that can operate on
      either audio time-series or spectrogram input.
  
      Parameters
      ----------
      y : None or np.ndarray
          If provided, an audio time series
  
      S : None or np.ndarray
          Spectrogram input, optional
  
      n_fft : int > 0
          STFT window size
  
      hop_length : int > 0
          STFT hop length
  
      power : float > 0
          Exponent for the magnitude spectrogram,
          e.g., 1 for energy, 2 for power, etc.
  
      win_length : int <= n_fft [scalar]
          Each frame of audio is windowed by ``window``.
          The window will be of length ``win_length`` and then padded
          with zeros to match ``n_fft``.
  
          If unspecified, defaults to ``win_length = n_fft``.
  
      window : string, tuple, number, function, or np.ndarray [shape=(n_fft,)]
          - a window specification (string, tuple, or number);
            see `scipy.signal.get_window`
          - a window function, such as `scipy.signal.windows.hann`
          - a vector or array of length ``n_fft``
  
          .. see also:: `filters.get_window`
  
      center : boolean
          - If ``True``, the signal ``y`` is padded so that frame
            ``t`` is centered at ``y[t * hop_length]``.
          - If ``False``, then frame ``t`` begins at ``y[t * hop_length]``
  
      pad_mode : string
          If ``center=True``, the padding mode to use at the edges of the signal.
          By default, STFT uses zero padding.
  
      Returns
      -------
      S_out : np.ndarray [dtype=np.float]
          - If ``S`` is provided as input, then ``S_out == S``
          - Else, ``S_out = |stft(y, ...)|**power``
      n_fft : int > 0
          - If ``S`` is provided, then ``n_fft`` is inferred from ``S``
          - Else, copied from input
      """
      if S is not None:
          # Infer n_fft from spectrogram shape, but only if it mismatches
          if n_fft is None or n_fft // 2 + 1 != S.shape[-2]:
              n_fft = 2 * (S.shape[-2] - 1)
      else:
          # Otherwise, compute a magnitude spectrogram from input
          if n_fft is None:
              raise ParameterError(
                  f"Unable to compute spectrogram with n_fft={n_fft}"
              )
          if y is None:
              raise ParameterError(
                  "Input signal must be provided to compute a spectrogram"
              )
          S = (
              np.abs(
                  stft(
                      y,
                      n_fft=n_fft,
                      hop_length=hop_length,
                      win_length=win_length,
                      center=center,
                      window=window,
                      pad_mode=pad_mode,
                  )
              )
              ** power
          )
  
      return S, n_fft
  
imports: from __future__ import annotations
  import warnings
  import numpy
  import scipy
  import scipy.ndimage
  import scipy.signal
  import scipy.interpolate
  from numba import jit
  from .None import convert
  from .fft import get_fftlib
  from .audio import resample
  from .._cache import cache
  from ..None import util
  from ..util.exceptions import ParameterError
  from ..filters import get_window, semitone_filterbank
  from ..filters import window_sumsquare
  from numpy.typing import DTypeLike
  from typing import Any, Callable, Optional, Tuple, List, Union, overload
  from typing_extensions import Literal
  from .._typing import _WindowSpec, _PadMode, _PadModeSTFT, _SequenceLike, _ScalarOrSequence, _ComplexLike_co, _FloatLike_co
label_desc: Use image node_id 33 for calling a global function with example usage: _spectrogram() and returns: S,  n_fft