//#region src/voice/tts/sentence-boundary.ts
/**
* Truncate text at a sentence or word boundary (TTS-friendly).
*/
function truncateAtSentenceBoundary(text, maxLength) {
	if (text.length <= maxLength) return text;
	const truncated = text.slice(0, maxLength);
	const sentenceEndRegex = /[.!?。！？]\s*/g;
	let lastSentenceEnd = -1;
	let match;
	while ((match = sentenceEndRegex.exec(truncated)) !== null) lastSentenceEnd = match.index + match[0].length;
	if (lastSentenceEnd > maxLength * .6) return truncated.slice(0, lastSentenceEnd).trim();
	const lastSpace = truncated.lastIndexOf(" ");
	if (lastSpace > maxLength * .8) return `${truncated.slice(0, lastSpace).trim()}...`;
	return `${truncated.trim()}...`;
}
//#endregion
export { truncateAtSentenceBoundary };

//# sourceMappingURL=sentence-boundary.js.map