From 827d55e471f7c118e52f954df3759d925d7482f9 Mon Sep 17 00:00:00 2001 From: rany2 Date: Tue, 5 Aug 2025 14:01:32 +0300 Subject: [PATCH] Limit text size to 4096 bytes (#394) Fix https://github.com/rany2/edge-tts/issues/390 Signed-off-by: rany --- src/edge_tts/communicate.py | 22 +--------------------- src/edge_tts/srt_composer.py | 2 +- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/edge_tts/communicate.py b/src/edge_tts/communicate.py index 8a8a9fe..52ea351 100644 --- a/src/edge_tts/communicate.py +++ b/src/edge_tts/communicate.py @@ -311,26 +311,6 @@ def ssml_headers_plus_data(request_id: str, timestamp: str, ssml: str) -> str: ) -def calc_max_mesg_size(tts_config: TTSConfig) -> int: - """Calculates the maximum message size for the given voice, rate, and volume. - - Returns: - int: The maximum message size. - """ - websocket_max_size: int = 2**16 - overhead_per_message: int = ( - len( - ssml_headers_plus_data( - connect_id(), - date_to_string(), - mkssml(tts_config, ""), - ) - ) - + 50 # margin of error - ) - return websocket_max_size - overhead_per_message - - class CommunicateRequest(TypedDict): """ A class to communicate with the service. @@ -379,7 +359,7 @@ class Communicate: # Split the text into multiple strings and store them. self.texts = split_text_by_byte_length( escape(remove_incompatible_characters(text)), - calc_max_mesg_size(self.tts_config), + 4096, ) # Validate the proxy parameter. diff --git a/src/edge_tts/srt_composer.py b/src/edge_tts/srt_composer.py index 187f112..c996f7d 100644 --- a/src/edge_tts/srt_composer.py +++ b/src/edge_tts/srt_composer.py @@ -1,6 +1,6 @@ """A tiny library for composing SRT files. -Based on https://github.com/cdown/srt with parsing, subtitle modifying, +Based on https://github.com/cdown/srt with parsing, subtitle modifying functionality and Python 2 support removed. This is because of https://github.com/rany2/edge-tts/issues/383.