diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-18 23:18:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-18 23:18:45 +0300 |
| commit | 8779de2c97e445acf82e8422c899fdefa4649bda (patch) | |
| tree | b24d270a4e655c66059034cfdf0713e3bf3d32f5 /internal/gui/generator.go | |
| parent | f3c1b568ac28e211d218f0b33ccb85cf782ce248 (diff) | |
feat: multiple improvements to GUI and codebase
- Add random voice speed between 0.90-1.00 for more natural audio
- Display voice and speed info in GUI audio player
- Implement automatic retry loading for missing files (checks every 2 seconds)
- Fix voice/speed info persistence during audio playback
- Remove image caching functionality for cleaner codebase
- Rename prompt.txt to image_prompt.txt for clarity
- Fix GUI to recognize newly added cards during runtime (rescan on navigation)
- Update README to reflect removed image cache
These changes improve the user experience by making the audio more natural,
providing better feedback about audio generation parameters, and ensuring
the GUI stays synchronized with externally added cards.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/gui/generator.go')
| -rw-r--r-- | internal/gui/generator.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/internal/gui/generator.go b/internal/gui/generator.go index ca9d854..92ead40 100644 --- a/internal/gui/generator.go +++ b/internal/gui/generator.go @@ -91,8 +91,12 @@ func (a *Application) generateAudio(word string) (string, error) { rand.Seed(time.Now().UnixNano()) voice := allVoices[rand.Intn(len(allVoices))] - // Update audio config with random voice + // Generate random speed between 0.90 and 1.00 + speed := 0.90 + rand.Float64()*0.10 + + // Update audio config with random voice and speed a.audioConfig.OpenAIVoice = voice + a.audioConfig.OpenAISpeed = speed // Create audio provider provider, err := audio.NewProvider(a.audioConfig) @@ -127,11 +131,18 @@ func (a *Application) generateAudio(word string) (string, error) { } // Save audio attribution - if err := a.saveAudioAttribution(word, outputFile, voice); err != nil { + if err := a.saveAudioAttribution(word, outputFile, voice, speed); err != nil { // Non-fatal error, just log it fmt.Printf("Warning: Failed to save audio attribution: %v\n", err) } + // Save voice metadata for GUI display + metadataFile := filepath.Join(wordDir, "audio_metadata.txt") + metadata := fmt.Sprintf("voice=%s\nspeed=%.2f\n", voice, speed) + if err := os.WriteFile(metadataFile, []byte(metadata), 0644); err != nil { + fmt.Printf("Warning: Failed to save audio metadata: %v\n", err) + } + return outputFile, nil } @@ -154,8 +165,6 @@ func (a *Application) generateImagesWithPrompt(word string, customPrompt string, Size: "512x512", // Half of 1024x1024 Quality: "standard", Style: "natural", - CacheDir: "./.image_cache", - EnableCache: a.config.EnableCache, } searcher = image.NewOpenAIClient(openaiConfig) @@ -216,7 +225,7 @@ func (a *Application) generateImagesWithPrompt(word string, customPrompt string, usedPrompt := openaiClient.GetLastPrompt() if usedPrompt != "" { // Save the prompt to disk immediately for this word - promptFile := filepath.Join(wordDir, "prompt.txt") + promptFile := filepath.Join(wordDir, "image_prompt.txt") os.WriteFile(promptFile, []byte(usedPrompt), 0644) // Only update UI if this word is still the current word @@ -237,12 +246,12 @@ func (a *Application) generateImagesWithPrompt(word string, customPrompt string, } // saveAudioAttribution saves attribution info for generated audio -func (a *Application) saveAudioAttribution(word, audioFile, voice string) error { +func (a *Application) saveAudioAttribution(word, audioFile, voice string, speed float64) error { attribution := fmt.Sprintf("Audio generated by OpenAI TTS\n\n") attribution += fmt.Sprintf("Bulgarian word: %s\n", word) attribution += fmt.Sprintf("Model: %s\n", a.audioConfig.OpenAIModel) attribution += fmt.Sprintf("Voice: %s\n", voice) - attribution += fmt.Sprintf("Speed: %.2f\n", a.audioConfig.OpenAISpeed) + attribution += fmt.Sprintf("Speed: %.2f\n", speed) if a.audioConfig.OpenAIInstruction != "" { attribution += fmt.Sprintf("\nVoice instructions:\n%s\n", a.audioConfig.OpenAIInstruction) |
