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 by retrieving pre-trained dense and quantizer models specified by their parameters
  (names and vocabulary size).
  
  Args:
      dense_model_name (str): Name of the dense module used to represent the audio
      quantizer_model_name (str): Name of the quantizer module that converts dense representation into discrete tokens
      vocab_size (int): Specifies the codebook size
      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","by","retrieving","pre-trained","dense","and","quantizer","models","specified","by","their","parameters","(","names","and","vocabulary","size",")",".","Args",":","dense_model_name","(","str",")",":","Name","of","the","dense","module","used","to","represent","the","audio","quantizer_model_name","(","str",")",":","Name","of","the","quantizer","module","that","converts","dense","representation","into","discrete","tokens","vocab_size","(","int",")",":","Specifies","the","codebook","size","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 by_name(
      cls,
      dense_model_name: str,
      quantizer_model_name: str,
      vocab_size: int,
      deduplicate: bool,
      add_bos_eos: bool = False,
      need_f0: bool = True,
      f0_normalizer: Optional[Callable] = None,
      f0_quantizer: Optional[Callable] = None,
  ) -> "SpeechEncoder":
      """Builds a SpeechEncoder instance by retrieving pre-trained dense and quantizer models specified by their parameters
      (names and vocabulary size).
  
      Args:
          dense_model_name (str): Name of the dense module used to represent the audio
          quantizer_model_name (str): Name of the quantizer module that converts dense representation into discrete tokens
          vocab_size (int): Specifies the codebook size
          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
      """
      dense_model = dispatch_dense_model(dense_model_name)
      quantizer_model = dispatch_quantizer(
          dense_model_name, quantizer_model_name, vocab_size
      )
  
      return cls(
          dense_model,
          quantizer_model,
          deduplicate,
          add_bos_eos,
          need_f0,
          f0_normalizer,
          f0_quantizer,
      )
  
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 2 for calling the SpeechEncoder obj's underlying member method code with example usage: obj.by_name(cls, dense_model_name, quantizer_model_name, vocab_size, deduplicate, add_bos_eos, need_f0, f0_normalizer, f0_quantizer) and returns: cls