mirror of
https://github.com/HumanAIGC/lite-avatar.git
synced 2026-02-05 18:09:20 +08:00
add files
This commit is contained in:
49
funasr_local/text/cleaner.py
Normal file
49
funasr_local/text/cleaner.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from typing import Collection
|
||||
|
||||
from jaconv import jaconv
|
||||
|
||||
from typeguard import check_argument_types
|
||||
|
||||
try:
|
||||
from vietnamese_cleaner import vietnamese_cleaners
|
||||
except ImportError:
|
||||
vietnamese_cleaners = None
|
||||
|
||||
|
||||
class TextCleaner:
|
||||
"""Text cleaner.
|
||||
|
||||
Examples:
|
||||
>>> cleaner = TextCleaner("tacotron")
|
||||
>>> cleaner("(Hello-World); & jr. & dr.")
|
||||
'HELLO WORLD, AND JUNIOR AND DOCTOR'
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, cleaner_types: Collection[str] = None):
|
||||
assert check_argument_types()
|
||||
|
||||
if cleaner_types is None:
|
||||
self.cleaner_types = []
|
||||
elif isinstance(cleaner_types, str):
|
||||
self.cleaner_types = [cleaner_types]
|
||||
else:
|
||||
self.cleaner_types = list(cleaner_types)
|
||||
|
||||
def __call__(self, text: str) -> str:
|
||||
for t in self.cleaner_types:
|
||||
if t == "tacotron":
|
||||
import tacotron_cleaner.cleaners
|
||||
text = tacotron_cleaner.cleaners.custom_english_cleaners(text)
|
||||
elif t == "jaconv":
|
||||
text = jaconv.normalize(text)
|
||||
elif t == "vietnamese":
|
||||
if vietnamese_cleaners is None:
|
||||
raise RuntimeError("Please install underthesea")
|
||||
text = vietnamese_cleaners.vietnamese_cleaner(text)
|
||||
elif t == "korean_cleaner":
|
||||
text = KoreanCleaner.normalize_text(text)
|
||||
else:
|
||||
raise RuntimeError(f"Not supported: type={t}")
|
||||
|
||||
return text
|
||||
Reference in New Issue
Block a user