From f6fa6f606b9814a40347cf5d4062810ff9b53a38 Mon Sep 17 00:00:00 2001 From: rany Date: Sun, 5 Dec 2021 10:05:15 +0200 Subject: [PATCH] Remove characters the service does not support --- src/edgeTTS/communicate.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/edgeTTS/communicate.py b/src/edgeTTS/communicate.py index 8cf58c2..1021553 100644 --- a/src/edgeTTS/communicate.py +++ b/src/edgeTTS/communicate.py @@ -45,12 +45,15 @@ def remove_incompatible_characters(string): result in an error from the service. Args: - string (byte): The string to be cleaned. + string (str or bytes): The string to be cleaned. Returns: - byte: The cleaned string. + str: The cleaned string. """ - cleaned_string = b"" + if isinstance(string, bytes): + string = string.decode("utf-8") + + cleaned_string = "" for character in string: character_code = ord(character) if ( @@ -244,7 +247,8 @@ class Communicate: + 50 ) # margin of error messages = split_text_by_byte_length( - escape(messages), websocket_max_size - overhead_per_message + escape(remove_incompatible_characters(messages)), + websocket_max_size - overhead_per_message, ) else: if isinstance(messages, str):