mirror of
https://github.com/k2-fsa/icefall.git
synced 2025-08-13 20:12:24 +00:00
Update prepare_manifest.py
update Update prepare_manifest.py Update prepare_manifest.py
This commit is contained in:
parent
9ed5e92702
commit
49150ff9ab
@ -31,23 +31,26 @@ from icefall.utils import str2bool
|
|||||||
class TextNormalizer:
|
class TextNormalizer:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.en_tn_model = EnNormalizer(cache_dir="/tmp/tn", overwrite_cache=False)
|
self.en_tn_model = EnNormalizer(cache_dir="/tmp/tn", overwrite_cache=False)
|
||||||
self.table = str.maketrans(
|
self.table = str.maketrans("’‘,。;?!():-《》、“”【】", "'',.;?!(): <>/\"\"[]")
|
||||||
"’‘,。;?!():-《》、“”【】", "'',.;?!(): <>/\"\"[]"
|
|
||||||
)
|
|
||||||
|
|
||||||
def __call__(self, cut):
|
def __call__(self, cut):
|
||||||
text = cut["supervisions"][0]["custom"]["texts"][0]
|
text = cut["supervisions"][0]["custom"]["texts"][0]
|
||||||
|
|
||||||
# Process brackets
|
|
||||||
text = re.sub(r"\([^\)]*\d[^\)]*\)", " ", text)
|
|
||||||
text = re.sub(r"\([^\)]*\)", " ", text)
|
|
||||||
|
|
||||||
# Apply mappings
|
# Apply mappings
|
||||||
text = text.translate(self.table)
|
text = text.translate(self.table)
|
||||||
|
|
||||||
|
# Process brackets
|
||||||
|
text = re.sub(r"\([^)]*\)|\{[^}]*\}|\[[^\]]*\]|<[^>]*>", " ", text)
|
||||||
|
|
||||||
|
# Process backslash
|
||||||
|
text = re.sub(r"\\.", "", text)
|
||||||
|
|
||||||
# Remove extra spaces
|
# Remove extra spaces
|
||||||
text = re.sub(r"\s+", " ", text).strip()
|
text = re.sub(r"\s+", " ", text).strip()
|
||||||
|
|
||||||
|
if len(text) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
text = self.en_tn_model.normalize(text)
|
text = self.en_tn_model.normalize(text)
|
||||||
|
|
||||||
cut["supervisions"][0]["text"] = text
|
cut["supervisions"][0]["text"] = text
|
||||||
@ -82,7 +85,8 @@ def main():
|
|||||||
for future in tqdm(futures, desc="Processing"):
|
for future in tqdm(futures, desc="Processing"):
|
||||||
try:
|
try:
|
||||||
result = future.result()
|
result = future.result()
|
||||||
fout.write((json.dumps(result) + "\n").encode())
|
if result is not None:
|
||||||
|
fout.write((json.dumps(result) + "\n").encode())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Caught exception:\n{e}\n")
|
print(f"Caught exception:\n{e}\n")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user