PreConnectAudioBuffer class

Captures and buffers microphone audio before a room connection completes.

This is used by Room.withPreConnectAudio to reduce perceived latency for voice agent experiences: the microphone can begin recording while the app is still connecting and dispatching an agent, then the buffered audio is sent once the agent becomes active.

Audio is buffered in memory and bounded by defaultMaxSize. If it overflows, the oldest audio is dropped until the agent is ready.

Constructors

PreConnectAudioBuffer(Room _room, {PreConnectOnError? onError, int sampleRate = defaultSampleRate})

Properties

agentReadyFuture Future<void>
Completes when an agent becomes active and the buffer has been sent.
no setter
bufferedSize int
Number of buffered bytes currently stored.
no setter
hashCode int
The hash code for this object.
no setterinherited
isRecording bool
Whether pre-connect recording is currently active.
no setter
localTrack LocalAudioTrack?
The local audio track used for recording while pre-connecting.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() Future<void>
Disposes this buffer (alias for reset).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() Future<void>
Stops recording and clears buffered audio and listeners so the instance can be reused.
sendAudioData({required List<String> agents, String topic = dataTopic}) Future<void>
Sends the currently buffered audio to one or more agent identities.
setErrorHandler(PreConnectOnError? onError) → void
Updates the callback invoked when pre-connect audio fails.
startRecording({Duration timeout = const Duration(seconds: 20)}) Future<void>
Starts capturing audio into an in-memory buffer.
stopRecording({Object? withError}) Future<void>
Stops recording and releases audio capture resources.
toString() String
A string representation of this object.
inherited

Operators

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

Constants

dataTopic → const String
Topic used to send the buffered audio stream to agents.
defaultChunkSize → const int
defaultMaxSize → const int
defaultSampleRate → const int