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.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user