Fix audio pre-buffer bypass on clients due to network sub-chunking
Raw PCM is split into 32KB sub-chunks for network transmission. On the client, these sub-chunks arrive nearly simultaneously, triggering the "second chunk arrived" fast-path which cancelled the pre-buffer after ~10ms instead of the intended 2000ms. Now the fast-path only applies on Authority (server) where chunks represent genuine separate TTS batches. Clients always wait the full pre-buffer duration via TickComponent timer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c0c1b2cea4
commit
0124de8b53
@ -1035,20 +1035,26 @@ void UPS_AI_ConvAgent_ElevenLabsComponent::EnqueueAgentAudio(const TArray<uint8>
|
|||||||
else if (bPreBuffering)
|
else if (bPreBuffering)
|
||||||
{
|
{
|
||||||
// Second (or later) audio chunk arrived during pre-buffer period.
|
// Second (or later) audio chunk arrived during pre-buffer period.
|
||||||
// We now have both chunks buffered — start playback immediately.
|
// On Authority: this means a genuine second TTS chunk arrived from the
|
||||||
bPreBuffering = false;
|
// WebSocket, so we have enough data buffered — start playback immediately.
|
||||||
if (bDebug)
|
// On Clients: sub-chunks from network splitting arrive nearly simultaneously,
|
||||||
|
// which would defeat the pre-buffer. Let the timer in TickComponent handle it.
|
||||||
|
if (GetOwnerRole() == ROLE_Authority)
|
||||||
{
|
{
|
||||||
const double NowPb = FPlatformTime::Seconds();
|
bPreBuffering = false;
|
||||||
const double BufferedMs = (NowPb - PreBufferStartTime) * 1000.0;
|
if (bDebug)
|
||||||
const double Tpb3 = NowPb - SessionStartTime;
|
{
|
||||||
UE_LOG(LogPS_AI_ConvAgent_ElevenLabs, Log,
|
const double NowPb = FPlatformTime::Seconds();
|
||||||
TEXT("[T+%.2fs] [Turn %d] Pre-buffer: second chunk arrived (%.0fms buffered). Starting playback."),
|
const double BufferedMs = (NowPb - PreBufferStartTime) * 1000.0;
|
||||||
Tpb3, LastClosedTurnIndex, BufferedMs);
|
const double Tpb3 = NowPb - SessionStartTime;
|
||||||
}
|
UE_LOG(LogPS_AI_ConvAgent_ElevenLabs, Log,
|
||||||
if (AudioPlaybackComponent && !AudioPlaybackComponent->IsPlaying())
|
TEXT("[T+%.2fs] [Turn %d] Pre-buffer: second chunk arrived (%.0fms buffered). Starting playback."),
|
||||||
{
|
Tpb3, LastClosedTurnIndex, BufferedMs);
|
||||||
AudioPlaybackComponent->Play();
|
}
|
||||||
|
if (AudioPlaybackComponent && !AudioPlaybackComponent->IsPlaying())
|
||||||
|
{
|
||||||
|
AudioPlaybackComponent->Play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SilentTickCount = 0;
|
SilentTickCount = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user