Files
hyprvoice/internal/transcriber/transcriber.go
T
Ben Nasedkin 025ff7fc55 feat: add Groq Whisper API support for transcription and translation
Add support for Groq Whisper API as an alternative to OpenAI:
- groq-transcription: Fast transcription using whisper-large-v3 or whisper-large-v3-turbo
- groq-translation: Translation to English (whisper-large-v3 only)

Features:
- New transcription adapters for both Groq services
- Config validation with provider-specific model restrictions
- API key support via config file or GROQ_API_KEY environment variable
- Updated interactive configuration wizard with provider selection
- Comprehensive test coverage for all providers
- Shared WAV conversion utility for audio preprocessing

Breaking changes: None
Backward compatibility: Existing OpenAI configurations continue to work unchanged
2025-10-18 19:19:03 +03:00

63 lines
1.5 KiB
Go

package transcriber
import (
"context"
"fmt"
"github.com/leonardotrapani/hyprvoice/internal/recording"
)
// Main transcriber interface
type Transcriber interface {
Start(ctx context.Context, frameCh <-chan recording.AudioFrame) (<-chan error, error)
Stop(ctx context.Context) error
GetFinalTranscription() (string, error)
}
// Adapter interface for different transcription backends
type TranscriptionAdapter interface {
Transcribe(ctx context.Context, audioData []byte) (string, error)
}
// Configuration for the transcriber
type Config struct {
Provider string
APIKey string
Language string
Model string
}
// NewTranscriber creates a new simple transcriber
func NewTranscriber(config Config) (Transcriber, error) {
// Create the appropriate adapter
var adapter TranscriptionAdapter
switch config.Provider {
case "openai":
if config.APIKey == "" {
return nil, fmt.Errorf("OpenAI API key required")
}
adapter = NewOpenAIAdapter(config)
case "groq-transcription":
if config.APIKey == "" {
return nil, fmt.Errorf("Groq API key required")
}
adapter = NewGroqTranscriptionAdapter(config)
case "groq-translation":
if config.APIKey == "" {
return nil, fmt.Errorf("Groq API key required")
}
adapter = NewGroqTranslationAdapter(config)
default:
return nil, fmt.Errorf("unsupported provider: %s", config.Provider)
}
// Create simple transcriber that collects all audio
transcriber := NewSimpleTranscriber(config, adapter)
return transcriber, nil
}