@ottervoice/runtime-react-native
Documentation / @ottervoice/runtime-react-native
@ottervoice/runtime-react-native
Section titled “@ottervoice/runtime-react-native”React Native and Expo runtime adapter for OtterVoice recording and gapless PCM playback.
Install
Section titled “Install”npm install @ottervoice/core @ottervoice/runtime-react-nativeimport { createExpoRuntime } from '@ottervoice/runtime-react-native';
const runtime = createExpoRuntime({ input: audioInputBindings, output: audioOutputBindings,});Native capture and playback primitives are injected so the runtime has no hard
dependency on a particular Expo audio library. See the repository’s
examples/react-native-expo app for a complete integration.
Documentation · React Native example · GitHub
License
Section titled “License”MIT
Classes
Section titled “Classes”ExpoAudioInput
Section titled “ExpoAudioInput”Defined in: runtime-react-native/src/audio-input.ts:134
Expo microphone capture with two modes:
- Expo SDK 57 native PCM streaming: continuous RMS/VAD plus a complete WAV emitted at turn end. Encoded capture can be suspended during assistant playback while the volume stream stays active for barge-in.
- Legacy file recording: one recorded-file chunk per start/stop cycle.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ExpoAudioInput(options): ExpoAudioInput;Defined in: runtime-react-native/src/audio-input.ts:147
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
ExpoAudioInputOptions |
Returns
Section titled “Returns”Methods
Section titled “Methods”onChunk()
Section titled “onChunk()”onChunk(cb): () => void;Defined in: runtime-react-native/src/audio-input.ts:281
Subscribe to encoded / PCM chunks.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(chunk) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”onError()
Section titled “onError()”onError(cb): () => void;Defined in: runtime-react-native/src/audio-input.ts:291
Subscribe to capture failures.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(error) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”onVolume()
Section titled “onVolume()”onVolume(cb): () => void;Defined in: runtime-react-native/src/audio-input.ts:286
Subscribe to normalized volume levels in 0..1 for VAD.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(level) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”pause()
Section titled “pause()”pause(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:269
Pause capture without tearing down permission / hardware (optional).
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”requestPermission()
Section titled “requestPermission()”requestPermission(): Promise<boolean>;Defined in: runtime-react-native/src/audio-input.ts:151
Prompt for mic permission; false should surface as a session error.
Returns
Section titled “Returns”Promise<boolean>
Implementation of
Section titled “Implementation of”AudioInputAdapter.requestPermission
resume()
Section titled “resume()”resume(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:273
Resume after pause.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”resumeCapture()
Section titled “resumeCapture()”resumeCapture(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:265
Resume encoded chunk capture after suspendCapture. Runtimes with a
barge-in pre-roll buffer may include it when includePreRoll is true.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”AudioInputAdapter.resumeCapture
start()
Section titled “start()”start(options?): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:155
Begin capture.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
AudioInputOptions |
Preferred rate / encoding hints the runtime may honor. |
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”stop()
Section titled “stop()”stop(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:211
Stop capture and release resources tied to the current start.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”suspendCapture()
Section titled “suspendCapture()”suspendCapture(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:257
Suspend encoded chunk delivery while leaving volume/VAD monitoring active. A runtime may retain a bounded barge-in pre-roll internally.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”AudioInputAdapter.suspendCapture
ExpoAudioOutput
Section titled “ExpoAudioOutput”Defined in: runtime-react-native/src/audio-output.ts:122
Expo audio playback with an optional gapless PCM response queue. The latter lets React Native start speaking as soon as OpenRouter’s first SSE audio delta arrives instead of waiting for the complete WAV response.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ExpoAudioOutput(options): ExpoAudioOutput;Defined in: runtime-react-native/src/audio-output.ts:133
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
ExpoAudioOutputOptions |
Returns
Section titled “Returns”Properties
Section titled “Properties”| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
startPcmStream? |
readonly |
(options) => Promise<AudioOutputStream> |
Begin incremental raw-PCM playback for low-latency speech streaming. | runtime-react-native/src/audio-output.ts:129 |
Methods
Section titled “Methods”onEnd()
Section titled “onEnd()”onEnd(cb): () => void;Defined in: runtime-react-native/src/audio-output.ts:427
Subscribe to playback end (natural finish or stop).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
() => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”onError()
Section titled “onError()”onError(cb): () => void;Defined in: runtime-react-native/src/audio-output.ts:432
Subscribe to playback failures.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(error) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”onStart()
Section titled “onStart()”onStart(cb): () => void;Defined in: runtime-react-native/src/audio-output.ts:422
Subscribe to playback start.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
() => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”onVolume()
Section titled “onVolume()”onVolume(cb): () => void;Defined in: runtime-react-native/src/audio-output.ts:417
Subscribe to normalized RMS of the assistant audio currently being played (used as an acoustic echo reference for barge-in).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(level, at?) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”pause()
Section titled “pause()”pause(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:393
Pause playback without discarding the current utterance (optional).
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”play()
Section titled “play()”play(input): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:139
Play a complete encoded buffer or URL.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
AudioPlaybackInput |
URL and/or in-memory bytes plus optional MIME / volume. |
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”resume()
Section titled “resume()”resume(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:401
Resume after AudioOutputAdapter.pause.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”stop()
Section titled “stop()”stop(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:382
Stop current playback and cancel any open PCM stream.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”Interfaces
Section titled “Interfaces”ExpoAudioInputOptions
Section titled “ExpoAudioInputOptions”Defined in: runtime-react-native/src/audio-input.ts:46
Injected mic / file helpers for ExpoAudioInput. Prefer ExpoAudioInputOptions.createPcmStream for full-duplex VAD; fall back to ExpoAudioInputOptions.createRecording for batch capture. Wired by createExpoRuntime via ExpoRuntimeOptions.input.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
createPcmStream? |
(options, onBuffer) => | ExpoPcmInputStream | Promise<ExpoPcmInputStream> |
Create a native PCM microphone stream. Expo SDK 57 useAudioStream can supply this without custom native code, so it also works in Expo Go. |
runtime-react-native/src/audio-input.ts:55 |
createRecording? |
() => Promise<ExpoRecordingHandle> |
Legacy file recorder factory. Prefer createPcmStream for full duplex. |
runtime-react-native/src/audio-input.ts:48 |
now? |
() => number |
Override clock used for chunk timestamps (tests). | runtime-react-native/src/audio-input.ts:62 |
readAudioFile? |
(uri) => Promise<ArrayBuffer> |
Read a legacy recorded file URI into an ArrayBuffer. | runtime-react-native/src/audio-input.ts:50 |
requestPermission? |
() => Promise<boolean> |
Microphone permission (wrap requestRecordingPermissionsAsync). |
runtime-react-native/src/audio-input.ts:60 |
ExpoAudioOutputOptions
Section titled “ExpoAudioOutputOptions”Defined in: runtime-react-native/src/audio-output.ts:71
Injected playback / file helpers for ExpoAudioOutput. Provide ExpoAudioOutputOptions.createPcmPlaylist plus ExpoAudioOutputOptions.writePcmChunk for streaming assistant audio; ExpoAudioOutputOptions.createSound covers one-shot URI playback. Wired by createExpoRuntime via ExpoRuntimeOptions.output.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
createPcmPlaylist? |
() => | ExpoPcmPlaylist | Promise<ExpoPcmPlaylist> |
Create an Expo AudioPlaylist configured for frequent status updates. |
runtime-react-native/src/audio-output.ts:77 |
createSound |
(uri) => Promise<ExpoSound> |
Load a sound from a URI (wrap createAudioPlayer). |
runtime-react-native/src/audio-output.ts:73 |
deleteAudioFile? |
(uri) => void | Promise<void> |
Best-effort cleanup for temporary response chunk files. | runtime-react-native/src/audio-output.ts:81 |
writeAudioFile? |
(buffer, mimeType) => Promise<string> |
Persist a complete audio buffer to a file URI. | runtime-react-native/src/audio-output.ts:75 |
writePcmChunk? |
(input) => Promise<string> |
Wrap and persist one PCM16 response chunk as a small WAV file. | runtime-react-native/src/audio-output.ts:79 |
ExpoPcmChunkFileInput
Section titled “ExpoPcmChunkFileInput”Defined in: runtime-react-native/src/audio-output.ts:57
One PCM16 fragment to persist as a WAV URI for playlist playback.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|
channels |
number |
Channel count of subsequent write payloads. |
PcmAudioStreamOptions.channels |
core/dist/types.d.ts:678 |
data |
ArrayBuffer |
Interleaved PCM16 bytes for this chunk. | - | runtime-react-native/src/audio-output.ts:59 |
encoding |
"pcm_s16le" |
Always linear 16-bit PCM for incremental streams. | PcmAudioStreamOptions.encoding |
core/dist/types.d.ts:674 |
index |
number |
Monotonic chunk index used for temp filenames. | - | runtime-react-native/src/audio-output.ts:61 |
sampleRate |
number |
Sample rate of subsequent write payloads in Hz. |
PcmAudioStreamOptions.sampleRate |
core/dist/types.d.ts:676 |
volume? |
number |
Playback gain in [0, 1]. |
PcmAudioStreamOptions.volume |
core/dist/types.d.ts:680 |
ExpoPcmInputBuffer
Section titled “ExpoPcmInputBuffer”Defined in: runtime-react-native/src/audio-input.ts:17
A raw PCM block produced by Expo SDK 57’s useAudioStream.
Properties
Section titled “Properties”ExpoPcmInputStream
Section titled “ExpoPcmInputStream”Defined in: runtime-react-native/src/audio-input.ts:25
The small part of Expo’s native AudioStream used by the runtime.
Methods
Section titled “Methods”start()
Section titled “start()”start(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:26
Returns
Section titled “Returns”Promise<void>
stop()
Section titled “stop()”stop(): void | Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:27
Returns
Section titled “Returns”void | Promise<void>
ExpoPcmInputStreamOptions
Section titled “ExpoPcmInputStreamOptions”Defined in: runtime-react-native/src/audio-input.ts:31
Sample format requested when creating ExpoPcmInputStream.
Properties
Section titled “Properties”ExpoPcmPlaylist
Section titled “ExpoPcmPlaylist”Defined in: runtime-react-native/src/audio-output.ts:46
Gapless Expo AudioPlaylist surface used for incremental PCM playback.
Methods
Section titled “Methods”add(uri): void;Defined in: runtime-react-native/src/audio-output.ts:47
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
uri |
string |
Returns
Section titled “Returns”void
clear()
Section titled “clear()”clear(): void;Defined in: runtime-react-native/src/audio-output.ts:51
Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy(): void;Defined in: runtime-react-native/src/audio-output.ts:52
Returns
Section titled “Returns”void
next()
Section titled “next()”next(): void;Defined in: runtime-react-native/src/audio-output.ts:48
Returns
Section titled “Returns”void
pause()
Section titled “pause()”pause(): void | Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:50
Returns
Section titled “Returns”void | Promise<void>
play()
Section titled “play()”play(): void | Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:49
Returns
Section titled “Returns”void | Promise<void>
setOnPlaybackStatusUpdate()
Section titled “setOnPlaybackStatusUpdate()”setOnPlaybackStatusUpdate(cb): () => void;Defined in: runtime-react-native/src/audio-output.ts:53
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(status) => void |
Returns
Section titled “Returns”() => void
ExpoPcmPlaylistStatus
Section titled “ExpoPcmPlaylistStatus”Defined in: runtime-react-native/src/audio-output.ts:28
Status callback payload from an ExpoPcmPlaylist.
Properties
Section titled “Properties”ExpoPlaybackStatus
Section titled “ExpoPlaybackStatus”Defined in: runtime-react-native/src/audio-output.ts:11
Status callback payload from an ExpoSound player.
Properties
Section titled “Properties”ExpoRecordingHandle
Section titled “ExpoRecordingHandle”Defined in: runtime-react-native/src/audio-input.ts:10
An Expo file-recording handle, kept for backwards-compatible batch capture.
Methods
Section titled “Methods”getURI()
Section titled “getURI()”getURI(): string | null;Defined in: runtime-react-native/src/audio-input.ts:13
Returns
Section titled “Returns”string | null
startAsync()
Section titled “startAsync()”startAsync(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:11
Returns
Section titled “Returns”Promise<void>
stopAndUnloadAsync()
Section titled “stopAndUnloadAsync()”stopAndUnloadAsync(): Promise<void>;Defined in: runtime-react-native/src/audio-input.ts:12
Returns
Section titled “Returns”Promise<void>
ExpoRuntime
Section titled “ExpoRuntime”Defined in: runtime-react-native/src/index.ts:24
Expo / React Native RuntimeAdapter returned by createExpoRuntime.
No network adapter — providers use global fetch / WebSocket.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|
audioInput |
ExpoAudioInput |
Microphone capture (PCM stream or legacy file recorder). | RuntimeAdapter.audioInput |
- | runtime-react-native/src/index.ts:26 |
audioOutput |
ExpoAudioOutput |
One-shot and gapless PCM playlist playback. | RuntimeAdapter.audioOutput |
- | runtime-react-native/src/index.ts:28 |
logger? |
LoggerAdapter |
Optional logger; core uses it sparingly. | - | RuntimeAdapter.logger |
core/dist/types.d.ts:853 |
network? |
NetworkAdapter |
Optional HTTP/WebSocket hooks for providers. | - | RuntimeAdapter.network |
core/dist/types.d.ts:849 |
storage? |
RuntimeStorageAdapter |
Optional persistence for caches. | - | RuntimeAdapter.storage |
core/dist/types.d.ts:851 |
ExpoRuntimeOptions
Section titled “ExpoRuntimeOptions”Defined in: runtime-react-native/src/index.ts:13
Injected Expo audio bindings for createExpoRuntime.
Pass platform primitives from expo-audio / file helpers so the package
stays free of a hard Expo dependency and remains testable.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
input |
ExpoAudioInputOptions |
Injected PCM capture bindings (Expo AudioStream / file helpers). | runtime-react-native/src/index.ts:15 |
output |
ExpoAudioOutputOptions |
Injected playback bindings (AudioPlaylist / PCM stream). | runtime-react-native/src/index.ts:17 |
ExpoSound
Section titled “ExpoSound”Defined in: runtime-react-native/src/audio-output.ts:19
An Expo AudioPlayer-like handle (abstracted for injection/testing).
Methods
Section titled “Methods”pauseAsync()?
Section titled “pauseAsync()?”optional pauseAsync(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:21
Returns
Section titled “Returns”Promise<void>
playAsync()
Section titled “playAsync()”playAsync(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:20
Returns
Section titled “Returns”Promise<void>
setOnPlaybackStatusUpdate()
Section titled “setOnPlaybackStatusUpdate()”setOnPlaybackStatusUpdate(cb): void;Defined in: runtime-react-native/src/audio-output.ts:24
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(status) => void |
Returns
Section titled “Returns”void
stopAsync()
Section titled “stopAsync()”stopAsync(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:22
Returns
Section titled “Returns”Promise<void>
unloadAsync()
Section titled “unloadAsync()”unloadAsync(): Promise<void>;Defined in: runtime-react-native/src/audio-output.ts:23
Returns
Section titled “Returns”Promise<void>
Functions
Section titled “Functions”createExpoRuntime()
Section titled “createExpoRuntime()”function createExpoRuntime(options): ExpoRuntime;Defined in: runtime-react-native/src/index.ts:39
Assemble an Expo RuntimeAdapter. You inject the Expo Audio /
expo-file-system primitives (so the adapter stays testable and free of a
hard Expo dependency). No network adapter is included — providers use the
global fetch/WebSocket available in React Native.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
ExpoRuntimeOptions |
Injected input/output primitives. See ExpoRuntimeOptions. |
Returns
Section titled “Returns”pcm16ToWav()
Section titled “pcm16ToWav()”function pcm16ToWav( pcm, sampleRate, channels): ArrayBuffer;Defined in: runtime-react-native/src/audio-input.ts:83
Wrap interleaved little-endian PCM16 in a standard WAV container.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
pcm |
Uint8Array |
Interleaved PCM16 samples. |
sampleRate |
number |
Sample rate in Hz. |
channels |
number |
Channel count (typically 1). |
Returns
Section titled “Returns”ArrayBuffer
A standard WAV container buffer.