code: def rms(
      *,
      y: Optional[np.ndarray] = None,
      S: Optional[np.ndarray] = None,
      frame_length: int = 2048,
      hop_length: int = 512,
      center: bool = True,
      pad_mode: _PadMode = "constant",
      dtype: DTypeLike = np.float32,
  ) -> np.ndarray:
      """Compute root-mean-square (RMS) value for each frame, either from the
      audio samples ``y`` or from a spectrogram ``S``.
  
      Computing the RMS value from audio samples is faster as it doesn't require
      a STFT calculation. However, using a spectrogram will give a more accurate
      representation of energy over time because its frames can be windowed,
      thus prefer using ``S`` if it's already available.
  
      Parameters
      ----------
      y : np.ndarray [shape=(..., n)] or None
          (optional) audio time series. Required if ``S`` is not input.
          Multi-channel is supported.
      S : np.ndarray [shape=(..., d, t)] or None
          (optional) spectrogram magnitude. Required if ``y`` is not input.
      frame_length : int > 0 [scalar]
          length of analysis frame (in samples) for energy calculation
      hop_length : int > 0 [scalar]
          hop length for STFT. See `librosa.stft` for details.
      center : bool
          If `True` and operating on time-domain input (``y``), pad the signal
          by ``frame_length//2`` on either side.
          If operating on spectrogram input, this has no effect.
      pad_mode : str
          Padding mode for centered analysis.  See `numpy.pad` for valid
          values.
      dtype : np.dtype, optional
          Data type of the output array.  Defaults to float32.
  
      Returns
      -------
      rms : np.ndarray [shape=(..., 1, t)]
          RMS value for each frame
  
      Examples
      --------
      >>> y, sr = librosa.load(librosa.ex('trumpet'))
      >>> librosa.feature.rms(y=y)
      array([[1.248e-01, 1.259e-01, ..., 1.845e-05, 1.796e-05]],
            dtype=float32)
  
      Or from spectrogram input
  
      >>> S, phase = librosa.magphase(librosa.stft(y))
      >>> rms = librosa.feature.rms(S=S)
  
      >>> import matplotlib.pyplot as plt
      >>> fig, ax = plt.subplots(nrows=2, sharex=True)
      >>> times = librosa.times_like(rms)
      >>> ax[0].semilogy(times, rms[0], label='RMS Energy')
      >>> ax[0].set(xticks=[])
      >>> ax[0].legend()
      >>> ax[0].label_outer()
      >>> librosa.display.specshow(librosa.amplitude_to_db(S, ref=np.max),
      ...                          y_axis='log', x_axis='time', ax=ax[1])
      >>> ax[1].set(title='log Power spectrogram')
  
      Use a STFT window of constant ones and no frame centering to get consistent
      results with the RMS computed from the audio samples ``y``
  
      >>> S = librosa.magphase(librosa.stft(y, window=np.ones, center=False))[0]
      >>> librosa.feature.rms(S=S)
      >>> plt.show()
  
      """
      if y is not None:
          if center:
              padding = [(0, 0) for _ in range(y.ndim)]
              padding[-1] = (
                  int(frame_length // 2),
                  int(frame_length // 2),
              )
              y = np.pad(y, padding, mode=pad_mode)
  
          x = util.frame(
              y, frame_length=frame_length, hop_length=hop_length
          )
  
          # Calculate power
          power = np.mean(
              util.abs2(x, dtype=dtype), axis=-2, keepdims=True
          )
      elif S is not None:
          # Check the frame length
          if S.shape[-2] != frame_length // 2 + 1:
              raise ParameterError(
                  "Since S.shape[-2] is {}, "
                  "frame_length is expected to be {} or {}; "
                  "found {}".format(
                      S.shape[-2],
                      S.shape[-2] * 2 - 2,
                      S.shape[-2] * 2 - 1,
                      frame_length,
                  )
              )
  
          # power spectrogram
          x = util.abs2(S, dtype=dtype)
  
          # Adjust the DC and sr/2 component
          x[..., 0, :] *= 0.5
          if frame_length % 2 == 0:
              x[..., -1, :] *= 0.5
  
          # Calculate power
          power = (
              2 * np.sum(x, axis=-2, keepdims=True) / frame_length**2
          )
      else:
          raise ParameterError("Either `y` or `S` must be input.")
  
      rms_result: np.ndarray = np.sqrt(power)
      return rms_result
  
imports: import numpy
  import scipy
  import scipy.signal
  import scipy.fftpack
  from ..None import util
  from ..None import filters
  from ..util.exceptions import ParameterError
  from ..core.convert import fft_frequencies
  from ..core.audio import zero_crossings
  from ..core.spectrum import power_to_db, _spectrogram
  from ..core.constantq import cqt, hybrid_cqt, vqt
  from ..core.pitch import estimate_tuning
  from typing import Any, Optional, Union, Collection
  from numpy.typing import DTypeLike
  from .._typing import _FloatLike_co, _WindowSpec, _PadMode, _PadModeSTFT
label_desc: Use image node_id 6 for calling a global function with example usage: rms() and returns: rms_result