From da4ff806554717fb3cc6446b4ece54a4102ec49d Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Thu, 3 Jul 2025 19:32:53 -0400 Subject: [PATCH] feat: improve TTS filename generation with better system prompt - Enhanced system prompt to generate 3-5 word descriptive filenames - Added robust text cleaning to remove quotes, special characters - Limit filename length to 50 chars for filesystem compatibility - Better dash-separated filename format like 'javascript-tutorial.mp3' --- src/tts.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tts.js b/src/tts.js index cd8683a..bc3cf2e 100644 --- a/src/tts.js +++ b/src/tts.js @@ -183,7 +183,7 @@ export async function generateTitleForTTS(text) { messages: [ { role: "system", - content: "Generate a concise title for the following text.", + content: "Generate a concise 3-5 word filename title for the following text. Return only the title words, no quotes, no explanation. Focus on the main topic or key concept. Example: 'Machine Learning Basics' or 'Recipe For Cookies' or 'JavaScript Tutorial'.", }, { role: "user", @@ -203,8 +203,12 @@ export async function generateTitleForTTS(text) { const data = await response.json(); return data.choices[0].message.content .trim() - .replace(/\s+/g, "-") - .toLowerCase(); + .replace(/['"]/g, "") // Remove quotes + .replace(/[^\w\s-]/g, "") // Remove special characters except spaces and hyphens + .replace(/\s+/g, "-") // Replace spaces with hyphens + .replace(/-+/g, "-") // Replace multiple hyphens with single + .toLowerCase() + .substring(0, 50); // Limit length for filesystem compatibility } // Handle TTS from element (for modal usage)