created centralized UDP Listener

This commit is contained in:
tom.hempel
2025-10-25 14:58:22 +02:00
parent 4ddb89d011
commit 3f72973ff5
10 changed files with 585 additions and 534 deletions

View File

@ -334,6 +334,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
{
ConvaiLogger.Info("🔊 Starting continuous audio monitoring as fallback", ConvaiLogger.LogCategory.Character);
AudioClip lastMonitoredClip = null;
float lastNPCCheckLog = 0f;
while (true)
{
@ -343,6 +344,29 @@ namespace Convai.Scripts.Runtime.Multiplayer
// Check if we still have a valid source NPC
if (sourceNPC == null || sourceNPC.AudioManager == null)
{
// Log every 2 seconds if no NPC found (AGGRESSIVE LOGGING)
if (Time.time - lastNPCCheckLog > 2f)
{
if (sourceNPC == null)
ConvaiLogger.Warn("⚠️ [Speech Sender] No source NPC found! Looking for ConvaiNPC in scene...", ConvaiLogger.LogCategory.Character);
else
ConvaiLogger.Warn($"⚠️ [Speech Sender] NPC '{sourceNPC.characterName}' has no AudioManager!", ConvaiLogger.LogCategory.Character);
// Try to find NPC again
if (useActiveNPC)
{
var foundNPC = FindEnabledConvaiNPC();
if (foundNPC != null && foundNPC != sourceNPC)
{
ConvaiLogger.Info($"✅ [Speech Sender] Found NPC: {foundNPC.characterName} on GameObject '{foundNPC.gameObject.name}'", ConvaiLogger.LogCategory.Character);
sourceNPC = foundNPC;
SubscribeToNPCEvents();
}
}
lastNPCCheckLog = Time.time;
}
yield return new WaitForSeconds(1f); // Wait longer if no NPC
continue;
}
@ -351,6 +375,11 @@ namespace Convai.Scripts.Runtime.Multiplayer
AudioSource audioSource = sourceNPC.AudioManager.GetComponent<AudioSource>();
if (audioSource == null)
{
if (Time.time - lastNPCCheckLog > 2f)
{
ConvaiLogger.Warn($"⚠️ [Speech Sender] NPC '{sourceNPC.characterName}' AudioManager has no AudioSource component!", ConvaiLogger.LogCategory.Character);
lastNPCCheckLog = Time.time;
}
yield return new WaitForSeconds(1f);
continue;
}
@ -455,8 +484,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
byte[] packet = CreateAudioStartPacket(audioClip, transcript, sequence);
await _udpClient.SendAsync(packet, packet.Length, _targetEndPoint);
if (enableDebugLogging)
ConvaiLogger.DebugLog($"📤 Sent start packet {sequence}: {audioClip.samples} samples", ConvaiLogger.LogCategory.Character);
ConvaiLogger.Info($"📤 Sent speech START packet #{sequence} (magic: 0x{MAGIC_NUMBER:X}) to {targetIP}:{targetPort}, {audioClip.samples} samples", ConvaiLogger.LogCategory.Character);
}
private async Task SendAudioClipInChunks(AudioClip audioClip, int sequence)