enhanced UDP audio sender/receiver scripts with metrics for packet tracking and improved NPC assignment logic

This commit is contained in:
tom.hempel
2025-10-23 03:08:51 +02:00
parent 6a99392e34
commit 73b921fc9b
13 changed files with 751 additions and 12 deletions

View File

@ -70,6 +70,16 @@ namespace Convai.Scripts.Runtime.Multiplayer
public event Action<bool> OnRecordingStateChanged;
// Metrics for debug UI
private int _totalPacketsSent = 0;
private DateTime _lastPacketSentTime;
public int TotalPacketsSent => _totalPacketsSent;
public float TimeSinceLastSend => _lastPacketSentTime != default ?
(float)(DateTime.UtcNow - _lastPacketSentTime).TotalSeconds : -1f;
public string CurrentTargetIP => targetIP;
public int CurrentTargetPort => targetPort;
public bool UsingDiscovery => NetworkConfig.Instance?.useAutoDiscovery ?? false;
[Header("Recording Storage")]
[SerializeField] private bool saveLocalAudio = true;
[SerializeField] private int localSampleRate = 16000;
@ -609,6 +619,10 @@ namespace Convai.Scripts.Runtime.Multiplayer
// Send the packet
await _udpClient.SendAsync(packet, packet.Length, _targetEndPoint);
// Update metrics
_totalPacketsSent++;
_lastPacketSentTime = DateTime.UtcNow;
if (enableDebugLogging && _packetSequence % 10 == 0) // Log every 10th packet
{
ConvaiLogger.DebugLog($"Sent packet {_packetSequence} with {currentChunkSamples} samples", ConvaiLogger.LogCategory.Character);