Skip to content

Expose AudioContext.baseLatency / outputLatency (Web Audio spec) for latency compensation #1104

Description

@akinadebowale

Description

The Web Audio API specifies AudioContext.baseLatency and AudioContext.outputLatency. Neither is exposed by react-native-audio-api at 0.12.2 — not natively, and the web wrapper doesn't pass the browser's values through either (no baseLatency/outputLatency anywhere in the published types).

Why it matters

Any app that records against playing audio (overdub recording, call-and-response, rhythm games) needs recording latency compensation: a take performed in time lands outputLatency + inputLatency late on the timeline unless the app shifts it back. Right now there is no API surface to get those numbers, so apps must ship their own native module or a loopback-calibration flow. For scale: on an iPhone 16 speaker route (playAndRecord), I measure a ~188 ms end-to-end record round-trip through the library — all of it invisible to JS today.

The platform data already exists:

  • iOS: AVAudioSession.{outputLatency, inputLatency, ioBufferDuration} map directly (outputLatency → spec outputLatency; ioBufferDuration-derived term → baseLatency).
  • Android: the library owns the Oboe streams — AudioStream::calculateLatencyMillis() and stream timestamps are available on the open stream.
  • Web: pass through the browser's own properties.

Proposal

  1. context.baseLatency / context.outputLatency per spec (getters, snapshot per call).
  2. Bonus for the recording side: an equivalent input figure (e.g. AudioRecorder.inputLatency or a field on the onAudioReady event) — the spec has nothing here, but AVAudioSession.inputLatency and the Oboe input stream both report it.

Together with #1103 (populate the recorder when), this would make sample-accurate overdub placement possible without any app-side native code.

Environment

react-native-audio-api 0.12.2, iOS + Android + web, new architecture.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions