diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-18 23:41:22 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-18 23:41:22 +0300 |
| commit | d8c65cd0511b558fe62aac7022c267f51d76f3f9 (patch) | |
| tree | 4c490184ca6a1272f27a216d2e29cd9d666f48b7 /cmd | |
| parent | 8779de2c97e445acf82e8422c899fdefa4649bda (diff) | |
chore: bump version to 0.4.2
- Fix Fyne tooltip layer error by deferring tooltip setup after layer creation
- Add phonetic information generation to batch mode processing
- Fix GUI not displaying phonetic info for batch-generated cards
- Add debug logging for phonetic file loading
- Fix checkForMissingFiles to handle placeholder text in phonetic display
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/totalrecall/main.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/cmd/totalrecall/main.go b/cmd/totalrecall/main.go index db1a94e..7fffbaf 100644 --- a/cmd/totalrecall/main.go +++ b/cmd/totalrecall/main.go @@ -299,6 +299,13 @@ func processWordWithTranslation(word, providedTranslation string) error { } } + // Fetch phonetic information + fmt.Printf(" Fetching phonetic information...\n") + if err := fetchAndSavePhoneticInfo(word); err != nil { + // Don't fail the whole process if phonetic info fails + fmt.Printf(" Warning: Failed to fetch phonetic info: %v\n", err) + } + return nil } @@ -848,6 +855,72 @@ func saveAudioAttribution(word, audioFile string, config *audio.Config) error { return nil } +func fetchAndSavePhoneticInfo(word string) error { + // Check if OpenAI key is available + apiKey := getOpenAIKey() + if apiKey == "" { + return fmt.Errorf("OpenAI API key not configured") + } + + client := openai.NewClient(apiKey) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + req := openai.ChatCompletionRequest{ + Model: openai.GPT4o, + Messages: []openai.ChatCompletionMessage{ + { + Role: openai.ChatMessageRoleSystem, + Content: "You are a Bulgarian language expert helping language learners understand pronunciation. Provide detailed phonetic information using the International Phonetic Alphabet (IPA). For each IPA symbol used, give concrete examples of how it sounds using familiar English words or sounds when possible.", + }, + { + Role: openai.ChatMessageRoleUser, + Content: fmt.Sprintf(`For the Bulgarian word '%s': +1. Provide the complete IPA transcription +2. Break down EACH phonetic symbol used in the transcription +3. For EVERY symbol, explain how it's pronounced with examples: + - If similar to an English sound, give English word examples + - If not in English, describe tongue/mouth position or compare to similar sounds + - Include stress marks and explain which syllable is stressed + +Example format: +Word: [IPA transcription] +• /p/ - like 'p' in English 'pot' +• /a/ - like 'a' in 'father' +• /ˈ/ - stress mark (following syllable is stressed)`, word), + }, + }, + Temperature: 0.3, + MaxTokens: 500, + } + + resp, err := client.CreateChatCompletion(ctx, req) + if err != nil { + return fmt.Errorf("OpenAI API error: %w", err) + } + + if len(resp.Choices) == 0 || resp.Choices[0].Message.Content == "" { + return fmt.Errorf("no response from OpenAI") + } + + phoneticInfo := strings.TrimSpace(resp.Choices[0].Message.Content) + + // Find the card directory for this word + wordDir := findCardDirectory(word) + if wordDir == "" { + return fmt.Errorf("card directory not found for word: %s", word) + } + + // Save phonetic info to file + phoneticFile := filepath.Join(wordDir, "phonetic.txt") + if err := os.WriteFile(phoneticFile, []byte(phoneticInfo), 0644); err != nil { + return fmt.Errorf("failed to write phonetic file: %w", err) + } + + fmt.Printf(" Saved phonetic information\n") + return nil +} + func runGUIMode() error { // Create GUI configuration from command line flags and viper config guiConfig := &gui.Config{ |
