MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / decode_codes

Method decode_codes

moss_tts_local_v1.5/streaming.py:596–615  ·  view source on GitHub ↗
(self, codes: torch.LongTensor)

Source from the content-addressed store, hash-verified

594
595 @torch.inference_mode()
596 def decode_codes(self, codes: torch.LongTensor) -> torch.Tensor:
597 if codes.numel() == 0:
598 return torch.empty((2, 0), dtype=torch.float32, device=self.device)
599 if codes.ndim != 2 or int(codes.shape[1]) != self.n_vq:
600 raise ValueError(f"Expected codes shape [T, {self.n_vq}], got {tuple(codes.shape)}.")
601 codes_qbt = codes.transpose(0, 1).contiguous().unsqueeze(1).to(device=self.device, dtype=torch.long)
602 codes_lengths = torch.tensor([codes_qbt.shape[-1]], device=self.device, dtype=torch.long)
603 active_mask = torch.tensor([codes_qbt.shape[-1] > 0], device=self.device, dtype=torch.bool)
604 self.audio_tokenizer._set_streaming_exec_mask(active_mask)
605 decoded = self.audio_tokenizer._decode_frame(codes_qbt, codes_lengths)
606 if decoded.audio is None or decoded.audio_lengths is None:
607 raise RuntimeError("audio tokenizer did not return audio/audio_lengths.")
608 audio_length = int(decoded.audio_lengths[0].item())
609 if audio_length <= 0:
610 return torch.empty(
611 (int(getattr(self.audio_tokenizer, "number_channels", 2)), 0),
612 dtype=torch.float32,
613 device=self.device,
614 )
615 return decoded.audio[0, :, :audio_length].detach().to(torch.float32)
616
617
618@torch.inference_mode()

Callers 2

warmup_streaming_runtimeFunction · 0.80
_codec_workerFunction · 0.80

Calls 1

toMethod · 0.45

Tested by

no test coverage detected