first commit
This commit is contained in:
30
utils/text.py
Normal file
30
utils/text.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""
|
||||
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()]
|
||||
Reference in New Issue
Block a user