From 237fc5892842c69b47ccf81cc09a156f4168ade1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 23 Apr 2024 21:02:51 +0200 Subject: [PATCH] [tts.picovoice] A more robust logic for replacing unsupported characteres on the input. --- platypush/plugins/tts/picovoice/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/tts/picovoice/__init__.py b/platypush/plugins/tts/picovoice/__init__.py index 2d2685ea5a..9f7496a822 100644 --- a/platypush/plugins/tts/picovoice/__init__.py +++ b/platypush/plugins/tts/picovoice/__init__.py @@ -25,7 +25,7 @@ class TextConversionUtils: _logger = logging.getLogger(__name__) _number_re = re.compile(r'(([0-9]+\.[0-9]+)|([0-9]+\,[0-9]+)|([0-9]+))') _conversions_map = { - (re.compile(r'[(){}\[\]<>]'), ','), + (re.compile(r'\s*[(){}\[\]<>]'), ', '), (re.compile(r'[;]'), '.'), (re.compile(r'[@#]'), ' at '), (re.compile(r'[$]'), ' dollar '), @@ -39,6 +39,8 @@ class TextConversionUtils: (re.compile(r'[*]'), ' star '), (re.compile(r'[\\/]'), ' slash '), (re.compile(r'[_]'), ' underscore '), + # Anything that isn't a letter or supported punctuation is replaced with a space + (re.compile(r'[^a-zA-Z,.:?!\-\'" ]'), ' '), } @classmethod @@ -50,8 +52,8 @@ class TextConversionUtils: return text while match := cls._number_re.search(text): - number = match.group(1).replace(',', '') - text = text.replace(number, num2words(float(number))) + number = match.group(1) + text = text.replace(number, num2words(float(number.replace(',', '')))) return text