diff options
| author | Paul Buetow <paul@buetow.org> | 2026-01-21 21:48:01 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-01-21 21:48:01 +0200 |
| commit | 3fca6ea6b307d6b6c228030fde7a906db078b9db (patch) | |
| tree | 00f3ea2e717b399516599d20947b369a8a3c7a15 /internal/processor | |
| parent | 8a4b935792c50101cf65b36e44f376c90c2d08c1 (diff) | |
fix: bg-bg cards generating audio in separate directories
- Fix critical bug where generateAudioBgBg() was creating two separate
card directories (one for front audio, one for back audio)
- Root cause: generateAudioWithVoiceAndFilename() calls findOrCreateWordDirectory()
with both the front word AND the back word, creating separate directories
- Solution: Pass wordDir to both audio generation calls
- Create new generateAudioWithVoiceAndFilenameInDir() function
- Refactor generateAudioWithVoiceAndFilename() to use new function
- generateAudioBgBg() now finds directory ONCE and passes it to both calls
This fixes the issue where opening a bg-bg card showed 'no audio loaded'
because audio_front.mp3 and audio_back.mp3 were in different directories.
Diffstat (limited to 'internal/processor')
| -rw-r--r-- | internal/processor/processor.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/internal/processor/processor.go b/internal/processor/processor.go index 0947961..3b49cf0 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -271,15 +271,19 @@ func (p *Processor) generateAudioBgBg(front, back string) error { } fmt.Printf(" Using voice: %s\n", voice) + // Find or create the word directory ONCE (for the front word) + // Both audio files will be saved to this same directory + wordDir := p.findOrCreateWordDirectory(front) + // Generate front audio fmt.Printf(" Generating front audio for '%s'...\n", front) - if err := p.generateAudioWithVoiceAndFilename(front, voice, "audio_front"); err != nil { + if err := p.generateAudioWithVoiceAndFilenameInDir(front, voice, "audio_front", wordDir); err != nil { return fmt.Errorf("failed to generate front audio: %w", err) } // Generate back audio fmt.Printf(" Generating back audio for '%s'...\n", back) - if err := p.generateAudioWithVoiceAndFilename(back, voice, "audio_back"); err != nil { + if err := p.generateAudioWithVoiceAndFilenameInDir(back, voice, "audio_back", wordDir); err != nil { return fmt.Errorf("failed to generate back audio: %w", err) } @@ -293,6 +297,12 @@ func (p *Processor) generateAudioWithVoice(word, voice string) error { // generateAudioWithVoiceAndFilename generates audio for a word with a specific voice and filename func (p *Processor) generateAudioWithVoiceAndFilename(word, voice, filenameBase string) error { + wordDir := p.findOrCreateWordDirectory(word) + return p.generateAudioWithVoiceAndFilenameInDir(word, voice, filenameBase, wordDir) +} + +// generateAudioWithVoiceAndFilenameInDir generates audio for a word and saves it to a specific directory +func (p *Processor) generateAudioWithVoiceAndFilenameInDir(word, voice, filenameBase, wordDir string) error { // Generate random speed between 0.90 and 1.00 if not explicitly set speed := p.flags.OpenAISpeed if p.flags.OpenAISpeed == 0.9 && !viper.IsSet("audio.openai_speed") { @@ -334,9 +344,6 @@ func (p *Processor) generateAudioWithVoiceAndFilename(word, voice, filenameBase // Generate audio file ctx := context.Background() - // Find existing card directory or create new one - wordDir := p.findOrCreateWordDirectory(word) - // Build filename using the provided base var outputFile string if p.flags.AllVoices && filenameBase == "audio" { |
