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",")"]
code: def __init__(self, config: Coqpit):
      super().__init__(config, ap=None, tokenizer=None)
      self.mel_norm_path = None
      self.config = config
      self.ar_checkpoint = self.args.ar_checkpoint
      self.diff_checkpoint = (
          self.args.diff_checkpoint
      )  # TODO: check if this is even needed
      self.models_dir = config.model_dir
      self.autoregressive_batch_size = (
          pick_best_batch_size_for_gpu()
          if self.args.autoregressive_batch_size is None
          else self.args.autoregressive_batch_size
      )
      self.enable_redaction = self.args.enable_redaction
      self.device = torch.device(
          "cuda" if torch.cuda.is_available() else "cpu"
      )
      if self.enable_redaction:
          self.aligner = Wav2VecAlignment()
  
      self.tokenizer = VoiceBpeTokenizer()
  
      self.autoregressive = UnifiedVoice(
          max_mel_tokens=self.args.ar_max_mel_tokens,
          max_text_tokens=self.args.ar_max_text_tokens,
          max_conditioning_inputs=self.args.ar_max_conditioning_inputs,
          layers=self.args.ar_layers,
          model_dim=self.args.ar_model_dim,
          heads=self.args.ar_heads,
          number_text_tokens=self.args.ar_number_text_tokens,
          start_text_token=self.args.ar_start_text_token,
          checkpointing=self.args.ar_checkpointing,
          train_solo_embeddings=self.args.ar_train_solo_embeddings,
      ).cpu()
  
      self.diffusion = DiffusionTts(
          model_channels=self.args.diff_model_channels,
          num_layers=self.args.diff_num_layers,
          in_channels=self.args.diff_in_channels,
          out_channels=self.args.diff_out_channels,
          in_latent_channels=self.args.diff_in_latent_channels,
          in_tokens=self.args.diff_in_tokens,
          dropout=self.args.diff_dropout,
          use_fp16=self.args.diff_use_fp16,
          num_heads=self.args.diff_num_heads,
          layer_drop=self.args.diff_layer_drop,
          unconditioned_percentage=self.args.diff_unconditioned_percentage,
      ).cpu()
  
      self.clvp = CLVP(
          dim_text=self.args.clvp_dim_text,
          dim_speech=self.args.clvp_dim_speech,
          dim_latent=self.args.clvp_dim_latent,
          num_text_tokens=self.args.clvp_num_text_tokens,
          text_enc_depth=self.args.clvp_text_enc_depth,
          text_seq_len=self.args.clvp_text_seq_len,
          text_heads=self.args.clvp_text_heads,
          num_speech_tokens=self.args.clvp_num_speech_tokens,
          speech_enc_depth=self.args.clvp_speech_enc_depth,
          speech_heads=self.args.clvp_speech_heads,
          speech_seq_len=self.args.clvp_speech_seq_len,
          use_xformers=self.args.clvp_use_xformers,
      ).cpu()
  
      self.vocoder = self.args.vocoder.value.constructor().cpu()
  
      # Random latent generators (RLGs) are loaded lazily.
      self.rlg_auto = None
      self.rlg_diffusion = None
  
      if self.args.high_vram:
          self.autoregressive = self.autoregressive.to(self.device)
          self.diffusion = self.diffusion.to(self.device)
          self.clvp = self.clvp.to(self.device)
          self.vocoder = self.vocoder.to(self.device)
      self.high_vram = self.args.high_vram
  
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 1 to create a new Tortoise object from inherited base classes: BaseTTS with example: obj = Tortoise(config)