MCPcopy Create free account
hub / github.com/FireRedTeam/FireRedTTS2 / forward_chunk

Method forward_chunk

fireredtts2/codec/decoder.py:523–546  ·  view source on GitHub ↗

ISTFTHead can be adapted in streaming inference without retraining. Args: x: shape (B, T, C) cache: shape (B, N, T=3), istft cache Returns: audio: shape (B, t)

(
        self, x: torch.Tensor, cache: torch.Tensor = None, last_chunk: bool = False
    )

Source from the content-addressed store, hash-verified

521 return audio, audio_length
522
523 def forward_chunk(
524 self, x: torch.Tensor, cache: torch.Tensor = None, last_chunk: bool = False
525 ):
526 """ISTFTHead can be adapted in streaming inference without retraining.
527
528 Args:
529 x: shape (B, T, C)
530 cache: shape (B, N, T=3), istft cache
531 Returns:
532 audio: shape (B, t)
533 """
534 x_pred = self.out(x)
535 x_pred = x_pred.transpose(1, 2)
536 mag, p = x_pred.chunk(2, dim=1)
537 mag = torch.exp(mag) # (B, C, T)
538 mag = torch.clip(
539 mag, max=1e2
540 ) # safeguard to prevent excessively large magnitudes
541 # wrapping happens here. These two lines produce real and imaginary value
542 x = torch.cos(p)
543 y = torch.sin(p)
544 S = mag * (x + 1j * y) # (B, C, T)
545 audio, new_cache = self.istft.forward_chunk(S, cache, last_chunk)
546 return audio, new_cache
547
548
549# UpsampleConv(50->100Hz) + VocosBackbone + ISTFTHead

Callers

nothing calls this directly

Calls 1

forward_chunkMethod · 0.45

Tested by

no test coverage detected