Limit text size to 4096 bytes (#394)

Fix https://github.com/rany2/edge-tts/issues/390

Signed-off-by: rany <rany2@riseup.net>
This commit is contained in:
rany2
2025-08-05 14:01:32 +03:00
committed by GitHub
parent 36d3006df5
commit 827d55e471
2 changed files with 2 additions and 22 deletions

View File

@@ -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): class CommunicateRequest(TypedDict):
""" """
A class to communicate with the service. A class to communicate with the service.
@@ -379,7 +359,7 @@ class Communicate:
# Split the text into multiple strings and store them. # Split the text into multiple strings and store them.
self.texts = split_text_by_byte_length( self.texts = split_text_by_byte_length(
escape(remove_incompatible_characters(text)), escape(remove_incompatible_characters(text)),
calc_max_mesg_size(self.tts_config), 4096,
) )
# Validate the proxy parameter. # Validate the proxy parameter.

View File

@@ -1,6 +1,6 @@
"""A tiny library for composing SRT files. """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 functionality and Python 2 support removed. This is because of
https://github.com/rany2/edge-tts/issues/383. https://github.com/rany2/edge-tts/issues/383.