-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (21 loc) · 1014 Bytes
/
utils.py
File metadata and controls
31 lines (21 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import string
from config import Config
def preprocess_text(text, config: Config):
"""
Приводит текст к нижнему регистру и удаляет всю пунктуацию
для корректного сравнения ASR.
Args:
text: Текст для обработки
"""
# Нижний регистр
text_lowered = text.lower()
# Преобразование ё в е
text_lowered = text_lowered.replace('ё', 'е')
# Таблица для удаления всех знаков из string.punctuation
translator = str.maketrans('', '', string.punctuation)
# Удаляем пунктуацию
text_cleaned = text_lowered.translate(translator)
# Опционально: сжимаем несколько пробелов в один
# Это важно, так как jiwer работает со списками слов
text_normalized = " ".join(text_cleaned.split())
return text_normalized