picoclaw/pkg/voice/transcriber.go

44 lines
1.1 KiB
Go
Raw Normal View History

2026-02-04 11:06:13 +00:00
package voice
import (
"context"
"strings"
"github.com/sipeed/picoclaw/pkg/config"
2026-02-04 11:06:13 +00:00
)
2026-03-01 08:31:04 +00:00
type Transcriber interface {
Name() string
2026-03-01 08:31:04 +00:00
Transcribe(ctx context.Context, audioFilePath string) (*TranscriptionResponse, error)
}
2026-02-04 11:06:13 +00:00
type TranscriptionResponse struct {
Text string `json:"text"`
Language string `json:"language,omitempty"`
Duration float64 `json:"duration,omitempty"`
}
// DetectTranscriber inspects cfg and returns the appropriate Transcriber, or
// nil if no supported transcription provider is configured.
func DetectTranscriber(cfg *config.Config) Transcriber {
if modelName := strings.TrimSpace(cfg.Voice.ModelName); modelName != "" {
modelCfg, err := cfg.GetModelConfig(modelName)
if err != nil {
return nil
}
return NewAudioModelTranscriber(modelCfg)
}
// Direct Groq provider config takes priority.
if key := cfg.Providers.Groq.APIKey; key != "" {
return NewGroqTranscriber(key)
}
// Fall back to any model-list entry that uses the groq/ protocol.
for _, mc := range cfg.ModelList {
if strings.HasPrefix(mc.Model, "groq/") && mc.APIKey != "" {
return NewGroqTranscriber(mc.APIKey)
}
}
return nil
}