From a7d408e9032efdd3891194725b54d0e4611c43ea Mon Sep 17 00:00:00 2001 From: Assistant builder Date: Fri, 12 Jun 2026 13:54:16 +0000 Subject: [PATCH] Test 3: scale playback timeout to buffer length (was hardcoded 2 s) FireAndForgetPlayback's cleanup task had the same 2 s done.Wait timeout as the beep cleanup. Beep is 200 ms so 2 s is generous; recording playback is 5 s so the timeout fired mid-playback, cleanup ran stream.Stop(), and the audio cut at ~2.2 s. Timeout is now recording-duration + 2 s. --- tests/03-full-cycle-cs/Program.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/03-full-cycle-cs/Program.cs b/tests/03-full-cycle-cs/Program.cs index dabe81f..c3580ef 100644 --- a/tests/03-full-cycle-cs/Program.cs +++ b/tests/03-full-cycle-cs/Program.cs @@ -347,10 +347,14 @@ static void FireAndForgetPlayback(int device, short[] recordBuf, PlaybackDoneFla done.Dispose(); throw; } + // Timeout = playback wall-clock + 2 s safety margin. Test 2's beep cleanup uses + // a flat 2 s because beep is 200 ms; for a 5 s recording the same value would + // fire mid-playback, Stop the stream, and cut the audio. + double expectedSeconds = recordBuf.Length / (double)WakewordModel.SampleRate; + var waitTimeout = TimeSpan.FromSeconds(expectedSeconds + 2.0); Task.Run(() => { - // Same 2 s safety timeout as the beep cleanup. - if (!done.Wait(TimeSpan.FromSeconds(2))) + if (!done.Wait(waitTimeout)) Console.Error.WriteLine("[error] recording playback timed out — callback may have faulted"); Thread.Sleep(200); stream.Stop();