docstr: Uses a pretrained vocoder to generate audio from predicted mel
  spectogram. By default, uses speechbrain hifigan.
  Arguments
  ---------
  inference_mel: torch.Tensor
      predicted mel from fastspeech2 inference
  mel_lens: torch.Tensor
      predicted mel lengths from fastspeech2 inference
      used to mask the noise from padding
docstr_tok: ["Uses","a","pretrained","vocoder","to","generate","audio","from","predicted","mel","spectogram",".","By","default",",","uses","speechbrain","hifigan",".","Arguments","--","--","--","--","-","inference_mel",":","torch.Tensor","predicted","mel","from","fastspeech2","inference","mel_lens",":","torch.Tensor","predicted","mel","lengths","from","fastspeech2","inference","used","to","mask","the","noise","from","padding"]
code: def run_vocoder(self, inference_mel, mel_lens):
      """Uses a pretrained vocoder to generate audio from predicted mel
      spectogram. By default, uses speechbrain hifigan.
      Arguments
      ---------
      inference_mel: torch.Tensor
          predicted mel from fastspeech2 inference
      mel_lens: torch.Tensor
          predicted mel lengths from fastspeech2 inference
          used to mask the noise from padding
      """
      if self.last_batch is None:
          return
      *_, wavs = self.last_batch
  
      inference_mel = inference_mel[
          : self.hparams.progress_batch_sample_size
      ]
      mel_lens = mel_lens[0 : self.hparams.progress_batch_sample_size]
      assert (
          self.hparams.vocoder == "hifi-gan"
          and self.hparams.pretrained_vocoder is True
      ), "Specified vocoder not supported yet"
      logger.info(
          f"Generating audio with pretrained {self.hparams.vocoder_source} vocoder"
      )
      hifi_gan = HIFIGAN.from_hparams(
          source=self.hparams.vocoder_source,
          savedir=self.hparams.vocoder_download_path,
      )
      waveforms = hifi_gan.decode_batch(
          inference_mel.transpose(2, 1),
          mel_lens,
          self.hparams.hop_length,
      )
      for idx, wav in enumerate(waveforms):
          path = os.path.join(
              self.hparams.progress_sample_path,
              str(self.last_epoch),
              f"pred_{Path(wavs[idx]).stem}.wav",
          )
          torchaudio.save(path, wav, self.hparams.sample_rate)
  
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
label_desc: Use image node_id 9 for calling the FastSpeech2Brain obj's underlying member method code with example usage: obj.run_vocoder(inference_mel, mel_lens) without return types