class_docstr: Base `tts` class. Every new `tts` model must inherit this.
  
  It defines common `tts` specific functions on top of `Model` implementation.
class_docstr_tok: ["Base","`","tts","`","class",".","Every","new","`","tts","`","model","must","inherit","this",".","It","defines","common","`","tts","`","specific","functions","on","top","of","`","Model","`","implementation","."]
docstr: Generic batch formatting for `TTSDataset`.
  
  You must override this if you use a custom dataset.
  
  Args:
      batch (Dict): [description]
  
  Returns:
      Dict: [description]
docstr_tok: ["Generic","batch","formatting","for","`","TTSDataset","`",".","You","must","override","this","if","you","use","a","custom","dataset",".","Args",":","batch","(","Dict",")",":","[","description","]","Returns",":","Dict",":","[","description","]"]
code: def format_batch(self, batch: Dict) -> Dict:
      """Generic batch formatting for `TTSDataset`.
  
      You must override this if you use a custom dataset.
  
      Args:
          batch (Dict): [description]
  
      Returns:
          Dict: [description]
      """
      # setup input batch
      text_input = batch["token_id"]
      text_lengths = batch["token_id_lengths"]
      speaker_names = batch["speaker_names"]
      linear_input = batch["linear"]
      mel_input = batch["mel"]
      mel_lengths = batch["mel_lengths"]
      stop_targets = batch["stop_targets"]
      item_idx = batch["item_idxs"]
      d_vectors = batch["d_vectors"]
      speaker_ids = batch["speaker_ids"]
      attn_mask = batch["attns"]
      waveform = batch["waveform"]
      pitch = batch["pitch"]
      energy = batch["energy"]
      language_ids = batch["language_ids"]
      max_text_length = torch.max(text_lengths.float())
      max_spec_length = torch.max(mel_lengths.float())
  
      # compute durations from attention masks
      durations = None
      if attn_mask is not None:
          durations = torch.zeros(
              attn_mask.shape[0], attn_mask.shape[2]
          )
          for idx, am in enumerate(attn_mask):
              # compute raw durations
              c_idxs = am[
                  :, : text_lengths[idx], : mel_lengths[idx]
              ].max(1)[1]
              # c_idxs, counts = torch.unique_consecutive(c_idxs, return_counts=True)
              c_idxs, counts = torch.unique(c_idxs, return_counts=True)
              dur = torch.ones([text_lengths[idx]]).to(counts.dtype)
              dur[c_idxs] = counts
              # smooth the durations and set any 0 duration to 1
              # by cutting off from the largest duration indeces.
              extra_frames = dur.sum() - mel_lengths[idx]
              largest_idxs = torch.argsort(-dur)[:extra_frames]
              dur[largest_idxs] -= 1
              assert (
                  dur.sum() == mel_lengths[idx]
              ), f" [!] total duration {dur.sum()} vs spectrogram length {mel_lengths[idx]}"
              durations[idx, : text_lengths[idx]] = dur
  
      # set stop targets wrt reduction factor
      stop_targets = stop_targets.view(
          text_input.shape[0], stop_targets.size(1) // self.config.r, -1
      )
      stop_targets = (
          (stop_targets.sum(2) > 0.0).unsqueeze(2).float().squeeze(2)
      )
      stop_target_lengths = torch.divide(
          mel_lengths, self.config.r
      ).ceil_()
  
      return {
          "text_input": text_input,
          "text_lengths": text_lengths,
          "speaker_names": speaker_names,
          "mel_input": mel_input,
          "mel_lengths": mel_lengths,
          "linear_input": linear_input,
          "stop_targets": stop_targets,
          "stop_target_lengths": stop_target_lengths,
          "attn_mask": attn_mask,
          "durations": durations,
          "speaker_ids": speaker_ids,
          "d_vectors": d_vectors,
          "max_text_length": float(max_text_length),
          "max_spec_length": float(max_spec_length),
          "item_idx": item_idx,
          "waveform": waveform,
          "pitch": pitch,
          "energy": energy,
          "language_ids": language_ids,
          "audio_unique_names": batch["audio_unique_names"],
      }
  
imports: import os
  import random
  from typing import Dict, List, Tuple, Union
  import torch
  import torch.distributed
  from coqpit import Coqpit
  from torch import nn
  from torch.utils.data import DataLoader
  from torch.utils.data.sampler import WeightedRandomSampler
  from trainer.torch import DistributedSampler, DistributedSamplerWrapper
  from TTS.model import BaseTrainerModel
  from TTS.tts.datasets.dataset import TTSDataset
  from TTS.tts.utils.data import get_length_balancer_weights
  from TTS.tts.utils.languages import LanguageManager, get_language_balancer_weights
  from TTS.tts.utils.speakers import SpeakerManager, get_speaker_balancer_weights, get_speaker_manager
  from TTS.tts.utils.synthesis import synthesis
  from TTS.tts.utils.visual import plot_alignment, plot_spectrogram
label_desc: Use image node_id 6 for calling the BaseTTS obj's underlying member method code with example usage: obj.format_batch(batch) and returns: dict