- OpenAIAdapter now accepts EndpointConfig for custom endpoints - added language code conversion via ToProviderFormat - backward-compatible NewOpenAIAdapterFromConfig for migration - works with OpenAI, Groq, and Mistral endpoints
76 lines
1.8 KiB
Go
76 lines
1.8 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)
|
|
}
|
|
|
|
// BatchAdapter interface for batch transcription backends (collect all audio, transcribe at end)
|
|
type BatchAdapter interface {
|
|
Transcribe(ctx context.Context, audioData []byte) (string, error)
|
|
}
|
|
|
|
// Configuration for the transcriber
|
|
type Config struct {
|
|
Provider string
|
|
APIKey string
|
|
Language string
|
|
Model string
|
|
Keywords []string
|
|
}
|
|
|
|
// NewTranscriber creates a new simple transcriber
|
|
func NewTranscriber(config Config) (Transcriber, error) {
|
|
// Create the appropriate adapter
|
|
var adapter BatchAdapter
|
|
|
|
switch config.Provider {
|
|
case "openai":
|
|
if config.APIKey == "" {
|
|
return nil, fmt.Errorf("OpenAI API key required")
|
|
}
|
|
adapter = NewOpenAIAdapterFromConfig(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)
|
|
|
|
case "mistral-transcription":
|
|
if config.APIKey == "" {
|
|
return nil, fmt.Errorf("Mistral API key required")
|
|
}
|
|
adapter = NewMistralAdapter(config)
|
|
|
|
case "elevenlabs":
|
|
if config.APIKey == "" {
|
|
return nil, fmt.Errorf("ElevenLabs API key required")
|
|
}
|
|
adapter = NewElevenLabsAdapter(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
|
|
}
|