Skip to content

Commit

Permalink
Fallback to cn2an for window users
Browse files Browse the repository at this point in the history
Signed-off-by: Lengyue <[email protected]>
  • Loading branch information
leng-yue committed Jan 4, 2024
1 parent 5eeca88 commit c8accc7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions fish_speech/text/chinese.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
import re

import jieba.posseg as psg
from loguru import logger
from pypinyin import Style, lazy_pinyin
from tn.chinese.normalizer import Normalizer

from fish_speech.text.symbols import punctuation
from fish_speech.text.tone_sandhi import ToneSandhi

try:
from tn.chinese.normalizer import Normalizer

normalizer = Normalizer().normalize
except ImportError:
import cn2an

logger.warning("tn.chinese.normalizer not found, use cn2an normalizer")
normalizer = lambda x: cn2an.transform(x, "an2cn")

current_file_path = os.path.dirname(__file__)
OPENCPOP_DICT_PATH = os.path.join(current_file_path, "opencpop-strict.txt")

Expand All @@ -16,7 +26,6 @@
for line in open(OPENCPOP_DICT_PATH).readlines()
}

normalizer = Normalizer()
tone_modifier = ToneSandhi()


Expand Down Expand Up @@ -123,7 +132,7 @@ def _g2p(segments):


def text_normalize(text):
return normalizer.normalize(text)
return normalizer(text)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ dependencies = [
"loguru>=0.6.0",
"WeTextProcessing>=0.1.10",
"loralib>=0.1.2",
"natsort>=8.4.0"
"natsort>=8.4.0",
"cn2an>=0.5.22"
]

[project.optional-dependencies]
Expand Down

0 comments on commit c8accc7

Please sign in to comment.