Skip to content

Commit

Permalink
Update Bert-VITS2 for automated language detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Artrajz committed Nov 6, 2023
1 parent ed1897f commit 0883360
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions TTSManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,21 @@ def bert_vits2_infer(self, state, encode=True):
state["id"] = self.get_real_id(model_type=ModelType.BERT_VITS2, id=state["id"])
sampling_rate = model.sampling_rate

if state["lang"] == "auto":
state["lang"] = classify_language(state["text"], target_languages=model.lang)
# if state["lang"] == "auto":
# state["lang"] = classify_language(state["text"], target_languages=model.lang)

sentences_list = cut(state["text"], state["max"])
sentences_list = sentence_split_and_markup(state["text"], state["max"], state["lang"], state["speaker_lang"])
audios = []

pattern = r'\[(ZH|JA|EN)\](.*?)\[(ZH|JA|EN)\]'
for sentence in sentences_list:
audio = model.infer(sentence, state["id"], state["lang"], state["sdp_ratio"], state["noise"],
state["noise"], state["length"])
audios.append(audio)
audio = np.concatenate(audios)
matches = re.findall(pattern, sentence)
for match in matches:
language = match[0].lower()
text = match[1]
audio = model.infer(text, state["id"], language, state["sdp_ratio"], state["noise"],
state["noise"], state["length"])
audios.append(audio)
audio = np.concatenate(audios)

return self.encode(sampling_rate, audio, state["format"]) if encode else audio
return self.encode(sampling_rate, audio, state["format"]) if encode else audio

0 comments on commit 0883360

Please sign in to comment.