diff options
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 +} |
