feat(webui): Implement speech synthesis progress bar

This commit is contained in:
Arcitec 2025-09-11 00:06:05 +02:00
parent 55095de317
commit 555e146fb4
2 changed files with 21 additions and 17 deletions

View File

@ -291,9 +291,9 @@ class IndexTTS:
- 越大bucket数量越少batch越多推理速度越**占用内存更多可能影响质量
- 越小bucket数量越多batch越少推理速度越**占用内存和质量更接近于非快速推理
"""
print(">> start fast inference...")
print(">> starting fast inference...")
self._set_gr_progress(0, "start fast inference...")
self._set_gr_progress(0, "starting fast inference...")
if verbose:
print(f"origin text:{text}")
start_time = time.perf_counter()
@ -385,7 +385,7 @@ class IndexTTS:
processed_num += batch_num
# gpt speech
self._set_gr_progress(0.2 + 0.3 * processed_num / all_batch_num,
f"gpt inference speech... {processed_num}/{all_batch_num}")
f"gpt speech inference {processed_num}/{all_batch_num}...")
m_start_time = time.perf_counter()
with torch.no_grad():
with torch.amp.autocast(batch_text_tokens.device.type, enabled=self.dtype is not None,
@ -407,7 +407,7 @@ class IndexTTS:
gpt_gen_time += time.perf_counter() - m_start_time
# gpt latent
self._set_gr_progress(0.5, "gpt inference latents...")
self._set_gr_progress(0.5, "gpt latents inference...")
all_idxs = []
all_latents = []
has_warned = False
@ -456,7 +456,7 @@ class IndexTTS:
latent_length = len(all_latents)
# bigvgan chunk decode
self._set_gr_progress(0.7, "bigvgan decode...")
self._set_gr_progress(0.7, "bigvgan decoding...")
tqdm_progress = tqdm(total=latent_length, desc="bigvgan")
for items in chunk_latents:
tqdm_progress.update(len(items))
@ -478,7 +478,7 @@ class IndexTTS:
self.torch_empty_cache()
# wav audio output
self._set_gr_progress(0.9, "save audio...")
self._set_gr_progress(0.9, "saving audio...")
wav = torch.cat(wavs, dim=1)
wav_length = wav.shape[-1] / sampling_rate
print(f">> Reference audio length: {cond_mel_frame * 256 / sampling_rate:.2f} seconds")
@ -509,8 +509,8 @@ class IndexTTS:
# 原始推理模式
def infer(self, audio_prompt, text, output_path, verbose=False, max_text_tokens_per_segment=120,
**generation_kwargs):
print(">> start inference...")
self._set_gr_progress(0, "start inference...")
print(">> starting inference...")
self._set_gr_progress(0, "starting inference...")
if verbose:
print(f"origin text:{text}")
start_time = time.perf_counter()
@ -578,7 +578,7 @@ class IndexTTS:
# print(text_len)
progress += 1
self._set_gr_progress(0.2 + 0.4 * (progress - 1) / len(segments),
f"gpt inference latent... {progress}/{len(segments)}")
f"gpt latents inference {progress}/{len(segments)}...")
m_start_time = time.perf_counter()
with torch.no_grad():
with torch.amp.autocast(text_tokens.device.type, enabled=self.dtype is not None, dtype=self.dtype):
@ -620,7 +620,7 @@ class IndexTTS:
print(f"fix codes shape: {codes.shape}, codes type: {codes.dtype}")
print(f"code len: {code_lens}")
self._set_gr_progress(0.2 + 0.4 * progress / len(segments),
f"gpt inference speech... {progress}/{len(segments)}")
f"gpt speech inference {progress}/{len(segments)}...")
m_start_time = time.perf_counter()
# latent, text_lens_out, code_lens_out = \
with torch.amp.autocast(text_tokens.device.type, enabled=self.dtype is not None, dtype=self.dtype):
@ -644,7 +644,7 @@ class IndexTTS:
# wavs.append(wav[:, :-512])
wavs.append(wav.cpu()) # to cpu before saving
end_time = time.perf_counter()
self._set_gr_progress(0.9, "save audio...")
self._set_gr_progress(0.9, "saving audio...")
wav = torch.cat(wavs, dim=1)
wav_length = wav.shape[-1] / sampling_rate
print(f">> Reference audio length: {cond_mel_frame * 256 / sampling_rate:.2f} seconds")

View File

@ -298,8 +298,8 @@ class IndexTTS2:
emo_vector=None,
use_emo_text=False, emo_text=None, use_random=False, interval_silence=200,
verbose=False, max_text_tokens_per_segment=120, **generation_kwargs):
print(">> start inference...")
self._set_gr_progress(0, "start inference...")
print(">> starting inference...")
self._set_gr_progress(0, "starting inference...")
if verbose:
print(f"origin text:{text}, spk_audio_prompt:{spk_audio_prompt},"
f" emo_audio_prompt:{emo_audio_prompt}, emo_alpha:{emo_alpha}, "
@ -400,9 +400,10 @@ class IndexTTS2:
self._set_gr_progress(0.1, "text processing...")
text_tokens_list = self.tokenizer.tokenize(text)
segments = self.tokenizer.split_segments(text_tokens_list, max_text_tokens_per_segment)
segments_count = len(segments)
if verbose:
print("text_tokens_list:", text_tokens_list)
print("segments count:", len(segments))
print("segments count:", segments_count)
print("max_text_tokens_per_segment:", max_text_tokens_per_segment)
print(*segments, sep="\n")
do_sample = generation_kwargs.pop("do_sample", True)
@ -421,9 +422,11 @@ class IndexTTS2:
gpt_forward_time = 0
s2mel_time = 0
bigvgan_time = 0
progress = 0
has_warned = False
for sent in segments:
for seg_idx, sent in enumerate(segments):
self._set_gr_progress(0.2 + 0.7 * seg_idx / segments_count,
f"speech synthesis {seg_idx + 1}/{segments_count}...")
text_tokens = self.tokenizer.convert_tokens_to_ids(sent)
text_tokens = torch.tensor(text_tokens, dtype=torch.int32, device=self.device).unsqueeze(0)
if verbose:
@ -553,7 +556,8 @@ class IndexTTS2:
# wavs.append(wav[:, :-512])
wavs.append(wav.cpu()) # to cpu before saving
end_time = time.perf_counter()
self._set_gr_progress(0.9, "save audio...")
self._set_gr_progress(0.9, "saving audio...")
wavs = self.insert_interval_silence(wavs, sampling_rate=sampling_rate, interval_silence=interval_silence)
wav = torch.cat(wavs, dim=1)
wav_length = wav.shape[-1] / sampling_rate