code: def inference(
      model_name,
      model,
      ap,
      text_input,
      text_lengths,
      mel_input,
      mel_lengths,
      speaker_ids=None,
      d_vectors=None,
  ):
      if model_name == "glow_tts":
          speaker_c = None
          if speaker_ids is not None:
              speaker_c = speaker_ids
          elif d_vectors is not None:
              speaker_c = d_vectors
          outputs = model.inference_with_MAS(
              text_input,
              text_lengths,
              mel_input,
              mel_lengths,
              aux_input={
                  "d_vectors": speaker_c,
                  "speaker_ids": speaker_ids,
              },
          )
          model_output = outputs["model_outputs"]
          model_output = model_output.detach().cpu().numpy()
  
      elif "tacotron" in model_name:
          aux_input = {
              "speaker_ids": speaker_ids,
              "d_vectors": d_vectors,
          }
          outputs = model(
              text_input,
              text_lengths,
              mel_input,
              mel_lengths,
              aux_input,
          )
          postnet_outputs = outputs["model_outputs"]
          # normalize tacotron output
          if model_name == "tacotron":
              mel_specs = []
              postnet_outputs = postnet_outputs.data.cpu().numpy()
              for b in range(postnet_outputs.shape[0]):
                  postnet_output = postnet_outputs[b]
                  mel_specs.append(
                      torch.FloatTensor(
                          ap.out_linear_to_mel(postnet_output.T).T
                      )
                  )
              model_output = torch.stack(mel_specs).cpu().numpy()
  
          elif model_name == "tacotron2":
              model_output = postnet_outputs.detach().cpu().numpy()
      return model_output
  
file_path: TTS/TTS/bin/extract_tts_spectrograms.py
imports: import argparse
  import os
  import numpy
  import torch
  from torch.utils.data import DataLoader
  from tqdm import tqdm
  from TTS.config import load_config
  from TTS.tts.datasets import TTSDataset, load_tts_samples
  from TTS.tts.models import setup_model
  from TTS.tts.utils.speakers import SpeakerManager
  from TTS.tts.utils.text.tokenizer import TTSTokenizer
  from TTS.utils.audio import AudioProcessor
  from TTS.utils.audio.numpy_transforms import quantize
  from TTS.utils.generic_utils import count_parameters
label_desc: Use image node_id 4 for calling a global function with example usage: inference(model_name, model, ap, text_input, text_lengths, mel_input, mel_lengths, speaker_ids, d_vectors) and returns: model_output