Fix raw PCM multicast exceeding UE5 replicated array limit
UE5 limits replicated TArrays to 65535 elements. ElevenLabs sends audio chunks up to ~72K bytes, exceeding this limit when sent as raw PCM. Split into 32000-byte sub-chunks (1s of 16kHz 16-bit mono) before calling MulticastReceiveAgentAudio. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6cac56fa06
commit
fc728454d0
@ -658,14 +658,25 @@ void UPS_AI_ConvAgent_ElevenLabsComponent::HandleAudioReceived(const TArray<uint
|
||||
{
|
||||
// Fallback: send raw PCM (no compression). ~32 KB/s at 16kHz 16-bit mono.
|
||||
// Fine for LAN; revisit with proper Opus if internet play is needed.
|
||||
// UE5 limits replicated TArrays to 65535 elements, so we must chunk.
|
||||
static bool bWarnedOnce = false;
|
||||
if (!bWarnedOnce)
|
||||
{
|
||||
bWarnedOnce = true;
|
||||
UE_LOG(LogPS_AI_ConvAgent_ElevenLabs, Warning,
|
||||
TEXT("[NET-SRV] Opus encoder unavailable — sending raw PCM (no compression)."));
|
||||
TEXT("[NET-SRV] Opus encoder unavailable — sending raw PCM in chunks (no compression)."));
|
||||
}
|
||||
|
||||
static constexpr int32 MaxChunkBytes = 32000; // 1s of 16kHz 16-bit mono, well under 65535 limit
|
||||
int32 Offset = 0;
|
||||
while (Offset < PCMData.Num())
|
||||
{
|
||||
const int32 ChunkSize = FMath::Min(MaxChunkBytes, PCMData.Num() - Offset);
|
||||
TArray<uint8> Chunk;
|
||||
Chunk.Append(PCMData.GetData() + Offset, ChunkSize);
|
||||
MulticastReceiveAgentAudio(Chunk);
|
||||
Offset += ChunkSize;
|
||||
}
|
||||
MulticastReceiveAgentAudio(PCMData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user