From 15f376c8aa3c170d1a505bec49bab60471bf148d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 19 Jul 2025 22:53:22 +0300 Subject: fix: always use random voice selection for audio generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, random voice was only used for regeneration. Now all audio generation uses a random voice from the available OpenAI voices for more variety in pronunciation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/gui/generator.go | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'internal/gui') diff --git a/internal/gui/generator.go b/internal/gui/generator.go index f7bed2f..7704fb3 100644 --- a/internal/gui/generator.go +++ b/internal/gui/generator.go @@ -85,36 +85,15 @@ func (a *Application) translateEnglishToBulgarian(word string) (string, error) { // generateAudio generates audio for a word func (a *Application) generateAudio(ctx context.Context, word string) (string, error) { - // Check if this is a regeneration by looking for existing audio file - wordDir := a.findCardDirectory(word) - isRegeneration := false - if wordDir != "" { - audioFile := filepath.Join(wordDir, fmt.Sprintf("audio.%s", a.config.AudioFormat)) - if _, err := os.Stat(audioFile); err == nil { - isRegeneration = true - } - } + // Always use random voice and speed for variety + allVoices := []string{"alloy", "ash", "ballad", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer", "verse"} - // For regeneration, use random voice and speed; otherwise use defaults - var voice string - var speed float64 - - if isRegeneration { - // Get available voices - allVoices := []string{"alloy", "ash", "ballad", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer", "verse"} - - // Select a random voice - rand.Seed(time.Now().UnixNano()) - voice = allVoices[rand.Intn(len(allVoices))] - - // Generate random speed between 0.90 and 1.00 - speed = 0.90 + rand.Float64()*0.10 - } else { - // Use defaults for first generation - voice = "alloy" - speed = 1.0 - // speed = 0.98 - } + // Select a random voice + rand.Seed(time.Now().UnixNano()) + voice := allVoices[rand.Intn(len(allVoices))] + + // Generate random speed between 0.90 and 1.00 + speed := 0.90 + rand.Float64()*0.10 // Update audio config with selected voice and speed a.audioConfig.OpenAIVoice = voice @@ -127,7 +106,7 @@ func (a *Application) generateAudio(ctx context.Context, word string) (string, e } // Find existing card directory or create new one again after provider creation - wordDir = a.findCardDirectory(word) + wordDir := a.findCardDirectory(word) if wordDir == "" { // No existing directory, create new one with card ID cardID := internal.GenerateCardID(word) -- cgit v1.2.3