From c03b859beb7fa5f9b9e436c4f01ca1f2a401b957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stardust=C2=B7=E5=87=8F?= Date: Tue, 3 Oct 2023 19:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E6=AE=B5=E5=90=88?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/webui.py b/webui.py index c71538f..742b7c2 100644 --- a/webui.py +++ b/webui.py @@ -24,6 +24,7 @@ from text import cleaned_text_to_sequence, get_bert from text.cleaner import clean_text import gradio as gr import webbrowser +import numpy as np net_g = None @@ -103,22 +104,17 @@ def infer(text, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid, langua return audio -def tts_fn( - text, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale, language -): +def tts_fn(text, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale): + slices = text.split("|") + audio_list = [] with torch.no_grad(): - audio = infer( - text, - sdp_ratio=sdp_ratio, - noise_scale=noise_scale, - noise_scale_w=noise_scale_w, - length_scale=length_scale, - sid=speaker, - language=language, - ) - torch.cuda.empty_cache() - return "Success", (hps.data.sampling_rate, audio) - + for slice in slices: + audio = infer(slice, sdp_ratio=sdp_ratio, noise_scale=noise_scale, noise_scale_w=noise_scale_w, length_scale=length_scale, sid=speaker) + audio_list.append(audio) + silence = np.zeros(hps.data.sampling_rate) # 生成1秒的静音 + audio_list.append(silence) # 将静音添加到列表中 + audio_concat = np.concatenate(audio_list) + return "Success", (hps.data.sampling_rate, audio_concat) if __name__ == "__main__": parser = argparse.ArgumentParser()