code: def __generate_mels(
      entry,
      spec_model,
      device,
      use_beta_binomial_interpolator,
      mel_root,
  ):
      # Generate a spectrograms (we need to use ground truth alignment for correct matching between audio and mels)
      audio = __load_wav(entry["audio_filepath"])
      audio = torch.from_numpy(audio).unsqueeze(0).to(device)
      audio_len = torch.tensor(
          audio.shape[1], dtype=torch.long, device=device
      ).unsqueeze(0)
  
      if (
          spec_model.fastpitch.speaker_emb is not None
          and "speaker" in entry
      ):
          speaker = torch.tensor([entry["speaker"]]).to(device)
      else:
          speaker = None
  
      with torch.no_grad():
          if "normalized_text" in entry:
              text = spec_model.parse(
                  entry["normalized_text"], normalize=False
              )
          else:
              text = spec_model.parse(entry["text"])
  
          text_len = torch.tensor(
              text.shape[-1], dtype=torch.long, device=device
          ).unsqueeze(0)
          spect, spect_len = spec_model.preprocessor(
              input_signal=audio, length=audio_len
          )
  
          # Generate attention prior and spectrogram inputs for HiFi-GAN
          if use_beta_binomial_interpolator:
              beta_binomial_interpolator = BetaBinomialInterpolator()
              attn_prior = (
                  torch.from_numpy(
                      beta_binomial_interpolator(
                          spect_len.item(), text_len.item()
                      )
                  )
                  .unsqueeze(0)
                  .to(text.device)
              )
          else:
              attn_prior = (
                  torch.from_numpy(
                      beta_binomial_prior_distribution(
                          text_len.item(), spect_len.item()
                      )
                  )
                  .unsqueeze(0)
                  .to(text.device)
              )
  
          spectrogram = spec_model.forward(
              text=text,
              input_lens=text_len,
              spec=spect,
              mel_lens=spect_len,
              attn_prior=attn_prior,
              speaker=speaker,
          )[0]
  
          save_path = (
              mel_root / f"{Path(entry['audio_filepath']).stem}.npy"
          )
          np.save(save_path, spectrogram[0].to("cpu").numpy())
          entry["mel_filepath"] = str(save_path)
  
      return entry
  
file_path: NeMo/scripts/dataset_processing/tts/generate_mels.py
imports: import argparse
  import json
  from pathlib import Path
  import numpy
  import soundfile
  import torch
  from joblib import Parallel, delayed
  from tqdm import tqdm
  from nemo.collections.tts.models import FastPitchModel
  from nemo.collections.tts.parts.utils.tts_dataset_utils import BetaBinomialInterpolator, beta_binomial_prior_distribution
  from nemo.utils import logging
label_desc: Use image node_id 3 for calling a global function with example usage: __generate_mels(entry, spec_model, device, use_beta_binomial_interpolator, mel_root) and returns: entry