Live PCM from a microphone or from what the device plays, tapped natively and delivered to Dart as XAudioFrames of mono 16 kHz Int16 samples.
The microphone tap is a reader of the input, not an owner of the capture
graph: Apple installs it on the AVAudioEngine input node; Android reads
an AudioRecord on VOICE_COMMUNICATION when voice processing is on, and
on MIC when it is off. Consumers feed it to speech recognition and
level meters.
final capture = XAudioCapture.instance;
final sub = capture.frames.listen((f) => recognizer.add(f.samples));
await capture.start();
start and stop are idempotent. state is the single source of truth for whether frames are flowing — it drops to XAudioCaptureState.interrupted when the OS revokes the input, and no capture resumes on its own.
Android hosts must declare android.permission.RECORD_AUDIO; Apple hosts
need NSMicrophoneUsageDescription, and a sandboxed macOS host also needs
com.apple.security.device.audio-input and, for a playback tap,
com.apple.security.screen-capture. Capturing playback asks once more
at start: macOS through the screen-recording grant, Android through
the media-projection consent.
- Implementers
Properties
-
frames
→ Stream<
XAudioFrame> -
Captured audio, from start until capture stops. A broadcast stream:
subscribing does not itself start capture.
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<
XAudioCaptureState> -
Current lifecycle state, driven by the native tap.
no setter
- supported → bool
-
Whether this platform has a native tap. Elsewhere start throws
unsupportedand state stays XAudioCaptureState.idle.no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sources(
) → Future< List< XAudioSource> > -
What this host can tap right now: the hardware inputs the OS names,
plus device playback where the platform taps it — macOS, and Android 10
and newer in an app whose pubspec sets
ux: enable_media_projection: true. iOS lists microphones alone. Empty where supported is false. -
start(
{String? sourceId, bool voiceProcessing = true}) → Future< void> -
Opens
sourceId, or the system's default microphone when it is null, requesting permission if it has not been granted. Returns once frames are flowing; a second call while running does nothing, whateversourceIdit names. -
stop(
) → Future< void> - Closes the tap. Does nothing when already idle. state settles to XAudioCaptureState.idle behind the frames already in flight, so it can still read XAudioCaptureState.running as this returns.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → XAudioCapture
-
The process-wide tap. One source at a time, one instance.
final
Constants
- frameSamples → const int
- Samples per delivered frame — 20 ms at sampleRate.
- sampleRate → const int
- Sample rate of every delivered frame.