refactored ConvaiUDPSpeechSender for faster audio clip detection and simplified UDPPeerDiscovery to maintain connection without timeouts or heartbeats

This commit is contained in:
tom.hempel
2025-10-27 15:57:40 +01:00
parent fae9ddc9af
commit 639ac894ce
4 changed files with 28 additions and 57 deletions

View File

@ -292,12 +292,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
{
checkCount++;
// Log periodically to show we're still monitoring
if (enableDebugLogging && checkCount % 10 == 0)
{
ConvaiLogger.DebugLog($"🔊 Monitoring... check #{checkCount}, current clip: {(audioSource?.clip != null ? audioSource.clip.name : "null")}, isTalking: {sourceNPC.IsCharacterTalking}", ConvaiLogger.LogCategory.Character);
}
// SIMPLIFIED: Check EVERY frame if there's a new clip, don't wait for events
if (audioSource?.clip != null && audioSource.clip != lastClip)
{
// New clip detected!
@ -312,6 +307,14 @@ namespace Convai.Scripts.Runtime.Multiplayer
// Get the transcript from the most recent available transcript
string transcript = GetRecentTranscript();
// Start transmission if not already started
if (!_isSendingSpeech)
{
_isSendingSpeech = true;
OnSpeechTransmission?.Invoke(true);
ConvaiLogger.Info($"🔊 Starting speech transmission", ConvaiLogger.LogCategory.Character);
}
// Send this clip
ConvaiLogger.Info($"🔊 TRANSMITTING CLIP to {targetIP}:{targetPort}", ConvaiLogger.LogCategory.Character);
_ = TransmitAudioClip(lastClip, transcript);
@ -322,7 +325,13 @@ namespace Convai.Scripts.Runtime.Multiplayer
}
}
yield return new WaitForSeconds(0.1f); // Check every 100ms
// Log periodically to show we're still monitoring
if (enableDebugLogging && checkCount % 100 == 0)
{
ConvaiLogger.DebugLog($"🔊 Monitoring... check #{checkCount}, current clip: {(audioSource?.clip != null ? audioSource.clip.name : "null")}, isTalking: {sourceNPC.IsCharacterTalking}", ConvaiLogger.LogCategory.Character);
}
yield return new WaitForSeconds(0.05f); // Check every 50ms for faster detection
}
ConvaiLogger.Info($"🔊 Stopped monitoring audio clips (NPC stopped talking or was destroyed). Checks performed: {checkCount}", ConvaiLogger.LogCategory.Character);
@ -440,15 +449,6 @@ namespace Convai.Scripts.Runtime.Multiplayer
try
{
// Start transmission if not already started
if (!_isSendingSpeech)
{
_isSendingSpeech = true;
OnSpeechTransmission?.Invoke(true);
ConvaiLogger.Info($"🔊 Starting speech transmission", ConvaiLogger.LogCategory.Character);
}
// Use the current speech sequence for this entire clip
int clipSequence = _speechSequence;