mirror of
https://github.com/hanzoai/go-cosyvoice.git
synced 2026-09-30 21:53:53 +00:00
packagec conn object and add README
This commit is contained in:
@@ -138,3 +138,9 @@ func main() {
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
# ADDATIONS
|
||||
### The conditions for WebSocket disconnection
|
||||
1. If task execution fails, the server sends the task-failed event and closes the websocketConnection.
|
||||
2. If the interval between two tasks exceeds 60 seconds, the connection will be disconnected due to timeout. In this package, after the Asynthesizer/Synthesizer object is created, a goroutine is started for health detection by send pingMessage. Developers don't need to worry about this condition.
|
||||
3. In task, if the interval between two commands exceeds 23S, the server triggers a timeout error and disconnects. When you use Asyncthesizer, if your business is likely to exceed 23S, periodically call SendText() to send empty characters or punctuation marks to prevent the connection breaking. Synthesizer is not needed.
|
||||
@@ -95,16 +95,12 @@ func (c *Client) AsyncSynthesizer(ctx context.Context, opts ...SynthesizerOption
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
conn := &wsConn{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
conn: socketConn,
|
||||
logger: option.logger,
|
||||
pingInterval: time.Duration(option.pingInterval) * time.Second,
|
||||
ticker: time.NewTicker(time.Duration(option.pingInterval) * time.Second),
|
||||
}
|
||||
conn := newWsConn(
|
||||
ctx,
|
||||
socketConn,
|
||||
option.logger,
|
||||
time.Duration(option.pingInterval)*time.Second,
|
||||
)
|
||||
|
||||
go conn.handleHealthCheck()
|
||||
|
||||
|
||||
@@ -17,13 +17,26 @@ type wsConn struct {
|
||||
conn openairt.WebSocketConn
|
||||
logger openairt.Logger
|
||||
pingInterval time.Duration
|
||||
ticker *time.Ticker
|
||||
|
||||
ticker *time.Ticker
|
||||
lock sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
sendBarrier chan struct{}
|
||||
}
|
||||
|
||||
func newWsConn(ctx context.Context, conn openairt.WebSocketConn, logger openairt.Logger, pingInterval time.Duration) *wsConn {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
return &wsConn{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
conn: conn,
|
||||
logger: logger,
|
||||
pingInterval: pingInterval,
|
||||
|
||||
ticker: time.NewTicker(pingInterval),
|
||||
}
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
data string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user