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