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)