fix audio cutoff: don't Stop() after playback, let NAudio drain naturally
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user