feat:语音对话优化

This commit is contained in:
2026-06-14 19:54:22 +08:00
parent 16105f5ac6
commit c3118dd72a
11 changed files with 156 additions and 52 deletions

View File

@@ -158,7 +158,8 @@ func (m *MiMoService) Recognize(ctx context.Context, audio []byte, opts Options)
}
if len(mResp.Choices) == 0 {
return "", fmt.Errorf("stt: mimo returned empty choices")
// MiMo 返回空结果,视为无法识别(非错误),返回空文本
return "", nil
}
text := strings.TrimSpace(mResp.Choices[0].Message.Content)

View File

@@ -103,9 +103,12 @@ func TestMiMoService_Recognize_EmptyChoices(t *testing.T) {
defer srv.Close()
wav := makeValidWAV([]byte{0x00, 0x00})
_, err := s.Recognize(context.Background(), wav, Options{})
if err == nil {
t.Fatal("expected error for empty choices")
text, err := s.Recognize(context.Background(), wav, Options{})
if err != nil {
t.Fatalf("unexpected error for empty choices: %v", err)
}
if text != "" {
t.Errorf("expected empty string for empty choices, got %q", text)
}
}