31 lines
691 B
Python
31 lines
691 B
Python
"""
|
||
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()]
|