class_docstr: The Brain implementation for Tacotron2
docstr: Produces a sample in inference mode. This is called when producing
  samples and can be useful because
docstr_tok: ["Produces","a","sample","in","inference","mode",".","This","is","called","when","producing","samples","and","can","be","useful","because"]
code: def run_inference_sample(self, stage):
      """Produces a sample in inference mode. This is called when producing
      samples and can be useful because"""
  
      if self.last_batch is None:
          return
      (
          inputs,
          targets,
          _,
          labels,
          wavs,
          spk_embs,
          spk_ids,
      ) = self.last_batch
      text_padded, input_lengths, _, _, _ = inputs
  
      mel_out, _, _ = self.hparams.model.infer(
          text_padded[:1], spk_embs[:1], input_lengths[:1]
      )
      self.hparams.progress_sample_logger.remember(
          inference_mel_out=self._get_spectrogram_sample(mel_out)
      )
  
      if stage == sb.Stage.VALID:
          inf_sample_path = os.path.join(
              self.hparams.progress_sample_path,
              str(self.hparams.epoch_counter.current),
          )
  
          if not os.path.exists(inf_sample_path):
              os.makedirs(inf_sample_path)
  
          inf_sample_text = os.path.join(
              self.hparams.progress_sample_path,
              str(self.hparams.epoch_counter.current),
              "inf_input_text.txt",
          )
          with open(inf_sample_text, "w") as f:
              f.write(labels[0])
  
          inf_input_audio = os.path.join(
              self.hparams.progress_sample_path,
              str(self.hparams.epoch_counter.current),
              "inf_input_audio.wav",
          )
          torchaudio.save(
              inf_input_audio,
              sb.dataio.dataio.read_audio(wavs[0]).unsqueeze(0),
              self.hparams.sample_rate,
          )
  
          if self.hparams.log_audio_samples:
              waveform_ss = self.vocoder.decode_batch(mel_out)
              inf_sample_audio = os.path.join(
                  self.hparams.progress_sample_path,
                  str(self.hparams.epoch_counter.current),
                  "inf_output_audio.wav",
              )
              torchaudio.save(
                  inf_sample_audio,
                  waveform_ss.squeeze(1).cpu(),
                  self.hparams.sample_rate,
              )
  
          if self.hparams.use_tensorboard:
              self.tensorboard_logger.log_audio(
                  f"{stage}/inf_audio_target",
                  sb.dataio.dataio.read_audio(wavs[0]).unsqueeze(0),
                  self.hparams.sample_rate,
              )
              if self.hparams.log_audio_samples:
                  self.tensorboard_logger.log_audio(
                      f"{stage}/inf_audio_pred",
                      waveform_ss.squeeze(1),
                      self.hparams.sample_rate,
                  )
              try:
                  self.tensorboard_logger.log_figure(
                      f"{stage}/inf_mel_target", targets[0][0]
                  )
                  self.tensorboard_logger.log_figure(
                      f"{stage}/inf_mel_pred", mel_out
                  )
              except Exception:
                  # This is to avoid the code from crashing in case of a mel-spectrogram with one frame
                  pass
  
imports: import torch
  import speechbrain
  import sys
  import logging
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.text_to_sequence import text_to_sequence
  from speechbrain.utils.data_utils import scalarize
  import os
  from speechbrain.inference.vocoders import HIFIGAN
  import torchaudio
label_desc: Use image node_id 10 for calling the Tacotron2Brain obj's underlying member method code with example usage: obj.run_inference_sample(stage) without return types