Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ab435b68b1
commit
52172d615f
2 changed files with 28 additions and 7 deletions
|
|
@ -113,16 +113,24 @@ func (c *DiscordChannel) receiveVoice(vc *discordgo.VoiceConnection, guildID str
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p == nil {
|
||||||
|
logger.DebugCF("discord", "Received nil Opus packet", nil)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Opus) == 0 {
|
||||||
|
logger.DebugCF("discord", "Received empty Opus packet", map[string]any{
|
||||||
|
"seq": p.Sequence,
|
||||||
|
"ssrc": p.SSRC,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
logger.DebugCF("discord", "Received Opus packet", map[string]any{
|
logger.DebugCF("discord", "Received Opus packet", map[string]any{
|
||||||
"seq": p.Sequence,
|
"seq": p.Sequence,
|
||||||
"len": len(p.Opus),
|
"len": len(p.Opus),
|
||||||
"ssrc": p.SSRC,
|
"ssrc": p.SSRC,
|
||||||
})
|
})
|
||||||
|
|
||||||
if p == nil || len(p.Opus) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interruption detection: if user sends voice while TTS is playing,
|
// Interruption detection: if user sends voice while TTS is playing,
|
||||||
// cancel TTS after a short debounce (3 packets in 200ms)
|
// cancel TTS after a short debounce (3 packets in 200ms)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
@ -158,7 +166,17 @@ func (c *DiscordChannel) receiveVoice(vc *discordgo.VoiceConnection, guildID str
|
||||||
Data: p.Opus,
|
Data: p.Opus,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.bus.PublishAudioChunk(c.ctx, chunk)
|
ctx, cancel := context.WithTimeout(c.ctx, 100*time.Millisecond)
|
||||||
|
err := c.bus.PublishAudioChunk(ctx, chunk)
|
||||||
|
cancel()
|
||||||
|
if err != nil {
|
||||||
|
logger.ErrorCF("discord", "Failed to publish audio chunk", map[string]any{
|
||||||
|
"guild": guildID,
|
||||||
|
"sessionID": sessionID,
|
||||||
|
"sequence": sequence,
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,10 @@ func (a *Agent) listenChunks(ctx context.Context) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case chunk := <-chunks:
|
case chunk, ok := <-chunks:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
a.handleChunk(chunk)
|
a.handleChunk(chunk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue