Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tts_mel in streaming inference #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions flow_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ def token2wav(self, token, uuid, prompt_token=torch.zeros(1, 0, dtype=torch.int3
# mel overlap fade in out
if self.mel_overlap_dict[uuid] is not None:
tts_mel = fade_in_out(tts_mel, self.mel_overlap_dict[uuid], self.mel_window)
if finalize is False:
self.mel_overlap_dict[uuid] = tts_mel[:, :, -self.mel_overlap_len:]
tts_mel = tts_mel[:, :, :-self.mel_overlap_len]

# append hift cache
if self.hift_cache_dict[uuid] is not None:
hift_cache_mel, hift_cache_source = self.hift_cache_dict[uuid]['mel'], self.hift_cache_dict[uuid]['source']
tts_mel = torch.concat([hift_cache_mel, tts_mel], dim=2)

hift_tts_mel = torch.concat([hift_cache_mel, tts_mel], dim=2)
else:
hift_tts_mel = tts_mel
hift_cache_source = torch.zeros(1, 1, 0)

# _tts_mel=tts_mel.contiguous()
# keep overlap mel and hift cache
if finalize is False:
self.mel_overlap_dict[uuid] = tts_mel[:, :, -self.mel_overlap_len:]
tts_mel = tts_mel[:, :, :-self.mel_overlap_len]
tts_speech, tts_source = self.hift.inference(mel=tts_mel, cache_source=hift_cache_source)
tts_speech, tts_source = self.hift.inference(mel=hift_tts_mel, cache_source=hift_cache_source)

if finalize is False:
self.hift_cache_dict[uuid] = {'mel': tts_mel[:, :, -self.mel_cache_len:],
'source': tts_source[:, :, -self.source_cache_len:],
'speech': tts_speech[:, -self.source_cache_len:]}
Expand All @@ -82,7 +85,6 @@ def token2wav(self, token, uuid, prompt_token=torch.zeros(1, 0, dtype=torch.int3
tts_speech = tts_speech[:, :-self.source_cache_len]

else:
tts_speech, tts_source = self.hift.inference(mel=tts_mel, cache_source=hift_cache_source)
del self.hift_cache_dict[uuid]
del self.mel_overlap_dict[uuid]
# if uuid in self.hift_cache_dict.keys() and self.hift_cache_dict[uuid] is not None:
Expand Down Expand Up @@ -137,6 +139,7 @@ def stream_inference(self, token):

# Convert Mel spectrogram to audio using HiFi-GAN
tts_speech = torch.cat(tts_speechs, dim=-1).cpu()

tts_mel = torch.cat(tts_mels, dim=-1).cpu()
print(token.size(1), tts_mel.size(-1), tts_speech.size(-1))
print(int(token.size(1) / self.flow.input_frame_rate * 22050 / 256), tts_mel.size(-1)*256)
return tts_speech.cpu()