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: Samples a random speaker embedding from a pretrained GMM
  
  Returns
  -------
  x: torch.Tensor
      A randomly sampled speaker embedding
docstr_tok: ["Samples","a","random","speaker","embedding","from","a","pretrained","GMM","Returns","--","--","--","-","x",":","torch.Tensor","A","randomly","sampled","speaker","embedding"]
code: def __sample_random_speaker(self):
      """Samples a random speaker embedding from a pretrained GMM
  
      Returns
      -------
      x: torch.Tensor
          A randomly sampled speaker embedding
      """
  
      # Fetches and Loads GMM trained on speaker embeddings
      speaker_gmm_local_path = fetch(
          filename=self.hparams.random_speaker_sampler,
          source=self.hparams.random_speaker_sampler_source,
          savedir=self.hparams.pretrainer.collect_in,
      )
      random_speaker_gmm = torch.load(speaker_gmm_local_path)
      gmm_n_components = random_speaker_gmm["gmm_n_components"]
      gmm_means = random_speaker_gmm["gmm_means"]
      gmm_covariances = random_speaker_gmm["gmm_covariances"]
  
      # Randomly selects a speaker
      counts = torch.zeros(gmm_n_components)
      counts[random.randint(0, gmm_n_components - 1)] = 1
      x = torch.empty(0, device=counts.device)
  
      # Samples an embedding for the speaker
      for k in torch.arange(gmm_n_components)[counts > 0]:
          # Considers full covariance type
          d_k = torch.distributions.multivariate_normal.MultivariateNormal(
              gmm_means[k], gmm_covariances[k]
          )
          x_k = torch.stack(
              [d_k.sample() for _ in range(int(counts[k]))]
          )
  
          x = torch.cat((x, x_k), dim=0)
  
      return x
  
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 6 for calling the MSTacotron2 obj's underlying member method code with example usage: obj.__sample_random_speaker() and returns: x