Class VoiceOutputController
- Namespace
- DisCatSharp.Voice.Entities
- Assembly
- DisCatSharp.Voice.dll
Scheduler-based output controller for external voice playback. Replaces the timer-driven always-mix behavior with three explicit modes: idle, Opus passthrough, and interrupt/overlay playback.
public sealed class VoiceOutputController : IExternalOpusSource, IAsyncDisposable
- Inheritance
-
VoiceOutputController
- Implements
- Inherited Members
Remarks
Design goals:
- Music bypasses decode/mix/re-encode completely in steady-state.
- TTS/system audio interrupts or ducks music instead of being hard-mixed.
- Backpressure is bounded and explicit.
- No PeriodicTimer-based master clock in the passthrough path.
Bind this controller to a voice connection via BindExternalOpusSourceAsync(IExternalOpusSource, CancellationToken).
Constructors
- VoiceOutputController(AudioFormat)
Initializes a new instance of the VoiceOutputController class.
Properties
- HasActiveOverlay
Gets a value indicating whether one or more overlay jobs are currently active.
- HasMusicSource
Gets a value indicating whether a music source is currently bound.
- MusicGain
Gets or sets the current music gain multiplier used in passthrough mode. Values below 1 require decode/mix/re-encode and should be avoided for steady-state music.
- PauseMusicForOverlays
Gets or sets a value indicating whether music should be paused while overlays are playing. When true, overlay playback avoids costly hard-mixing and gives the lowest latency.
Methods
- DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
- QueueOwnedPcmOverlayAsync(Stream, string?, CancellationToken)
Queues a PCM overlay job and disposes the stream when playback completes.
- QueuePcmOverlayAsync(Stream, string?, CancellationToken)
Queues a PCM overlay job, such as TTS or a system prompt. The PCM stream must be 16-bit little-endian PCM matching the configured output format.
- ReadFramesAsync(CancellationToken)
Asynchronously reads Opus frames from the external source.
- SetDucking(bool, float)
Sets ducking state explicitly. Prefer pausing music entirely for overlays when possible (lowest latency).
- SetMusicSourceAsync(IExternalOpusSource?, CancellationToken)
Binds the main music source. Rebinding cleanly stops the prior source pump. The music source is expected to produce Opus frames and is forwarded directly when possible.