diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-19 23:35:44 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-19 23:35:44 +0300 |
| commit | 6038d6e29d4878cccb46bf35bb9885ec7d376422 (patch) | |
| tree | f7861a731ba20db54e4ca578d6cd586ad8a87ab0 /internal/audio/provider.go | |
| parent | 3a6c690230f769ad33bc26e2fc5d5662e38fe3d6 (diff) | |
feat: improve flashcard storage and audio regenerationv0.6.0
- Change default card storage from ~/Downloads to ~/.local/state/totalrecall/cards/
- Keep .apkg exports in ~/Downloads for user convenience
- Fix audio regeneration to use random voice and speed (0.9-1.0)
- Fix GNOME dock icon by updating StartupWMClass to "Totalrecall"
- Fix navigation to properly find cards in new XDG state directory
- Ensure config defaults are properly filled when using GUI mode
- Bump version to 0.6.0
π€ Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/audio/provider.go')
| -rw-r--r-- | internal/audio/provider.go | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/internal/audio/provider.go b/internal/audio/provider.go index 53b08c1..0142fb3 100644 --- a/internal/audio/provider.go +++ b/internal/audio/provider.go @@ -9,10 +9,10 @@ import ( type Provider interface { // GenerateAudio generates audio from text and saves it to the specified file GenerateAudio(ctx context.Context, text string, outputFile string) error - + // Name returns the provider name Name() string - + // IsAvailable checks if the provider is properly configured and available IsAvailable() error } @@ -22,14 +22,14 @@ type Config struct { Provider string // Provider name: "openai" OutputDir string // Directory for output files OutputFormat string // Output format: "mp3" or "wav" - + // OpenAI-specific settings OpenAIKey string OpenAIModel string // "tts-1", "tts-1-hd", or "gpt-4o-mini-tts" OpenAIVoice string // "alloy", "ash", "ballad", "coral", "echo", "fable", "onyx", "nova", "sage", "shimmer", "verse" OpenAISpeed float64 // 0.25 to 4.0 OpenAIInstruction string // Voice instructions for gpt-4o-mini-tts model - + // Caching settings EnableCache bool CacheDir string @@ -38,15 +38,16 @@ type Config struct { // DefaultConfig returns default configuration func DefaultProviderConfig() *Config { return &Config{ - Provider: "openai", - OutputDir: "./", - OutputFormat: "mp3", - OpenAIModel: "gpt-4o-mini-tts", // New model with voice instructions support - OpenAIVoice: "alloy", - OpenAISpeed: 0.98, // Default speed for clarity + Provider: "openai", + OutputDir: "./", + OutputFormat: "mp3", + OpenAIModel: "gpt-4o-mini-tts", // New model with voice instructions support + OpenAIVoice: "alloy", + OpenAISpeed: 1.0, + // OpenAISpeed: 0.98, // Default speed for clarity OpenAIInstruction: "You are speaking Bulgarian language (Π±ΡΠ»Π³Π°ΡΡΠΊΠΈ Π΅Π·ΠΈΠΊ). Pronounce the Bulgarian text with authentic Bulgarian phonetics, not Russian. Speak slowly and clearly for language learners.", - EnableCache: true, - CacheDir: "./.audio_cache", + EnableCache: true, + CacheDir: "./.audio_cache", } } @@ -55,14 +56,14 @@ func NewProvider(config *Config) (Provider, error) { if config == nil { config = DefaultProviderConfig() } - + switch config.Provider { case "openai": if config.OpenAIKey == "" { return nil, fmt.Errorf("OpenAI API key is required") } return NewOpenAIProvider(config) - + default: return nil, fmt.Errorf("unknown audio provider: %s", config.Provider) } @@ -70,8 +71,8 @@ func NewProvider(config *Config) (Provider, error) { // ProviderWithFallback wraps a primary provider with a fallback option type ProviderWithFallback struct { - primary Provider - fallback Provider + primary Provider + fallback Provider } // NewProviderWithFallback creates a provider that falls back to secondary if primary fails @@ -87,9 +88,9 @@ func (p *ProviderWithFallback) GenerateAudio(ctx context.Context, text string, o err := p.primary.GenerateAudio(ctx, text, outputFile) if err != nil { // Log the primary error - fmt.Printf("Primary provider (%s) failed: %v. Falling back to %s\n", + fmt.Printf("Primary provider (%s) failed: %v. Falling back to %s\n", p.primary.Name(), err, p.fallback.Name()) - + // Try fallback return p.fallback.GenerateAudio(ctx, text, outputFile) } @@ -107,12 +108,12 @@ func (p *ProviderWithFallback) IsAvailable() error { if primaryErr == nil { return nil } - + fallbackErr := p.fallback.IsAvailable() if fallbackErr == nil { return nil } - - return fmt.Errorf("both providers unavailable: primary=%v, fallback=%v", + + return fmt.Errorf("both providers unavailable: primary=%v, fallback=%v", primaryErr, fallbackErr) -}
\ No newline at end of file +} |
