MCPcopy Create free account
hub / github.com/1038lab/ComfyUI-FireRedTTS / _encode_one_batch

Method _encode_one_batch

fireredtts2/codec/model.py:218–235  ·  view source on GitHub ↗
(self, audio16k: torch.Tensor)

Source from the content-addressed store, hash-verified

216 return cls(codec)
217
218 def _encode_one_batch(self, audio16k: torch.Tensor):
219 B, T = audio16k.shape
220 audio16k_length = torch.tensor(
221 [T] * B, dtype=torch.long, device=audio16k.device
222 )
223 # Semantic
224 ssl, ssl_length = self.ssl.forward(audio16k, audio16k_length)
225 ssl = ssl.clone() # For onnx export
226 sem_feats, sem_length = self.ssl_adaptor(ssl, ssl_length)
227 # Acoustic
228 aco_feats, aco_length = self.acoustic_encoder(audio16k, audio16k_length)
229 # VQ
230 vq_in_feats = torch.cat([sem_feats, aco_feats], dim=2)
231 vq_in_feats, vq_in_length = self.downsample(vq_in_feats, aco_length)
232 # RVQ,
233 indices = self.rvq.encode_codes(vq_in_feats.transpose(1, 2)) # (nq, B, L)
234 indices = indices.permute(1, 0, 2)
235 return indices # (B, nq, L)
236
237 @staticmethod
238 def _pad_and_chunk(audio: torch.Tensor, chunk_size: int) -> List[torch.Tensor]:

Callers 1

encodeMethod · 0.95

Calls 2

encode_codesMethod · 0.80
forwardMethod · 0.45

Tested by

no test coverage detected