- services/gateway/api: net/http router with JWT auth, stub login, 6 tests - services/gateway/ws: WebSocket hub with echo support - services/voice: STT/TTS provider chain with fallback, 6 tests - cmd/cyrene/main.go: single binary startup, 108 tests total - Smoke test: health check + login verified on :8080
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package voice
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewServiceDefaultConfig(t *testing.T) {
|
|
svc := New(Config{
|
|
STTProvider: "silent",
|
|
TTSProviders: []string{"silent"},
|
|
})
|
|
|
|
if svc.sttProvider == nil {
|
|
t.Fatal("expected STT provider")
|
|
}
|
|
if svc.sttProvider.Name() != "silent" {
|
|
t.Errorf("expected silent STT, got %s", svc.sttProvider.Name())
|
|
}
|
|
}
|
|
|
|
func TestNewServiceEmptyConfig(t *testing.T) {
|
|
svc := New(Config{})
|
|
|
|
if svc.sttProvider == nil {
|
|
t.Fatal("expected fallback STT provider")
|
|
}
|
|
if len(svc.ttsProviders) == 0 {
|
|
t.Fatal("expected at least one fallback TTS provider")
|
|
}
|
|
}
|
|
|
|
func TestServiceRecognize(t *testing.T) {
|
|
svc := New(Config{})
|
|
|
|
result, err := svc.Recognize(context.Background(), []byte("test audio"))
|
|
if err != nil {
|
|
t.Errorf("Recognize should not error: %v", err)
|
|
}
|
|
if result != "" {
|
|
t.Logf("Recognize result: %s", result)
|
|
}
|
|
}
|
|
|
|
func TestServiceSynthesize(t *testing.T) {
|
|
svc := New(Config{TTSProviders: []string{"silent"}})
|
|
|
|
audio, err := svc.Synthesize(context.Background(), "你好世界", "zh-CN-XiaoxiaoNeural")
|
|
if err != nil {
|
|
t.Fatalf("Synthesize should not error: %v", err)
|
|
}
|
|
if audio == nil {
|
|
t.Error("expected non-nil audio")
|
|
}
|
|
}
|
|
|
|
func TestTTSProviderChain(t *testing.T) {
|
|
svc := New(Config{
|
|
TTSProviders: []string{"edge-tts", "espeak", "silent"},
|
|
})
|
|
|
|
if len(svc.ttsProviders) != 3 {
|
|
t.Errorf("expected 3 TTS providers, got %d", len(svc.ttsProviders))
|
|
}
|
|
|
|
names := []string{"edge-tts", "espeak", "silent"}
|
|
for i, p := range svc.ttsProviders {
|
|
if p.Name() != names[i] {
|
|
t.Errorf("provider[%d]: expected %s, got %s", i, names[i], p.Name())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProviderNames(t *testing.T) {
|
|
if n := (&dashscopeSTT{}).Name(); n != "dashscope" {
|
|
t.Errorf("got %s", n)
|
|
}
|
|
if n := (&silentSTT{}).Name(); n != "silent" {
|
|
t.Errorf("got %s", n)
|
|
}
|
|
if n := (&edgeTTS{}).Name(); n != "edge-tts" {
|
|
t.Errorf("got %s", n)
|
|
}
|
|
if n := (&espeakTTS{}).Name(); n != "espeak" {
|
|
t.Errorf("got %s", n)
|
|
}
|
|
if n := (&silentTTS{}).Name(); n != "silent" {
|
|
t.Errorf("got %s", n)
|
|
}
|
|
}
|