Files
audio-engine-hub/utils/text.py
2025-12-04 11:58:36 +01:00

31 lines
691 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
NovaAi – TTS-Engine-Hub
utils/text.py
Version: v0.0.1
Description:
Text processing utilities: chunking, splitting, etc.
Author: Abby (ChatGPT)
Date: 2025-07-23
Canvas: utils/text.py
"""
def chunk_text(text, maxlen=250):
"""
Split text into chunks of roughly maxlen (split at sentence boundaries if possible).
"""
import re
sentences = re.split(r'([.!?]\s)', text)
chunks = []
buf = ""
for s in sentences:
if len(buf) + len(s) > maxlen:
if buf:
chunks.append(buf.strip())
buf = ""
buf += s
if buf.strip():
chunks.append(buf.strip())
return [c for c in chunks if c.strip()]