code: def build_generator(
      self,
      models,
      args,
      seq_gen_cls=None,
      extra_gen_cls_kwargs=None,
  ):
      if not self.args.target_is_code or self.args.eval_inference:
          from fairseq.models.text_to_speech.vocoder import get_vocoder
  
          self.vocoder = get_vocoder(self.args, self.data_cfg)
          self.vocoder = (
              self.vocoder.cuda()
              if torch.cuda.is_available() and not self.args.cpu
              else self.vocoder.cpu()
          )
  
      has_dual_decoder = (
          getattr(models[0], "mt_task_name", None) is not None
      )
  
      if self.args.target_is_code:
          if self.args.n_frames_per_step == 1:
              if has_dual_decoder:
                  seq_generator = self.build_generator_dual_decoder(
                      models,
                      args,
                      extra_gen_cls_kwargs=extra_gen_cls_kwargs,
                  )
              else:
                  seq_generator = super().build_generator(
                      models,
                      args,
                      seq_gen_cls=None,
                      extra_gen_cls_kwargs=extra_gen_cls_kwargs,
                  )
          else:
              assert (
                  getattr(args, "beam", 1) == 1
                  and getattr(args, "nbest", 1) == 1
              ), "only support viterbi search for stacked units"
              seq_generator = StackUnitSequenceGenerator(
                  self.tgt_dict,
                  self.args.target_code_size,
              )
      else:
          if has_dual_decoder:
              if getattr(args, "teacher_forcing", False):
                  raise NotImplementedError
              else:
                  from fairseq.speech_generator import (
                      MultiDecoderSpeechGenerator,
                  )
  
                  generator = MultiDecoderSpeechGenerator
  
              lang_token_ids_aux = {
                  i
                  for s, i in self.tgt_dict_mt.indices.items()
                  if TextTargetMultitaskData.is_lang_tag(s)
              }
  
              if extra_gen_cls_kwargs is None:
                  extra_gen_cls_kwargs = {}
              extra_gen_cls_kwargs[
                  "symbols_to_strip_from_output"
              ] = lang_token_ids_aux
  
              eos_id_mt = (
                  self.tgt_dict_mt.index(self.eos_token_mt)
                  if self.eos_token_mt
                  else None
              )
              assert eos_id_mt != self.tgt_dict_mt.unk()
              extra_gen_cls_kwargs["eos_mt"] = eos_id_mt
  
              seq_generator = generator(
                  models,
                  args,
                  self.vocoder,
                  self.data_cfg,
                  self.target_dictionary_mt,
                  max_iter=self.args.max_target_positions,
                  eos_prob_threshold=self.args.eos_prob_threshold,
                  **extra_gen_cls_kwargs,
              )
          else:
              if getattr(args, "teacher_forcing", False):
                  from fairseq.speech_generator import (
                      TeacherForcingAutoRegressiveSpeechGenerator,
                  )
  
                  generator = (
                      TeacherForcingAutoRegressiveSpeechGenerator
                  )
                  logger.info("Teacher forcing mode for generation")
              else:
                  from fairseq.speech_generator import (
                      AutoRegressiveSpeechGenerator,
                  )
  
                  generator = AutoRegressiveSpeechGenerator
  
              seq_generator = generator(
                  models[0],
                  self.vocoder,
                  self.data_cfg,
                  max_iter=self.args.max_target_positions,
                  eos_prob_threshold=self.args.eos_prob_threshold,
              )
  
      return seq_generator
  
imports: import json
  import logging
  import math
  from argparse import Namespace
  from pathlib import Path
  from typing import List
  import torch
  import torch.nn
  from fairseq import utils
  from fairseq.data import Dictionary
  from fairseq.data.audio.data_cfg import MultitaskConfig, S2SDataConfig
  from fairseq.data.audio.speech_to_speech_dataset import SpeechToSpeechDatasetCreator
  from fairseq.data.audio.speech_to_text_dataset import SpeechToTextDataset, TextTargetMultitaskData
  from fairseq.tasks import LegacyFairseqTask, register_task
  from fairseq.tasks.speech_to_text import DummyMultiTask
  from fairseq.tasks.text_to_speech import batch_mel_cepstral_distortion
label_desc: Use image node_id 12 for calling the SpeechToSpeechTask obj's underlying member method code with example usage: obj.build_generator(models, args, seq_gen_cls, extra_gen_cls_kwargs) and returns: seq_generator