code: def stft(x, fft_size, hop_size, win_length, window):
      """Perform STFT and convert to magnitude spectrogram.
      Args:
          x (Tensor): Input signal tensor (B, T).
          fft_size (int): FFT size.
          hop_size (int): Hop size.
          win_length (int): Window length.
          window (str): Window function type.
      Returns:
          Tensor: Magnitude spectrogram (B, #frames, fft_size // 2 + 1).
      """
      x_stft = torch.view_as_real(
          torch.stft(
              x,
              fft_size,
              hop_size,
              win_length,
              window,
              return_complex=True,
          )
      )
      real = x_stft[..., 0]
      imag = x_stft[..., 1]
  
      # NOTE(kan-bayashi): clamp is needed to avoid nan or inf
      return torch.sqrt(
          torch.clamp(real**2 + imag**2, min=1e-7)
      ).transpose(2, 1)
  
imports: import torch
  import torch.nn.functional
  from nemo.core.classes import Loss, typecheck
  from nemo.core.neural_types.elements import AudioSignal, LengthsType, LossType, SpectrogramType
  from nemo.core.neural_types.neural_type import NeuralType
label_desc: Use image node_id 1 for calling a global function with example usage: stft(x, fft_size, hop_size, win_length, window) and returns: torch