class_docstr: Tortoise model class.
  
  Currently only supports inference.
  
  Examples:
      >>> from TTS.tts.configs.tortoise_config import TortoiseConfig
      >>> from TTS.tts.models.tortoise import Tortoise
      >>> config = TortoiseConfig()
      >>> model = Tortoise.inif_from_config(config)
      >>> model.load_checkpoint(config, checkpoint_dir="paths/to/models_dir/", eval=True)
class_docstr_tok: ["Tortoise","model","class",".","Currently","only","supports","inference",".","Examples",":",">",">",">","from","TTS.tts.configs.tortoise_config","import","TortoiseConfig",">",">",">","from","TTS.tts.models.tortoise","import","Tortoise",">",">",">","config","=","TortoiseConfig","(",")",">",">",">","model","=","Tortoise.inif_from_config","(","config",")",">",">",">","model.load_checkpoint","(","config",",","checkpoint_dir=","''","paths\/to\/models_dir\/","''",",","eval=True",")"]
docstr: Transforms one or more voice_samples into a tuple (autoregressive_conditioning_latent, diffusion_conditioning_latent).
  These are expressive learned latents that encode aspects of the provided clips like voice, intonation, and acoustic
  properties.
  :param voice_samples: List of arbitrary reference clips, which should be *pairs* of torch tensors containing arbitrary kHz waveform data.
  :param latent_averaging_mode: 0/1/2 for following modes:
      0 - latents will be generated as in original tortoise, using ~4.27s from each voice sample, averaging latent across all samples
      1 - latents will be generated using (almost) entire voice samples, averaged across all the ~4.27s chunks
      2 - latents will be generated using (almost) entire voice samples, averaged per voice sample
docstr_tok: ["Transforms","one","or","more","voice_samples","into","a","tuple","(","autoregressive_conditioning_latent",",","diffusion_conditioning_latent",")",".","These","are","expressive","learned","latents","that","encode","aspects","of","the","provided","clips","like","voice",",","intonation",",","and","acoustic","properties",".",":","param","voice_samples",":","List","of","arbitrary","reference","clips",",","which","should","be","*","pairs","*","of","torch","tensors","containing","arbitrary","kHz","waveform","data",".",":","param","latent_averaging_mode",":","0\/1\/2","for","following","modes",":","0","-","latents","will","be","generated","as","in","original","tortoise",",","using","~4.27s","from","each","voice","sample",",","averaging","latent","across","all","samples","1","-","latents","will","be","generated","using","(","almost",")","entire","voice","samples",",","averaged","across","all","the","~4.27s","chunks","2","-","latents","will","be","generated","using","(","almost",")","entire","voice","samples",",","averaged","per","voice","sample"]
code: def get_conditioning_latents(
      self,
      voice_samples,
      return_mels=False,
      latent_averaging_mode=0,
      original_tortoise=False,
  ):
      """
      Transforms one or more voice_samples into a tuple (autoregressive_conditioning_latent, diffusion_conditioning_latent).
      These are expressive learned latents that encode aspects of the provided clips like voice, intonation, and acoustic
      properties.
      :param voice_samples: List of arbitrary reference clips, which should be *pairs* of torch tensors containing arbitrary kHz waveform data.
      :param latent_averaging_mode: 0/1/2 for following modes:
          0 - latents will be generated as in original tortoise, using ~4.27s from each voice sample, averaging latent across all samples
          1 - latents will be generated using (almost) entire voice samples, averaged across all the ~4.27s chunks
          2 - latents will be generated using (almost) entire voice samples, averaged per voice sample
      """
      assert latent_averaging_mode in [
          0,
          1,
          2,
      ], "latent_averaging mode has to be one of (0, 1, 2)"
  
      with torch.no_grad():
          voice_samples = [
              [v.to(self.device) for v in ls] for ls in voice_samples
          ]
  
          auto_conds = []
          for ls in voice_samples:
              auto_conds.append(
                  format_conditioning(
                      ls[0],
                      device=self.device,
                      mel_norm_file=self.mel_norm_path,
                  )
              )
          auto_conds = torch.stack(auto_conds, dim=1)
          with self.temporary_cuda(self.autoregressive) as ar:
              auto_latent = ar.get_conditioning(auto_conds)
  
          diffusion_conds = []
  
          DURS_CONST = self.args.duration_const
          for ls in voice_samples:
              # The diffuser operates at a sample rate of 24000 (except for the latent inputs)
              sample = (
                  torchaudio.functional.resample(ls[0], 22050, 24000)
                  if original_tortoise
                  else ls[1]
              )
              if latent_averaging_mode == 0:
                  sample = pad_or_truncate(sample, DURS_CONST)
                  cond_mel = wav_to_univnet_mel(
                      sample.to(self.device),
                      do_normalization=False,
                      device=self.device,
                  )
                  diffusion_conds.append(cond_mel)
              else:
                  from math import ceil
  
                  if latent_averaging_mode == 2:
                      temp_diffusion_conds = []
                  for chunk in range(
                      ceil(sample.shape[1] / DURS_CONST)
                  ):
                      current_sample = sample[
                          :,
                          chunk * DURS_CONST : (chunk + 1) * DURS_CONST,
                      ]
                      current_sample = pad_or_truncate(
                          current_sample, DURS_CONST
                      )
                      cond_mel = wav_to_univnet_mel(
                          current_sample.to(self.device),
                          do_normalization=False,
                          device=self.device,
                      )
                      if latent_averaging_mode == 1:
                          diffusion_conds.append(cond_mel)
                      elif latent_averaging_mode == 2:
                          temp_diffusion_conds.append(cond_mel)
                  if latent_averaging_mode == 2:
                      diffusion_conds.append(
                          torch.stack(temp_diffusion_conds).mean(0)
                      )
          diffusion_conds = torch.stack(diffusion_conds, dim=1)
  
          with self.temporary_cuda(self.diffusion) as diffusion:
              diffusion_latent = diffusion.get_conditioning(
                  diffusion_conds
              )
  
      if return_mels:
          return (
              auto_latent,
              diffusion_latent,
              auto_conds,
              diffusion_conds,
          )
      return auto_latent, diffusion_latent
  
imports: import os
  import random
  from contextlib import contextmanager
  from dataclasses import dataclass
  from time import time
  import torch
  import torch.nn.functional
  import torchaudio
  from coqpit import Coqpit
  from tqdm import tqdm
  from TTS.tts.layers.tortoise.arch_utils import TorchMelSpectrogram
  from TTS.tts.layers.tortoise.audio_utils import denormalize_tacotron_mel, load_voice, wav_to_univnet_mel
  from TTS.tts.layers.tortoise.autoregressive import UnifiedVoice
  from TTS.tts.layers.tortoise.classifier import AudioMiniEncoderWithClassifierHead
  from TTS.tts.layers.tortoise.clvp import CLVP
  from TTS.tts.layers.tortoise.diffusion import SpacedDiffusion, get_named_beta_schedule, space_timesteps
  from TTS.tts.layers.tortoise.diffusion_decoder import DiffusionTts
  from TTS.tts.layers.tortoise.random_latent_generator import RandomLatentConverter
  from TTS.tts.layers.tortoise.tokenizer import VoiceBpeTokenizer
  from TTS.tts.layers.tortoise.vocoder import VocConf, VocType
  from TTS.tts.layers.tortoise.wav2vec_alignment import Wav2VecAlignment
  from TTS.tts.models.base_tts import BaseTTS
label_desc: Use image node_id 3 for calling the Tortoise obj's underlying member method code with example usage: obj.get_conditioning_latents(voice_samples, return_mels, latent_averaging_mode, original_tortoise) and returns: auto_latent,  diffusion_latent, auto_latent,  diffusion_latent,  auto_conds,  diffusion_conds