class_docstr: SpeechEncoder encodes speech into streams of (pseudo-)units, unit durations,
  and, optionally, F0.
class_docstr_tok: ["SpeechEncoder","encodes","speech","into","streams","of","(","pseudo-",")","units",",","unit","durations",",","and",",","optionally",",","F0","."]
docstr: Builds a SpeechEncoder instance. SpeechEncoder encodes speech into streams of (pseudo-)units, unit durations,
  and, optionally, F0.
  
  Args:
      dense_model (torch.nn.Module): Dense module used to represent the audio
      quantizer_model (torch.nn.Module): Quantize module that converts dense representation into discrete tokens
      deduplicate (bool): if set, run-length encoding is applied so that repeated tokens are deduplicated
          and duration channel contains the number of repeats of the token.
      add_bos_eos (bool, optional): if set, each token sequences will be prepended with a special token (bos)
          and appended with another special token (eos).
      need_f0 (bool, optional): whether F0 stream should be returned. Estimating F0 is computationally heavy,
          consider disabling it if not needed.
      f0_normalizer (Optional[Callable], optional): A callback that allows F0 normalization (e.g., per-speaker)
      f0_quantizer (Optional[Callable], optional): F0 quantization module
docstr_tok: ["Builds","a","SpeechEncoder","instance",".","SpeechEncoder","encodes","speech","into","streams","of","(","pseudo-",")","units",",","unit","durations",",","and",",","optionally",",","F0",".","Args",":","dense_model","(","torch.nn.Module",")",":","Dense","module","used","to","represent","the","audio","quantizer_model","(","torch.nn.Module",")",":","Quantize","module","that","converts","dense","representation","into","discrete","tokens","deduplicate","(","bool",")",":","if","set",",","run-length","encoding","is","applied","so","that","repeated","tokens","are","deduplicated","and","duration","channel","contains","the","number","of","repeats","of","the","token",".","add_bos_eos","(","bool",",","optional",")",":","if","set",",","each","token","sequences","will","be","prepended","with","a","special","token","(","bos",")","and","appended","with","another","special","token","(","eos",")",".","need_f0","(","bool",",","optional",")",":","whether","F0","stream","should","be","returned",".","Estimating","F0","is","computationally","heavy",",","consider","disabling","it","if","not","needed",".","f0_normalizer","(","Optional","[","Callable","]",",","optional",")",":","A","callback","that","allows","F0","normalization","(","e.g.",",","per-speaker",")","f0_quantizer","(","Optional","[","Callable","]",",","optional",")",":","F0","quantization","module"]
code: def __init__(
      self,
      dense_model: torch.nn.Module,
      quantizer_model: torch.nn.Module,
      deduplicate: bool,
      add_bos_eos: bool = False,
      need_f0: bool = True,
      f0_normalizer: Optional[Callable] = None,
      f0_quantizer: Optional[Callable] = None,
  ):
      """Builds a SpeechEncoder instance. SpeechEncoder encodes speech into streams of (pseudo-)units, unit durations,
      and, optionally, F0.
  
      Args:
          dense_model (torch.nn.Module): Dense module used to represent the audio
          quantizer_model (torch.nn.Module): Quantize module that converts dense representation into discrete tokens
          deduplicate (bool): if set, run-length encoding is applied so that repeated tokens are deduplicated
              and duration channel contains the number of repeats of the token.
          add_bos_eos (bool, optional): if set, each token sequences will be prepended with a special token (bos)
              and appended with another special token (eos).
          need_f0 (bool, optional): whether F0 stream should be returned. Estimating F0 is computationally heavy,
              consider disabling it if not needed.
          f0_normalizer (Optional[Callable], optional): A callback that allows F0 normalization (e.g., per-speaker)
          f0_quantizer (Optional[Callable], optional): F0 quantization module
      """
      super().__init__()
      self.dense_model = dense_model
      self.quantizer_model = quantizer_model
  
      self.deduplicate = deduplicate
      self.add_bos_eos = add_bos_eos
      self.need_f0 = need_f0
      self.f0_normalizer = f0_normalizer
      self.f0_quantizer = f0_quantizer
  
      self.unit_vocab_size = self.quantizer_model.vocab_size
  
      self.register_buffer(
          "bos", torch.tensor([self.unit_vocab_size], dtype=torch.int)
      )
      self.register_buffer(
          "eos",
          torch.tensor([self.unit_vocab_size + 1], dtype=torch.int),
      )
  
      self.register_buffer(
          "_float_tensor", torch.tensor([0], dtype=torch.float)
      )
  
file_path: textlesslib/textless/data/speech_encoder.py
imports: import torch
  import torch.nn
  import torchaudio
  from typing import Optional, Callable, Dict
  from textless import dispatch_dense_model, dispatch_quantizer
  from textless import dispatch_dense_model
  from textless.data.f0_preprocess import get_f0, align_f0_to_durations, F0_FRAME_SPACE
  from .collater_utils import wrap_bos_eos
label_desc: Use image node_id 1 to create a new SpeechEncoder object from inherited base classes: torch.nn with example: obj = SpeechEncoder(dense_model, quantizer_model, deduplicate, add_bos_eos, need_f0, f0_normalizer, f0_quantizer)