feat: 实现 Deepgram STT 服务及测试(WebSocket mock,覆盖成功/超时/空音频/多轮 final)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user