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/audio_player.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/audio_player.go')
| -rw-r--r-- | internal/gui/audio_player.go | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/internal/gui/audio_player.go b/internal/gui/audio_player.go index 8df4461..38494c5 100644 --- a/internal/gui/audio_player.go +++ b/internal/gui/audio_player.go @@ -2,9 +2,11 @@ package gui import ( "fmt" + "os" "os/exec" "path/filepath" "runtime" + "strings" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" @@ -23,9 +25,10 @@ type AudioPlayer struct { stopButton *ttwidget.Button statusLabel *widget.Label - audioFile string - isPlaying bool - playCmd *exec.Cmd + audioFile string + isPlaying bool + playCmd *exec.Cmd + voiceInfo string // Stores voice and speed info } // NewAudioPlayer creates a new audio player widget @@ -71,7 +74,34 @@ func (p *AudioPlayer) SetAudioFile(audioFile string) { if audioFile != "" { p.playButton.Enable() - p.statusLabel.SetText(fmt.Sprintf("Audio: %s", filepath.Base(audioFile))) + + // Try to load voice metadata + wordDir := filepath.Dir(audioFile) + metadataFile := filepath.Join(wordDir, "audio_metadata.txt") + voice := "" + speed := "" + + if data, err := os.ReadFile(metadataFile); err == nil { + lines := strings.Split(string(data), "\n") + for _, line := range lines { + if strings.HasPrefix(line, "voice=") { + voice = strings.TrimPrefix(line, "voice=") + } else if strings.HasPrefix(line, "speed=") { + speed = strings.TrimPrefix(line, "speed=") + } + } + } + + // Store voice info + if voice != "" && speed != "" { + p.voiceInfo = fmt.Sprintf(" (voice: %s, speed: %s)", voice, speed) + } else { + p.voiceInfo = "" + } + + // Format status text with voice and speed info + statusText := fmt.Sprintf("Audio: %s%s", filepath.Base(audioFile), p.voiceInfo) + p.statusLabel.SetText(statusText) } else { p.Clear() } @@ -82,6 +112,7 @@ func (p *AudioPlayer) Clear() { p.onStop() // Stop any playing audio p.audioFile = "" p.isPlaying = false + p.voiceInfo = "" p.playButton.Disable() p.stopButton.Disable() p.statusLabel.SetText("No audio loaded") @@ -108,7 +139,7 @@ func (p *AudioPlayer) onPlay() { p.isPlaying = true p.playButton.SetIcon(theme.MediaPauseIcon()) p.stopButton.Enable() - p.statusLabel.SetText("Playing: " + filepath.Base(p.audioFile)) + p.statusLabel.SetText(fmt.Sprintf("Playing: %s%s", filepath.Base(p.audioFile), p.voiceInfo)) } // onStop handles stop button click @@ -121,7 +152,7 @@ func (p *AudioPlayer) onStop() { p.isPlaying = false p.playButton.SetIcon(theme.MediaPlayIcon()) p.stopButton.Disable() - p.statusLabel.SetText("Stopped: " + filepath.Base(p.audioFile)) + p.statusLabel.SetText(fmt.Sprintf("Stopped: %s%s", filepath.Base(p.audioFile), p.voiceInfo)) } // Play triggers audio playback @@ -174,7 +205,7 @@ func (p *AudioPlayer) startPlayback() error { p.isPlaying = false p.playButton.SetIcon(theme.MediaPlayIcon()) p.stopButton.Disable() - p.statusLabel.SetText("Finished: " + filepath.Base(p.audioFile)) + p.statusLabel.SetText(fmt.Sprintf("Finished: %s%s", filepath.Base(p.audioFile), p.voiceInfo)) }) } }() |
