fix TTS cutoff: lower chunk limit to 1500 chars, fix code block regex for backtick content

This commit is contained in:
russell@unturf.com 2026-02-24 18:15:07 -05:00
parent 8845d22ce9
commit b7ac2cbf3a

View file

@ -82,7 +82,7 @@ const ttsCache = new Map();
// Split long text into chunks at sentence boundaries for TTS API limits
// OpenAI-compatible TTS endpoints typically cap at ~4096 characters
const TTS_CHUNK_MAX = 3800; // leave headroom under 4096
const TTS_CHUNK_MAX = 1500; // conservative limit for TTS server compatibility
function splitTextIntoChunks(text) {
if (text.length <= TTS_CHUNK_MAX) return [text];
@ -122,7 +122,7 @@ function splitTextIntoChunks(text) {
remaining = remaining.substring(splitAt).trim();
}
console.log(`TTS: split ${text.length} chars into ${chunks.length} chunks`);
console.log(`TTS: split ${text.length} chars into ${chunks.length} chunks:`, chunks.map((c, i) => `chunk${i + 1}=${c.length}chars`));
return chunks;
}
@ -136,8 +136,8 @@ function cleanTextForTTS(text) {
.replace(/_([^_]+)_/g, '$1') // Italic alt
.replace(/#+\s/g, '') // Headers
.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1') // Links
.replace(/```[\s\S]*?```/g, '') // Code blocks (lazy match handles backticks in code)
.replace(/`([^`]+)`/g, '$1') // Inline code
.replace(/```[^`]*```/g, '') // Code blocks
// Remove HTML tags
.replace(/<[^>]+>/g, '')
// Remove excess whitespace