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: Encodes a raw waveform tensor into two or three aligned & synchronised streams: pseudo-unit (token),
  duration, and pitch aka F0 streams. F0 is only provided if the SpeechEncoder instance
  was initialized with `requires_f0=True`.
  
  Args:
      waveform (torch.Tensor): audio to be encoded
      speaker (Optional[str], optional): speaker id to be passed to the F0 normalizer.
      Can be safely ignored if no F0 stream is requested or no per-speaker F0 normalizer
      provided.
  
  Returns:
      Dict[str, torch.Tensor]: dictionary with the following keys:
       * "units": contains an int tensor with the unit stream,
       * "durations": duration of each unit, measured in frames,
       * "dense": dense encoding of the audio, as provided by the underlying dense model,
       * "f0": F0 stream - only returned if `requires_f0=True` was set in the constructor.
docstr_tok: ["Encodes","a","raw","waveform","tensor","into","two","or","three","aligned","&","synchronised","streams",":","pseudo-unit","(","token",")",",","duration",",","and","pitch","aka","F0","streams",".","F0","is","only","provided","if","the","SpeechEncoder","instance","was","initialized","with","`","requires_f0=True","`",".","Args",":","waveform","(","torch.Tensor",")",":","audio","to","be","encoded","speaker","(","Optional","[","str","]",",","optional",")",":","speaker","id","to","be","passed","to","the","F0","normalizer",".","Can","be","safely","ignored","if","no","F0","stream","is","requested","or","no","per-speaker","F0","normalizer","provided",".","Returns",":","Dict","[","str",",","torch.Tensor","]",":","dictionary","with","the","following","keys",":","*","``","units","''",":","contains","an","int","tensor","with","the","unit","stream",",","*","``","durations","''",":","duration","of","each","unit",",","measured","in","frames",",","*","``","dense","''",":","dense","encoding","of","the","audio",",","as","provided","by","the","underlying","dense","model",",","*","``","f0","''",":","F0","stream","-","only","returned","if","`","requires_f0=True","`","was","set","in","the","constructor","."]
code: def forward(
      self, waveform: torch.Tensor, speaker: Optional[str] = None
  ) -> Dict[str, torch.Tensor]:
      """Encodes a raw waveform tensor into two or three aligned & synchronised streams: pseudo-unit (token),
      duration, and pitch aka F0 streams. F0 is only provided if the SpeechEncoder instance
      was initialized with `requires_f0=True`.
  
      Args:
          waveform (torch.Tensor): audio to be encoded
          speaker (Optional[str], optional): speaker id to be passed to the F0 normalizer.
          Can be safely ignored if no F0 stream is requested or no per-speaker F0 normalizer
          provided.
  
      Returns:
          Dict[str, torch.Tensor]: dictionary with the following keys:
           * "units": contains an int tensor with the unit stream,
           * "durations": duration of each unit, measured in frames,
           * "dense": dense encoding of the audio, as provided by the underlying dense model,
           * "f0": F0 stream - only returned if `requires_f0=True` was set in the constructor.
      """
      units, durations, f0, dense_features = get_streams(
          waveform,
          speaker,
          self.dense_model,
          self.quantizer_model,
          self.f0_normalizer,
          self.f0_quantizer,
          self.need_f0,
          self.deduplicate,
          self.f0_code_ratio,
      )
  
      if self.add_bos_eos:
          units, durations, f0, dense_features = wrap_bos_eos(
              units, durations, f0, dense_features, self.bos, self.eos
          )
  
      item = {
          "units": units.to(self.device),
          "durations": durations.to(self.device),
          "dense": dense_features,
      }
      if f0 is not None:
          item["f0"] = f0
  
      return item
  
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 9 for calling the SpeechEncoder obj's underlying member method code with example usage: obj.forward(waveform, speaker) and returns: item