fix: 修复停止录音后未等待豆包返回最终结果,导致历史记录和自动粘贴失效
This commit is contained in:
@@ -111,6 +111,7 @@ func (c *Client) SendAudio(pcm []byte, last bool) error {
|
|||||||
// readLoop reads server responses and forwards them to resultCh.
|
// readLoop reads server responses and forwards them to resultCh.
|
||||||
func (c *Client) readLoop(resultCh chan<- wsMsg.ServerMsg) {
|
func (c *Client) readLoop(resultCh chan<- wsMsg.ServerMsg) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
c.conn.Close()
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.closed = true
|
c.closed = true
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
@@ -153,13 +154,26 @@ func (c *Client) readLoop(resultCh chan<- wsMsg.ServerMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Close shuts down the ASR connection.
|
// Finish sends the last audio frame and waits for ASR to return final results.
|
||||||
func (c *Client) Close() {
|
func (c *Client) Finish() {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
if !c.closed {
|
if c.closed {
|
||||||
c.conn.Close()
|
c.mu.Unlock()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
// Wait for readLoop to finish
|
_ = c.SendAudio(nil, true)
|
||||||
|
<-c.closeCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close forcefully shuts down the ASR connection.
|
||||||
|
func (c *Client) Close() {
|
||||||
|
c.mu.Lock()
|
||||||
|
if c.closed {
|
||||||
|
c.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.conn.Close()
|
||||||
|
c.mu.Unlock()
|
||||||
<-c.closeCh
|
<-c.closeCh
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user