diff options
| author | historia <historiavg@proton.me> | 2026-08-19 05:13:36 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-19 05:13:36 -0400 |
| commit | 94ddbb0634022a6e5209b5221c057228ec3d1418 (patch) | |
| tree | d7892e758cad10336816695166c511f7a9689704 /converter/chunking.py | |
| parent | 9d4d7ef806c17387af9778725cd65a5e7ed10e39 (diff) | |
| download | tts-audiobook-generator-94ddbb0634022a6e5209b5221c057228ec3d1418.tar.gz | |
feat: reuse one seed per run for consistent voice across chunks
Diffstat (limited to 'converter/chunking.py')
| -rw-r--r-- | converter/chunking.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/converter/chunking.py b/converter/chunking.py index 425765f..1ce69a3 100644 --- a/converter/chunking.py +++ b/converter/chunking.py @@ -8,11 +8,19 @@ from . import config logger = logging.getLogger(__name__) +# Hard ceiling on words per request, regardless of the configured chunk +# size. Both TTS servers silently truncate audio when a single generation +# exceeds its cap (~2.5 min for the faster backend's static KV cache, +# ~11 min for the Gradio demo) without reporting any error, so larger +# requests are always split client-side. Keep a margin below ~300 words +# to survive slow narration on the faster backend. +MAX_REQUEST_WORDS = 250 -def split_into_chunks(text: str, max_words: int = config.CHUNK_SIZE_WORDS) -> List[str]: + +def split_into_chunks(text: str, max_words: int = config.CHUNK_SIZE) -> List[str]: """Split text into chunks of at most ``max_words`` words. - ``max_words`` is clamped to ``config.MAX_REQUEST_WORDS``: requests + ``max_words`` is clamped to ``MAX_REQUEST_WORDS``: requests beyond that ceiling are silently truncated by the TTS servers (no error is reported), so chunks larger than the ceiling are never produced regardless of configuration. @@ -25,13 +33,13 @@ def split_into_chunks(text: str, max_words: int = config.CHUNK_SIZE_WORDS) -> Li at word boundaries as a last resort: individual tokens stay intact, but whitespace between them is normalized. """ - if max_words > config.MAX_REQUEST_WORDS: + if max_words > MAX_REQUEST_WORDS: logger.warning( "Requested chunk size of %d words exceeds the %d-word request ceiling; " "larger requests are silently truncated by the TTS servers, so the " - "size is clamped to %d words (see MAX_REQUEST_WORDS in converter/config.py)", - max_words, config.MAX_REQUEST_WORDS, config.MAX_REQUEST_WORDS) - max_words = config.MAX_REQUEST_WORDS + "size is clamped to %d words (see MAX_REQUEST_WORDS in converter/chunking.py)", + max_words, MAX_REQUEST_WORDS, MAX_REQUEST_WORDS) + max_words = MAX_REQUEST_WORDS if max_words < 1: max_words = 1 |
