docstr: Produces a sample in inference mode with predicted durations.
docstr_tok: ["Produces","a","sample","in","inference","mode","with","predicted","durations","."]
code: def run_inference(self):
      """Produces a sample in inference mode with predicted durations."""
      if self.last_batch is None:
          return
      tokens, *_, labels, _ = self.last_batch
  
      # Generates inference samples without using the silent phoneme predictor
      (
          _,
          postnet_mel_out,
          _,
          _,
          _,
          _,
          _,
          predict_mel_lens,
      ) = self.hparams.model(tokens)
  
      self.hparams.progress_sample_logger.remember(
          infer_output=self.process_mel(
              postnet_mel_out, [len(postnet_mel_out[0])]
          )
      )
  
      # Generates inference samples using the silent phoneme predictor
  
      # Preprocessing required at the inference time for the input text
      # "label" below contains input text
      # "phoneme_labels" contain the phoneme sequences corresponding to input text labels
      # "last_phonemes_combined" is used to indicate whether the index position is for a last phoneme of a word
      phoneme_labels = list()
      last_phonemes_combined = list()
  
      for label in labels:
          phoneme_label = list()
          last_phonemes = list()
  
          words = label.split()
          words = [word.strip() for word in words]
          words_phonemes = self.g2p(words)
  
          for words_phonemes_seq in words_phonemes:
              for phoneme in words_phonemes_seq:
                  if not phoneme.isspace():
                      phoneme_label.append(phoneme)
                      last_phonemes.append(0)
              last_phonemes[-1] = 1
  
          phoneme_labels.append(phoneme_label)
          last_phonemes_combined.append(last_phonemes)
  
      # Inserts silent phonemes in the input phoneme sequence
      all_tokens_with_spn = list()
      max_seq_len = -1
      for i in range(len(phoneme_labels)):
          phoneme_label = phoneme_labels[i]
          token_seq = (
              self.input_encoder.encode_sequence_torch(phoneme_label)
              .int()
              .to(self.device)
          )
          last_phonemes = torch.LongTensor(
              last_phonemes_combined[i]
          ).to(self.device)
  
          # Runs the silent phoneme predictor
          spn_preds = (
              self.hparams.modules["spn_predictor"]
              .infer(token_seq.unsqueeze(0), last_phonemes.unsqueeze(0))
              .int()
          )
  
          spn_to_add = torch.nonzero(spn_preds).reshape(-1).tolist()
  
          tokens_with_spn = list()
  
          for token_idx in range(token_seq.shape[0]):
              tokens_with_spn.append(token_seq[token_idx].item())
              if token_idx in spn_to_add:
                  tokens_with_spn.append(self.spn_token_encoded)
  
          tokens_with_spn = torch.LongTensor(tokens_with_spn).to(
              self.device
          )
          all_tokens_with_spn.append(tokens_with_spn)
          if max_seq_len < tokens_with_spn.shape[-1]:
              max_seq_len = tokens_with_spn.shape[-1]
  
      # "tokens_with_spn_tensor" holds the input phoneme sequence with silent phonemes
      tokens_with_spn_tensor = torch.LongTensor(
          tokens.shape[0], max_seq_len
      ).to(self.device)
      tokens_with_spn_tensor.zero_()
  
      for seq_idx, seq in enumerate(all_tokens_with_spn):
          tokens_with_spn_tensor[seq_idx, : len(seq)] = seq
  
      (
          _,
          postnet_mel_out_spn_pred,
          _,
          _,
          _,
          _,
          _,
          predict_mel_lens_spn_pred,
      ) = self.hparams.model(tokens_with_spn_tensor)
  
      return (
          postnet_mel_out,
          predict_mel_lens,
          postnet_mel_out_spn_pred,
          predict_mel_lens_spn_pred,
      )
  
imports: import os
  import sys
  import torch
  import logging
  import torchaudio
  import numpy
  import speechbrain
  from speechbrain.inference.vocoders import HIFIGAN
  from pathlib import Path
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.data_utils import scalarize
  from speechbrain.inference.text import GraphemeToPhoneme
label_desc: Use image node_id 8 for calling the FastSpeech2Brain obj's underlying member method code with example usage: obj.run_inference() and returns: postnet_mel_out,  predict_mel_lens,  postnet_mel_out_spn_pred,  predict_mel_lens_spn_pred