fix: 修复语音停顿导致提前粘贴的问题(累积文本,松开按钮才粘贴)

This commit is contained in:
2026-03-01 06:34:55 +08:00
parent 350e405fac
commit bfaa792760
2 changed files with 42 additions and 11 deletions

View File

@@ -74,7 +74,7 @@ func Dial(cfg Config, resultCh chan<- wsMsg.ServerMsg) (*Client, error) {
EnableDDC: true,
ShowUtterances: false,
ResultType: "single",
EndWindowSize: 400,
EndWindowSize: 2000,
},
}
data, err := EncodeFullClientRequest(req)
@@ -132,10 +132,15 @@ func (c *Client) readLoop(resultCh chan<- wsMsg.ServerMsg) {
resultCh <- wsMsg.ServerMsg{Type: wsMsg.MsgError, Message: resp.ErrMsg}
return
}
// nostream mode: result comes after last audio packet or >15s
// nostream mode: may return intermediate results every ~15s
text := resp.Text
if text != "" {
resultCh <- wsMsg.ServerMsg{Type: wsMsg.MsgFinal, Text: text}
if resp.IsLast {
resultCh <- wsMsg.ServerMsg{Type: wsMsg.MsgFinal, Text: text}
} else {
// Intermediate result (>15s audio) — preview only, don't paste
resultCh <- wsMsg.ServerMsg{Type: wsMsg.MsgPartial, Text: text}
}
}
if resp.IsLast {
return