code: def extract_spectrograms(
      data_loader,
      model,
      ap,
      output_path,
      quantize_bits=0,
      save_audio=False,
      debug=False,
      metada_name="metada.txt",
  ):
      model.eval()
      export_metadata = []
      for _, data in tqdm(
          enumerate(data_loader), total=len(data_loader)
      ):
          # format data
          (
              text_input,
              text_lengths,
              mel_input,
              mel_lengths,
              speaker_ids,
              d_vectors,
              _,
              _,
              _,
              item_idx,
          ) = format_data(data)
  
          model_output = inference(
              c.model.lower(),
              model,
              ap,
              text_input,
              text_lengths,
              mel_input,
              mel_lengths,
              speaker_ids,
              d_vectors,
          )
  
          for idx in range(text_input.shape[0]):
              wav_file_path = item_idx[idx]
              wav = ap.load_wav(wav_file_path)
              (
                  _,
                  wavq_path,
                  mel_path,
                  wav_gl_path,
                  wav_path,
              ) = set_filename(wav_file_path, output_path)
  
              # quantize and save wav
              if quantize_bits > 0:
                  wavq = quantize(wav, quantize_bits)
                  np.save(wavq_path, wavq)
  
              # save TTS mel
              mel = model_output[idx]
              mel_length = mel_lengths[idx]
              mel = mel[:mel_length, :].T
              np.save(mel_path, mel)
  
              export_metadata.append([wav_file_path, mel_path])
              if save_audio:
                  ap.save_wav(wav, wav_path)
  
              if debug:
                  print("Audio for debug saved at:", wav_gl_path)
                  wav = ap.inv_melspectrogram(mel)
                  ap.save_wav(wav, wav_gl_path)
  
      with open(
          os.path.join(output_path, metada_name), "w", encoding="utf-8"
      ) as f:
          for data in export_metadata:
              f.write(f"{data[0]}|{data[1]+'.npy'}\n")
  
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 5 for calling a global function with example usage: extract_spectrograms(data_loader, model, ap, output_path, quantize_bits, save_audio, debug, metada_name) without return types