XAudioSink class abstract interface

Push-based playback of mono 16 kHz Int16 PCM: enqueue chunks as they arrive and they play back-to-back, starting before the stream ends.

The sink is a writer on the output, not an owner of the route: Apple schedules buffers on an AVAudioPlayerNode, Android streams into an AudioTrack on the media usage. Neither claims the communication route nor takes audio focus, so a call in progress keeps its routing.

final sink = XAudioSink.instance;
await for (final chunk in ttsSocket) {
  await sink.enqueue(chunk);
}
await sink.drained.first;

enqueue resolves once the platform holds the chunk, not when it is audible. flush cancels everything still queued — including chunks this Dart side has not handed over yet — and releases the output; the next enqueue reopens it. A queue that empties on its own leaves the output open, so the next chunk of a conversation starts without a device warm-up.

Implementers

Properties

drained → Stream<void>
Fires each time the queue plays out completely. A broadcast stream; flush cancels queued audio rather than draining it, so it does not fire one.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
state → ValueListenable<XAudioSinkState>
Current lifecycle state, driven by the native sink.
no setter
supported → bool
Whether this platform has a native sink. Elsewhere enqueue throws unsupported and state stays XAudioSinkState.idle.
no setter

Methods

enqueue(Int16List samples) → Future<void>
Appends samples — mono Int16 at sampleRate — to the playback queue, opening the output on the first chunk. Resolves once the platform holds the chunk.
flush() → Future<void>
Silences the output and empties the queue, including chunks enqueued but not yet handed to the platform. state settles to XAudioSinkState.idle; no drained event follows.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

instance → XAudioSink
The process-wide sink. One output, one instance.
final

Constants

sampleRate → const int
Sample rate every enqueued chunk is interpreted at.