feature: 集成bert_vits

This commit is contained in:
killua committed 2024-06-24 11:02:42 +08:00
1 parent 2b98752db1
commit c58c7c9a5b
9 files changed
+69 -51

No files matched your search

+27 -20
View File
@@ -395,29 +395,28 @@ class TextToSpeech:
def synthesize(self,
text,
speaker_idx=0, # self.speakers 的 index,指定说话
sdp_ratio=0.5,
noise_scale=0.6,
noise_scale_w=0.9,
length_scale=1.0, # 越大语速越慢
language="mix", # ["ZH", "EN", "mix"] 三选一
opt_cut_by_send=False, # 按句切分 在按段落切分的基础上再按句子切分文本
interval_between_para=1.0, # 段间停顿(秒),需要大于句间停顿才有效
interval_between_sent=0.2, # 句间停顿(秒),勾选按句切分才生效
audio_prompt=None,
text_prompt="",
prompt_mode="Text prompts",
style_text="", # "使用辅助文本的语意来辅助生成对话(语言保持与主文本相同)\n\n"
# "**注意**:不要使用**指令式文本**(如:开心),要使用**带有强烈情感的文本**(如:我好快乐!!!)\n\n"
# "效果较不明确,留空即为不使用该功能"
style_weight=0.7, # "主文本和辅助文本的bert混合比率,0表示仅主文本,1表示仅辅助文本
en_ratio=1.0 # 中英混合时,英文速度控制,越大英文速度越慢
tts_info,
):
"""
return: audio, sample_rate
"""
speaker_id = tts_info['speaker_id'] # self.speakers 的 index,指定说话
sdp_ratio = tts_info['sdp_ratio']
noise_scale = tts_info['noise_scale']
noise_scale_w = tts_info['noise_scale_w']
length_scale = tts_info['length_scale']
language = tts_info['language'] # ["ZH", "EN", "mix"] 三选一
opt_cut_by_send = tts_info['opt_cut_by_send']
interval_between_para = tts_info['interval_between_para'] # 段间停顿(秒),需要大于句间停顿才有效
interval_between_sent = tts_info['interval_between_sent'] # 句间停顿(秒),勾选按句切分才生效
audio_prompt = None
text_prompt = ""
prompt_mode = "Text prompts"
style_text = tts_info['style_text']
style_weight = tts_info['style_weight']
en_ratio = tts_info['en_ratio']
speaker = self.speakers[speaker_idx]
speaker = self.speakers[speaker_id]
if language == "mix":
language, text = self.format_utils(text, speaker)
@@ -455,9 +454,17 @@ class TextToSpeech:
style_weight
)
# return text_output, audio_output
return audio_output[1], audio_output[0]
return self.convert_numpy_to_bytes(audio_output[1])
def print_speakers_info(self):
for i, speaker in enumerate(self.speakers):
print(f"id: {i}, speaker: {speaker}")
def convert_numpy_to_bytes(self, audio_data):
if isinstance(audio_data, np.ndarray):
if audio_data.dtype == np.dtype('float32'):
audio_data = np.int16(audio_data * np.iinfo(np.int16).max)
audio_data = audio_data.tobytes()
return audio_data
else:
raise TypeError("audio_data must be a numpy array")