mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-29 17:08:52 +00:00
Attach context for VAD
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
d2ef353575
commit
b9d58036f2
@ -447,6 +447,14 @@ func updateSession(session *Session, update *Session, cl *config.BackendConfigLo
|
|||||||
// https://github.com/snakers4/silero-vad/tree/master/examples/go
|
// https://github.com/snakers4/silero-vad/tree/master/examples/go
|
||||||
// XXX: use session.ModelInterface for VAD or hook directly VAD runtime here?
|
// XXX: use session.ModelInterface for VAD or hook directly VAD runtime here?
|
||||||
func handleVAD(session *Session, conversation *Conversation, c *websocket.Conn, done chan struct{}) {
|
func handleVAD(session *Session, conversation *Conversation, c *websocket.Conn, done chan struct{}) {
|
||||||
|
|
||||||
|
vadContext, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-done
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
|
|
||||||
// Implement VAD logic here
|
// Implement VAD logic here
|
||||||
// For brevity, this is a placeholder
|
// For brevity, this is a placeholder
|
||||||
// When VAD detects end of speech, generate a response
|
// When VAD detects end of speech, generate a response
|
||||||
@ -467,7 +475,7 @@ func handleVAD(session *Session, conversation *Conversation, c *websocket.Conn,
|
|||||||
}
|
}
|
||||||
soundIntBuffer.Data = sound.ConvertInt16ToInt(adata)
|
soundIntBuffer.Data = sound.ConvertInt16ToInt(adata)
|
||||||
|
|
||||||
resp, err := session.ModelInterface.VAD(context.Background(), &proto.VADRequest{
|
resp, err := session.ModelInterface.VAD(vadContext, &proto.VADRequest{
|
||||||
Audio: soundIntBuffer.AsFloat32Buffer().Data,
|
Audio: soundIntBuffer.AsFloat32Buffer().Data,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user