class_docstr: A ready-to-use wrapper for Zero-Shot Multi-Speaker Tacotron2.
  For voice cloning: (text, reference_audio) -> (mel_spec).
  For generating a random speaker voice: (text) -> (mel_spec).
  
  
  Example
  -------
  >>> tmpdir_tts = getfixture('tmpdir') / "tts"
  >>> mstacotron2 = MSTacotron2.from_hparams(source="speechbrain/tts-mstacotron2-libritts", savedir=tmpdir_tts) # doctest: +SKIP
  >>> # Sample rate of the reference audio must be greater or equal to the sample rate of the speaker embedding model
  >>> reference_audio_path = "tests/samples/single-mic/example1.wav"
  >>> input_text = "Mary had a little lamb."
  >>> mel_output, mel_length, alignment = mstacotron2.clone_voice(input_text, reference_audio_path) # doctest: +SKIP
  >>> # One can combine the TTS model with a vocoder (that generates the final waveform)
  >>> # Intialize the Vocoder (HiFIGAN)
  >>> tmpdir_vocoder = getfixture('tmpdir') / "vocoder"
  >>> from speechbrain.inference.vocoders import HIFIGAN
  >>> hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-libritts-22050Hz", savedir=tmpdir_vocoder) # doctest: +SKIP
  >>> # Running the TTS
  >>> mel_output, mel_length, alignment = mstacotron2.clone_voice(input_text, reference_audio_path) # doctest: +SKIP
  >>> # Running Vocoder (spectrogram-to-waveform)
  >>> waveforms = hifi_gan.decode_batch(mel_output) # doctest: +SKIP
  >>> # For generating a random speaker voice, use the following
  >>> mel_output, mel_length, alignment = mstacotron2.generate_random_voice(input_text) # doctest: +SKIP
docstr: Computes mel-spectrograms for a list of texts
  Texts are sorted in decreasing order on their lengths
  
  Arguments
  ---------
  texts: List[str]
      texts to be encoded into spectrogram
  spk_embs: torch.Tensor
      speaker embeddings
  
  Returns
  -------
  tensors of output spectrograms, output lengths and alignments
docstr_tok: ["Computes","mel-spectrograms","for","a","list","of","texts","Texts","are","sorted","in","decreasing","order","on","their","lengths","Arguments","--","--","--","--","-","texts",":","List","[","str","]","texts","to","be","encoded","into","spectrogram","spk_embs",":","torch.Tensor","speaker","embeddings","Returns","--","--","--","-","tensors","of","output","spectrograms",",","output","lengths","and","alignments"]
code: def __encode_batch(self, texts, spk_embs):
      """Computes mel-spectrograms for a list of texts
      Texts are sorted in decreasing order on their lengths
  
      Arguments
      ---------
      texts: List[str]
          texts to be encoded into spectrogram
      spk_embs: torch.Tensor
          speaker embeddings
  
      Returns
      -------
      tensors of output spectrograms, output lengths and alignments
      """
  
      with torch.no_grad():
          inputs = [
              {
                  "text_sequences": torch.tensor(
                      self.__text_to_seq(item)[0], device=self.device
                  )
              }
              for item in texts
          ]
  
          inputs = sorted(
              inputs,
              key=lambda x: x["text_sequences"].size()[0],
              reverse=True,
          )
  
          lens = [entry["text_sequences"].size()[0] for entry in inputs]
  
          inputs = speechbrain.dataio.batch.PaddedBatch(inputs)
  
          assert lens == sorted(
              lens, reverse=True
          ), "ipnut lengths must be sorted in decreasing order"
          input_lengths = torch.tensor(lens, device=self.device)
  
          mel_outputs_postnet, mel_lengths, alignments = self.infer(
              inputs.text_sequences.data, spk_embs, input_lengths
          )
      return mel_outputs_postnet, mel_lengths, alignments
  
imports: import re
  import logging
  import torch
  import torchaudio
  import random
  import speechbrain
  from speechbrain.utils.fetching import fetch
  from speechbrain.inference.interfaces import Pretrained
  from speechbrain.utils.text_to_sequence import text_to_sequence
  from speechbrain.inference.text import GraphemeToPhoneme
  from speechbrain.inference.encoders import MelSpectrogramEncoder
  from speechbrain.inference.classifiers import EncoderClassifier
label_desc: Use image node_id 5 for calling the MSTacotron2 obj's underlying member method code with example usage: obj.__encode_batch(texts, spk_embs) and returns: mel_outputs_postnet,  mel_lengths,  alignments