diff --git a/public/src/tts.js b/public/src/tts.js index 07491df..4a3ddd0 100644 --- a/public/src/tts.js +++ b/public/src/tts.js @@ -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