feat: 实现 Deepgram STT 服务及测试(WebSocket mock,覆盖成功/超时/空音频/多轮 final)

This commit is contained in:
hhs
2026-06-13 15:41:44 +08:00
parent 6fcbf023b4
commit 8f9b0b881e
2 changed files with 193 additions and 5 deletions

View File

@@ -95,16 +95,13 @@ func (d *DeepgramService) Recognize(ctx context.Context, audio []byte, opts Opti
continue
}
if len(resp.Channel.Alternatives) > 0 {
// 只累积 final 结果,跳过中间结果
if resp.IsFinal && len(resp.Channel.Alternatives) > 0 {
text := strings.TrimSpace(resp.Channel.Alternatives[0].Transcript)
if text != "" {
transcript.WriteString(text)
}
}
if resp.IsFinal {
break
}
}
return strings.TrimSpace(transcript.String()), nil