feat(voice): 语音silent降级信号(C2) — provider仅在结果为空时出现
- voice/Chain+Service: STTWithProvider/TTSWithProvider(真实档位cloud/local/edge-tts/espeak/silent), 旧方法改薄包装
- gateway: transcribe空文本带{text,provider} / voice_output空音频带provider / speech空音频tts_empty+X-Voice-Provider头
- middleware: CORS Access-Control-Expose-Headers: X-Voice-Provider
- 可选接口 voiceProviderReporter(type断言透传), 自定义实现回退silent
- 新增测试10个(provider_signal/voice_signal), build/vet/test全绿+交叉编译
- Docs/api-client v0.23 + api-reference CORS 同步
This commit is contained in:
1 parent
00f784b55f
commit
99f222761e
9 files changed
+345
-25
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package voice
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChain_STTWithProvider(t *testing.T) {
|
||||
t.Parallel()
|
||||
steps := []Provider{
|
||||
&stubProvider{name: "cloud", stt: &stubSTT{err: ErrNotConfigured}},
|
||||
&stubProvider{name: "local", stt: &stubSTT{text: "hi"}},
|
||||
}
|
||||
text, rung, err := NewChain(steps...).STTWithProvider(context.Background(), Audio{Format: "wav", Data: []byte("x")})
|
||||
if err != nil {
|
||||
t.Fatalf("STTWithProvider error: %v", err)
|
||||
}
|
||||
if text != "hi" || rung != "local" {
|
||||
t.Errorf("text/rung = %q/%q, want hi/local", text, rung)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChain_TTSWithProvider_Silent(t *testing.T) {
|
||||
t.Parallel()
|
||||
steps := []Provider{
|
||||
&stubProvider{name: "cloud", tts: &stubTTS{err: ErrNotConfigured}},
|
||||
SilentProvider(),
|
||||
}
|
||||
audio, rung, err := NewChain(steps...).TTSWithProvider(context.Background(), "hi")
|
||||
if err != nil {
|
||||
t.Fatalf("TTSWithProvider error: %v", err)
|
||||
}
|
||||
if len(audio.Data) != 0 || rung != "silent" {
|
||||
t.Errorf("audio/rung = %+v/%q, want empty/silent", audio, rung)
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_TTSWithProvider(t *testing.T) {
|
||||
t.Parallel()
|
||||
svc := NewService(NewChain(NewProvider("edge-tts", nil, &stubTTS{audio: Audio{Format: "mp3", Data: []byte("a")}})))
|
||||
defer svc.Close()
|
||||
|
||||
audio, rung, err := svc.TTSWithProvider(context.Background(), "hi")
|
||||
if err != nil {
|
||||
t.Fatalf("TTSWithProvider error: %v", err)
|
||||
}
|
||||
if string(audio.Data) != "a" || rung != "edge-tts" {
|
||||
t.Errorf("audio/rung = %+v/%q, want a/edge-tts", audio, rung)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user