diff --git a/Robovoice.App/VoicePipeline.cs b/Robovoice.App/VoicePipeline.cs index ae25990..b568f71 100644 --- a/Robovoice.App/VoicePipeline.cs +++ b/Robovoice.App/VoicePipeline.cs @@ -68,9 +68,6 @@ internal sealed class VoicePipeline : IDisposable _currentSession++; _gate.Reset(); _audioOutput.Stop(); - - // Unblock player thread if it's waiting on audioQueue.Take() - _audioQueue.Add(new AudioItem(_currentSession - 1, null)); } public void OnPttReleased() @@ -122,20 +119,21 @@ internal sealed class VoicePipeline : IDisposable _gate.Wait(); if (!_running) break; - // Block until first audio item is available - AudioItem firstItem; - try - { - firstItem = _audioQueue.Take(); - } - catch (InvalidOperationException) + // Drain stale items, then wait for real audio for current session + AudioItem firstItem = default!; + while (_running) { + try { firstItem = _audioQueue.Take(); } + catch (InvalidOperationException) { return; } + + if (firstItem.Session != _currentSession) + continue; + break; } if (!_running) break; - if (firstItem.Session != _currentSession) - continue; + if (firstItem.Samples == null) { // :F with no audio — nothing to play @@ -161,7 +159,6 @@ internal sealed class VoicePipeline : IDisposable } _audioOutput.Flush(); - _audioOutput.Stop(); _log("TTS: playback finished"); _gate.Reset(); }