- Add `AudioModelTranscriber` for model-based audio transcription via LLM providers - Support selecting a transcription model with `voice.model_name` in config - Keep Groq transcription as a fallback and move it into dedicated files with focused tests - Serialize `data:audio/...` media as input_audio for OpenAI-compatible providers - Improve transcription logging by rendering error fields as strings - Add coverage for transcriber detection, audio-model behavior, provider audio serialization, and Groq transcription Fixes #1890.
110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
package voice
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
)
|
|
|
|
func TestDetectTranscriber(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
cfg *config.Config
|
|
wantNil bool
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "no config",
|
|
cfg: &config.Config{},
|
|
wantNil: true,
|
|
},
|
|
{
|
|
name: "groq provider key",
|
|
cfg: &config.Config{
|
|
Providers: config.ProvidersConfig{
|
|
Groq: config.ProviderConfig{APIKey: "sk-groq-direct"},
|
|
},
|
|
},
|
|
wantName: "groq",
|
|
},
|
|
{
|
|
name: "voice model name selects audio model transcriber",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "voice-gemini"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "voice-gemini", Model: "gemini/gemini-2.5-flash", APIKey: "sk-gemini-model"},
|
|
},
|
|
},
|
|
wantName: "audio-model",
|
|
},
|
|
{
|
|
name: "groq via model list",
|
|
cfg: &config.Config{
|
|
ModelList: []config.ModelConfig{
|
|
{Model: "openai/gpt-4o", APIKey: "sk-openai"},
|
|
{Model: "groq/llama-3.3-70b", APIKey: "sk-groq-model"},
|
|
},
|
|
},
|
|
wantName: "groq",
|
|
},
|
|
{
|
|
name: "voice model name selects non-gemini audio model transcriber",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "voice-openai-audio"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "voice-openai-audio", Model: "openai/gpt-4o-audio-preview", APIKey: "sk-openai"},
|
|
},
|
|
},
|
|
wantName: "audio-model",
|
|
},
|
|
{
|
|
name: "groq model list entry without key is skipped",
|
|
cfg: &config.Config{
|
|
ModelList: []config.ModelConfig{
|
|
{Model: "groq/llama-3.3-70b", APIKey: ""},
|
|
},
|
|
},
|
|
wantNil: true,
|
|
},
|
|
{
|
|
name: "provider key takes priority over model list",
|
|
cfg: &config.Config{
|
|
Providers: config.ProvidersConfig{
|
|
Groq: config.ProviderConfig{APIKey: "sk-groq-direct"},
|
|
},
|
|
ModelList: []config.ModelConfig{
|
|
{Model: "groq/llama-3.3-70b", APIKey: "sk-groq-model"},
|
|
},
|
|
},
|
|
wantName: "groq",
|
|
},
|
|
{
|
|
name: "missing voice model name config returns nil",
|
|
cfg: &config.Config{
|
|
Voice: config.VoiceConfig{ModelName: "missing"},
|
|
ModelList: []config.ModelConfig{
|
|
{ModelName: "other", Model: "gemini/gemini-2.5-flash", APIKey: "sk-gemini-model"},
|
|
},
|
|
},
|
|
wantNil: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
tr := DetectTranscriber(tc.cfg)
|
|
if tc.wantNil {
|
|
if tr != nil {
|
|
t.Errorf("DetectTranscriber() = %v, want nil", tr)
|
|
}
|
|
return
|
|
}
|
|
if tr == nil {
|
|
t.Fatal("DetectTranscriber() = nil, want non-nil")
|
|
}
|
|
if got := tr.Name(); got != tc.wantName {
|
|
t.Errorf("Name() = %q, want %q", got, tc.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|