code: def get_ssl_features_disentangled(
      ssl_model,
      wav_featurizer,
      audio_path,
      emb_type="embedding_and_probs",
      use_unique_tokens=False,
      device="cpu",
  ):
      """
      Extracts content embedding, speaker embedding and duration tokens to be used as inputs for FastPitchModel_SSL
      synthesizer. Content embedding and speaker embedding extracted using SSLDisentangler model.
      Args:
          ssl_model: SSLDisentangler model
          wav_featurizer: WaveformFeaturizer object
          audio_path: path to audio file
          emb_type: Can be one of embedding_and_probs, embedding, probs, log_probs
          use_unique_tokens: If True, content embeddings with same predicted token are grouped and duration is different.
          device: device to run the model on
      Returns:
          content_embedding, speaker_embedding, duration
      """
      wav = load_wav(audio_path, wav_featurizer)
      audio_signal = wav[None]
      audio_signal_length = torch.tensor([wav.shape[0]])
      audio_signal = audio_signal.to(device)
      audio_signal_length = audio_signal_length.to(device)
      (
          _,
          speaker_embedding,
          content_embedding,
          content_log_probs,
          encoded_len,
      ) = ssl_model.forward_for_export(
          input_signal=audio_signal,
          input_signal_length=audio_signal_length,
          normalize_content=True,
      )
  
      content_embedding = content_embedding[0, : encoded_len[0].item()]
      content_log_probs = content_log_probs[
          : encoded_len[0].item(), 0, :
      ]
      content_embedding = content_embedding.t()
      content_log_probs = content_log_probs.t()
      content_probs = torch.exp(content_log_probs)
  
      ssl_downsampling_factor = (
          ssl_model._cfg.encoder.subsampling_factor
      )
  
      if emb_type == "probs":
          # content embedding is only character probabilities
          final_content_embedding = content_probs
  
      elif emb_type == "embedding":
          # content embedding is only output of content head of SSL backbone
          final_content_embedding = content_embedding
  
      elif emb_type == "log_probs":
          # content embedding is only log of character probabilities
          final_content_embedding = content_log_probs
  
      elif emb_type == "embedding_and_probs":
          # content embedding is the concatenation of character probabilities and output of content head of SSL backbone
          final_content_embedding = torch.cat(
              [content_embedding, content_probs], dim=0
          )
  
      else:
          raise ValueError(
              f"{emb_type} is not valid. Valid emb_type includes probs, embedding, log_probs or embedding_and_probs."
          )
  
      duration = (
          torch.ones(final_content_embedding.shape[1])
          * ssl_downsampling_factor
      )
      if use_unique_tokens:
          # group content embeddings with same predicted token (by averaging) and add the durations of the grouped embeddings
          # Eg. By default each content embedding corresponds to 4 frames of spectrogram (ssl_downsampling_factor)
          # If we group 3 content embeddings, the duration of the grouped embedding will be 12 frames.
          # This is useful for adapting the duration during inference based on the speaker.
          token_predictions = torch.argmax(content_probs, dim=0)
          content_buffer = [final_content_embedding[:, 0]]
          unique_content_embeddings = []
          unique_tokens = []
          durations = []
          for _t in range(1, final_content_embedding.shape[1]):
              if token_predictions[_t] == token_predictions[_t - 1]:
                  content_buffer.append(final_content_embedding[:, _t])
              else:
                  durations.append(
                      len(content_buffer) * ssl_downsampling_factor
                  )
                  unique_content_embeddings.append(
                      torch.mean(torch.stack(content_buffer), dim=0)
                  )
                  content_buffer = [final_content_embedding[:, _t]]
                  unique_tokens.append(token_predictions[_t].item())
  
          if len(content_buffer) > 0:
              durations.append(
                  len(content_buffer) * ssl_downsampling_factor
              )
              unique_content_embeddings.append(
                  torch.mean(torch.stack(content_buffer), dim=0)
              )
              unique_tokens.append(token_predictions[_t].item())
  
          unique_content_embedding = torch.stack(
              unique_content_embeddings
          )
          final_content_embedding = unique_content_embedding.t()
          duration = torch.tensor(durations).float()
  
      duration = duration.to(device)
      return (
          final_content_embedding[None],
          speaker_embedding,
          duration[None],
      )
  
file_path: NeMo/scripts/ssl_tts/ssl_tts_vc.py
imports: import argparse
  import os
  import librosa
  import soundfile
  import torch
  from nemo.collections.asr.parts.preprocessing.features import WaveformFeaturizer
  from nemo.collections.tts.models import fastpitch_ssl, hifigan, ssl_tts
  from nemo.collections.tts.parts.utils.tts_dataset_utils import get_base_dir
label_desc: Use image node_id 5 for calling a global function with example usage: get_ssl_features_disentangled(ssl_model, wav_featurizer, audio_path, emb_type, use_unique_tokens, device) and returns: final_content_embedding,  speaker_embedding,  duration