Refactor: improve regular expression performance during NLP

Improve performance by pre-compiling regular expressions that are executed many times.
This commit is contained in:
tsukumi
2024-05-12 00:26:46 +09:00
parent 2d6baa3928
commit 44693e7d6b
5 changed files with 171 additions and 150 deletions

View File

@@ -1,5 +1,6 @@
from style_bert_vits2.nlp.japanese.g2p import g2p
from style_bert_vits2.nlp.japanese.mora_list import (
CONSONANTS,
MORA_KATA_TO_MORA_PHONEMES,
MORA_PHONEMES_TO_MORA_KATA,
)
@@ -33,15 +34,6 @@ def phone_tone2kata_tone(phone_tone: list[tuple[str, int]]) -> list[tuple[str, i
カタカナと音高のリスト。
"""
# 子音の集合
CONSONANTS = set(
[
consonant
for consonant, _ in MORA_KATA_TO_MORA_PHONEMES.values()
if consonant is not None
]
)
phone_tone = phone_tone[1:] # 最初の("_", 0)を無視
phones = [phone for phone, _ in phone_tone]
tones = [tone for _, tone in phone_tone]