1
0
mirror of https://github.com/janvarev/Irene-Voice-Assistant.git synced 2025-12-02 22:58:35 +02:00
Files
Irene-Voice-Assistant/utils/all_num_to_text.py
janvarev 213a6e8736 v5.1 - сделана функция core.all_num_to_text(text), позволяющая конвертировать все числа в тексте для произношения. Очень нужна для работы TTS silero. Опирается на написанную utils/all_num_to_text.
plugin_tts_silero_v3.py - обработка текста - конвертация чисел в строку. Параметры расстановки акцента и "ё" вынесены в опции
прикручена библиотека mycroftAI/lingua-franca для конвертации чисел в строку.
core.py - инициализация библиотеки lingua-franca
2022-04-18 12:55:33 +03:00

39 lines
1.3 KiB
Python

# MIT License
# Janvarev Vladislav
#
# library for translate all digits in text to pronounce
import re
#from utils.num_to_text_ru import num2text
from lingua_franca.format import pronounce_number
def load_language(lang:str):
import lingua_franca
lingua_franca.load_language(lang)
def convert_one_num_float(match_obj):
if match_obj.group() is not None:
text = str(match_obj.group())
return pronounce_number(float(match_obj.group()))
def convert_diapazon(match_obj):
if match_obj.group() is not None:
text = str(match_obj.group())
text = text.replace("-"," тире ")
return all_num_to_text(text)
def all_num_to_text(text:str) -> str:
text = re.sub(r'[\d]*[.][\d]+-[\d]*[.][\d]+', convert_diapazon, text)
text = re.sub(r'-[\d]*[.][\d]+', convert_one_num_float, text)
text = re.sub(r'[\d]*[.][\d]+', convert_one_num_float, text)
text = re.sub(r'[\d]-[\d]+', convert_diapazon, text)
text = re.sub(r'-[\d]+', convert_one_num_float, text)
text = re.sub(r'[\d]+', convert_one_num_float, text)
text = text.replace("%", " процентов")
return text
if __name__ == "__main__":
load_language("ru")
print(all_num_to_text("Ба ва 120.1-120.8, Да -30.1, Ка 44.05, Га 225. Рынок -10%. Тест"))