[Fix] Fix Volume inconsistent (#144)
* [Fix] Fix Volume inconsistent Fixed the problem of volume inconsistency between sentence segments caused by Gradio volume normalization * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
21
webui.py
21
webui.py
@@ -40,7 +40,7 @@ def generate_audio(
|
|||||||
language,
|
language,
|
||||||
):
|
):
|
||||||
audio_list = []
|
audio_list = []
|
||||||
silence = np.zeros(hps.data.sampling_rate // 2)
|
silence = np.zeros(hps.data.sampling_rate // 2, dtype=np.int16)
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
for piece in slices:
|
for piece in slices:
|
||||||
audio = infer(
|
audio = infer(
|
||||||
@@ -55,7 +55,8 @@ def generate_audio(
|
|||||||
net_g=net_g,
|
net_g=net_g,
|
||||||
device=device,
|
device=device,
|
||||||
)
|
)
|
||||||
audio_list.append(audio)
|
audio16bit = gr.processing_utils.convert_to_16_bit_wav(audio)
|
||||||
|
audio_list.append(audio16bit)
|
||||||
audio_list.append(silence) # 将静音添加到列表中
|
audio_list.append(silence) # 将静音添加到列表中
|
||||||
return audio_list
|
return audio_list
|
||||||
|
|
||||||
@@ -92,11 +93,13 @@ def tts_split(
|
|||||||
net_g=net_g,
|
net_g=net_g,
|
||||||
device=device,
|
device=device,
|
||||||
)
|
)
|
||||||
audio_list.append(audio)
|
audio16bit = gr.processing_utils.convert_to_16_bit_wav(audio)
|
||||||
silence = np.zeros((int)(44100 * interval_between_para))
|
audio_list.append(audio16bit)
|
||||||
|
silence = np.zeros((int)(44100 * interval_between_para), dtype=np.int16)
|
||||||
audio_list.append(silence)
|
audio_list.append(silence)
|
||||||
else:
|
else:
|
||||||
for p in para_list:
|
for p in para_list:
|
||||||
|
audio_list_sent = []
|
||||||
sent_list = re_matching.cut_sent(p)
|
sent_list = re_matching.cut_sent(p)
|
||||||
for s in sent_list:
|
for s in sent_list:
|
||||||
audio = infer(
|
audio = infer(
|
||||||
@@ -111,14 +114,18 @@ def tts_split(
|
|||||||
net_g=net_g,
|
net_g=net_g,
|
||||||
device=device,
|
device=device,
|
||||||
)
|
)
|
||||||
audio_list.append(audio)
|
audio_list_sent.append(audio)
|
||||||
silence = np.zeros((int)(44100 * interval_between_sent))
|
silence = np.zeros((int)(44100 * interval_between_sent))
|
||||||
audio_list.append(silence)
|
audio_list_sent.append(silence)
|
||||||
if (interval_between_para - interval_between_sent) > 0:
|
if (interval_between_para - interval_between_sent) > 0:
|
||||||
silence = np.zeros(
|
silence = np.zeros(
|
||||||
(int)(44100 * (interval_between_para - interval_between_sent))
|
(int)(44100 * (interval_between_para - interval_between_sent))
|
||||||
)
|
)
|
||||||
audio_list.append(silence)
|
audio_list_sent.append(silence)
|
||||||
|
audio16bit = gr.processing_utils.convert_to_16_bit_wav(
|
||||||
|
np.concatenate(audio_list_sent)
|
||||||
|
) # 对完整句子做音量归一
|
||||||
|
audio_list.append(audio16bit)
|
||||||
audio_concat = np.concatenate(audio_list)
|
audio_concat = np.concatenate(audio_list)
|
||||||
return ("Success", (44100, audio_concat))
|
return ("Success", (44100, audio_concat))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user