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'
This commit is contained in:
parent
76bd27bea8
commit
da4ff80655
1 changed files with 7 additions and 3 deletions
10
src/tts.js
10
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue