@ottervoice/core
Documentation / @ottervoice/core
@ottervoice/core
Section titled “@ottervoice/core”Platform-agnostic core for OtterVoice — a TypeScript-first SDK for real-time voice conversation, including full-duplex barge-in.
This package contains no DOM, Node or native dependencies. It provides the session state machine, typed events, provider router, transcript buffer, turn detector, usage meter, a normalized error model, and built-in mock providers / runtime for testing.
bun add @ottervoice/coreWhat’s inside
Section titled “What’s inside”| Export | Purpose |
|---|---|
createVoiceSession / VoiceSession |
Conversation loop and full-duplex interruption policy. |
StateMachine, canTransition, isTerminal |
Session state transitions. |
TypedEmitter |
Strongly-typed, unsubscribe-returning event emitter. |
TranscriptBuffer |
Ordered turns → LLM message projection. |
TurnDetector |
Rule-based VAD / endpointing from volume samples. |
UsageMeter |
Per-session usage snapshot (you bill; it measures). |
ProviderRegistry, providerProfiles, resolveProfile |
Provider routing. |
createVoiceError, normalizeError, VoiceError |
Unified error model. |
createMockASR/LLM/TTS/Pronunciation, createMockRuntime |
Test doubles. |
Provider & runtime contracts
Section titled “Provider & runtime contracts”Implement these interfaces to plug in real services / platforms:
ASRProvider—createSession()→ streaming partial/final transcripts.LLMProvider—generate()(and optionalstream()).AudioLLMProvider— one model consumes a completed audio turn and returns assistant transcript + audio; setpipeline: 'audio_llm'. Caption ASR runs in parallel and does not feed the model.TTSProvider—synthesize()→ audio buffer or URL.PronunciationProvider—assess()→ scores.RuntimeAdapter—audioInput,audioOutput, optionalnetwork/storage/logger.
Every error raised by an adapter should be a NormalizedVoiceError (use
createVoiceError), so consumers handle one shape regardless of provider.
Set VoiceSessionConfig.asrPartial to false when provisional captions are not
needed. Core passes that preference to the ASR session while preserving
asr_final. For batch-backed rolling ASR, providers may implement
ASRSession.setInterimResultsEnabled(); volume-based sessions use it to defer
paid partial work until VAD confirms speech.
Session events
Section titled “Session events”statechange, asr_partial, asr_final, user_audio_end, assistant_text,
assistant_audio_start, assistant_audio_end, turn, usage, finished,
error. Subscribe with session.on(event, cb); the returned function
unsubscribes.
Example
Section titled “Example”See the root README for a
runnable, fully-mocked quick start, and examples/node-cli for an end-to-end
demo.
License
Section titled “License”MIT
Classes
Section titled “Classes”BargeInSpeechGate
Section titled “BargeInSpeechGate”Defined in: packages/core/src/playback-echo-filter.ts:44
Detects speech-shaped residual energy without requiring every audio frame to be loud. Natural speech contains short gaps between syllables; a vote over a moving window rejects isolated knocks while preserving those gaps.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BargeInSpeechGate(options?): BargeInSpeechGate;Defined in: packages/core/src/playback-echo-filter.ts:50
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
BargeInSpeechGateOptions |
Returns
Section titled “Returns”Methods
Section titled “Methods”push()
Section titled “push()”push(level): boolean;Defined in: packages/core/src/playback-echo-filter.ts:56
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
level |
number |
Returns
Section titled “Returns”boolean
reset()
Section titled “reset()”reset(): void;Defined in: packages/core/src/playback-echo-filter.ts:62
Returns
Section titled “Returns”void
MockAudioInput
Section titled “MockAudioInput”Defined in: packages/core/src/providers/mock-runtime.ts:24
In-memory audio input. Tests drive it by calling MockAudioInput.emitChunk / MockAudioInput.emitVolume; nothing touches a real microphone.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MockAudioInput(options?): MockAudioInput;Defined in: packages/core/src/providers/mock-runtime.ts:33
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
MockAudioInputOptions |
Returns
Section titled “Returns”Properties
Section titled “Properties”| Property | Type | Default value | Defined in |
|---|---|---|---|
lastOptions |
| AudioInputOptions | undefined |
undefined |
packages/core/src/providers/mock-runtime.ts:31 |
paused |
boolean |
false |
packages/core/src/providers/mock-runtime.ts:30 |
started |
boolean |
false |
packages/core/src/providers/mock-runtime.ts:29 |
Methods
Section titled “Methods”emitChunk()
Section titled “emitChunk()”emitChunk(chunk): void;Defined in: packages/core/src/providers/mock-runtime.ts:60
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
chunk |
AudioChunk |
Returns
Section titled “Returns”void
emitError()
Section titled “emitError()”emitError(error): void;Defined in: packages/core/src/providers/mock-runtime.ts:68
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
error |
NormalizedVoiceError |
Returns
Section titled “Returns”void
emitVolume()
Section titled “emitVolume()”emitVolume(level): void;Defined in: packages/core/src/providers/mock-runtime.ts:64
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
level |
number |
Returns
Section titled “Returns”void
onChunk()
Section titled “onChunk()”onChunk(cb): () => void;Defined in: packages/core/src/providers/mock-runtime.ts:72
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: packages/core/src/providers/mock-runtime.ts:82
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: packages/core/src/providers/mock-runtime.ts:77
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: packages/core/src/providers/mock-runtime.ts:52
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: packages/core/src/providers/mock-runtime.ts:37
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: packages/core/src/providers/mock-runtime.ts:56
Resume after pause.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”start()
Section titled “start()”start(options): Promise<void>;Defined in: packages/core/src/providers/mock-runtime.ts:41
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: packages/core/src/providers/mock-runtime.ts:47
Stop capture and release resources tied to the current start.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”MockAudioOutput
Section titled “MockAudioOutput”Defined in: packages/core/src/providers/mock-runtime.ts:100
In-memory audio output. Records what was “played”.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MockAudioOutput(options?): MockAudioOutput;Defined in: packages/core/src/providers/mock-runtime.ts:113
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
MockAudioOutputOptions |
Returns
Section titled “Returns”Properties
Section titled “Properties”| Property | Type | Default value | Defined in |
|---|---|---|---|
paused |
number |
0 |
packages/core/src/providers/mock-runtime.ts:109 |
played |
AudioPlaybackInput[] |
[] |
packages/core/src/providers/mock-runtime.ts:107 |
resumed |
number |
0 |
packages/core/src/providers/mock-runtime.ts:110 |
stopped |
number |
0 |
packages/core/src/providers/mock-runtime.ts:108 |
Methods
Section titled “Methods”emitVolume()
Section titled “emitVolume()”emitVolume(level): void;Defined in: packages/core/src/providers/mock-runtime.ts:154
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
level |
number |
Returns
Section titled “Returns”void
fireEnd()
Section titled “fireEnd()”fireEnd(): void;Defined in: packages/core/src/providers/mock-runtime.ts:148
Returns
Section titled “Returns”void
onEnd()
Section titled “onEnd()”onEnd(cb): () => void;Defined in: packages/core/src/providers/mock-runtime.ts:168
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: packages/core/src/providers/mock-runtime.ts:173
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: packages/core/src/providers/mock-runtime.ts:163
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: packages/core/src/providers/mock-runtime.ts:158
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) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
Implementation of
Section titled “Implementation of”pause()
Section titled “pause()”pause(): Promise<void>;Defined in: packages/core/src/providers/mock-runtime.ts:140
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: packages/core/src/providers/mock-runtime.ts:118
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: packages/core/src/providers/mock-runtime.ts:144
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: packages/core/src/providers/mock-runtime.ts:134
Stop current playback and cancel any open PCM stream.
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”PlaybackEchoFilter
Section titled “PlaybackEchoFilter”Defined in: packages/core/src/playback-echo-filter.ts:72
Removes the component of microphone RMS that is correlated with assistant playback. It searches a short delay window because browser playback, loudspeaker travel and microphone analysis are not sample-synchronous.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PlaybackEchoFilter(options?): PlaybackEchoFilter;Defined in: packages/core/src/playback-echo-filter.ts:84
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
PlaybackEchoFilterOptions |
Returns
Section titled “Returns”Methods
Section titled “Methods”filter()
Section titled “filter()”filter(microphoneLevel, at): number;Defined in: packages/core/src/playback-echo-filter.ts:118
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
microphoneLevel |
number |
at |
number |
Returns
Section titled “Returns”number
isReady()
Section titled “isReady()”isReady(at): boolean;Defined in: packages/core/src/playback-echo-filter.ts:163
True once enough playback reference frames exist to estimate echo.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
at |
number |
Returns
Section titled “Returns”boolean
pushOutput()
Section titled “pushOutput()”pushOutput(level, at): void;Defined in: packages/core/src/playback-echo-filter.ts:110
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
level |
number |
at |
number |
Returns
Section titled “Returns”void
reset()
Section titled “reset()”reset(): void;Defined in: packages/core/src/playback-echo-filter.ts:155
Returns
Section titled “Returns”void
start()
Section titled “start()”start(_at): void;Defined in: packages/core/src/playback-echo-filter.ts:96
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
_at |
number |
Returns
Section titled “Returns”void
stop()
Section titled “stop()”stop(): void;Defined in: packages/core/src/playback-echo-filter.ts:106
Returns
Section titled “Returns”void
ProviderRegistry
Section titled “ProviderRegistry”Defined in: packages/core/src/provider-router.ts:156
Maps provider ids (as used in ProviderProfile) to concrete provider instances, and resolves a profile into a usable ResolvedProviders bundle for a import(‘./session’).VoiceSession.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ProviderRegistry(initial?): ProviderRegistry;Defined in: packages/core/src/provider-router.ts:162
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
initial? |
RegisteredProviders |
Returns
Section titled “Returns”Methods
Section titled “Methods”getProfile()
Section titled “getProfile()”getProfile(name): ProviderProfile;Defined in: packages/core/src/provider-router.ts:199
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
ProviderProfileName |
Returns
Section titled “Returns”registerASR()
Section titled “registerASR()”registerASR(id, provider): this;Defined in: packages/core/src/provider-router.ts:179
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
provider |
ASRProvider |
Returns
Section titled “Returns”this
registerLLM()
Section titled “registerLLM()”registerLLM(id, provider): this;Defined in: packages/core/src/provider-router.ts:184
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
provider |
LLMProvider |
Returns
Section titled “Returns”this
registerPronunciation()
Section titled “registerPronunciation()”registerPronunciation(id, provider): this;Defined in: packages/core/src/provider-router.ts:194
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
provider |
PronunciationProvider |
Returns
Section titled “Returns”this
registerTTS()
Section titled “registerTTS()”registerTTS(id, provider): this;Defined in: packages/core/src/provider-router.ts:189
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
provider |
TTSProvider |
Returns
Section titled “Returns”this
resolve()
Section titled “resolve()”resolve(profileOrName): ResolvedProviders;Defined in: packages/core/src/provider-router.ts:203
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
profileOrName |
| ProviderProfileName | ProviderProfile |
Returns
Section titled “Returns”StateMachine
Section titled “StateMachine”Defined in: packages/core/src/state-machine.ts:77
Pure state container. The session owns one of these and is the only thing that mutates it via StateMachine.transition.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new StateMachine(initial?): StateMachine;Defined in: packages/core/src/state-machine.ts:80
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
initial |
VoiceSessionState |
'idle' |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get state(): VoiceSessionState;Defined in: packages/core/src/state-machine.ts:84
Returns
Section titled “Returns”Methods
Section titled “Methods”can(to): boolean;Defined in: packages/core/src/state-machine.ts:88
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
to |
VoiceSessionState |
Returns
Section titled “Returns”boolean
transition()
Section titled “transition()”transition(to): VoiceSessionState;Defined in: packages/core/src/state-machine.ts:96
Move to to, returning the previous state. Throws a VoiceError
with code invalid_state when the transition is not allowed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
to |
VoiceSessionState |
Returns
Section titled “Returns”TranscriptBuffer
Section titled “TranscriptBuffer”Defined in: packages/core/src/transcript-buffer.ts:30
Ordered store of conversation turns. Owns nothing about providers — it just accumulates turns and projects them into the shape the LLM expects.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TranscriptBuffer(generateId, now): TranscriptBuffer;Defined in: packages/core/src/transcript-buffer.ts:33
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
generateId |
() => string |
now |
() => number |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size(): number;Defined in: packages/core/src/transcript-buffer.ts:63
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(input): VoiceTurn;Defined in: packages/core/src/transcript-buffer.ts:38
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
AddTurnInput |
Returns
Section titled “Returns”all(): VoiceTurn[];Defined in: packages/core/src/transcript-buffer.ts:68
Immutable snapshot of all turns.
Returns
Section titled “Returns”clear()
Section titled “clear()”clear(): void;Defined in: packages/core/src/transcript-buffer.ts:82
Returns
Section titled “Returns”void
last()
Section titled “last()”last(): | VoiceTurn | undefined;Defined in: packages/core/src/transcript-buffer.ts:59
The most recently added turn, or undefined when empty.
Returns
Section titled “Returns”| VoiceTurn
| undefined
toMessages()
Section titled “toMessages()”toMessages(): LLMMessage[];Defined in: packages/core/src/transcript-buffer.ts:73
Project turns into LLM messages, dropping any with empty text.
Returns
Section titled “Returns”TurnDetector
Section titled “TurnDetector”Defined in: packages/core/src/turn-detector.ts:51
Rule-based voice-activity / endpointing detector.
It is driven purely by (volume, timestampMs) samples fed via
TurnDetector.pushVolume. It tracks whether the user has begun
speaking (volume over threshold for minSpeechMs) and when they have
stopped (volume under threshold for silenceTimeoutMs). This keeps the
detector free of timers so it is deterministic and trivially testable; the
session supplies the clock.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TurnDetector(config?): TurnDetector;Defined in: packages/core/src/turn-detector.ts:58
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config? |
TurnDetectionConfig |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”isSpeaking
Section titled “isSpeaking”Get Signature
Section titled “Get Signature”get isSpeaking(): boolean;Defined in: packages/core/src/turn-detector.ts:62
Returns
Section titled “Returns”boolean
options
Section titled “options”Get Signature
Section titled “Get Signature”get options(): Required<TurnDetectionConfig>;Defined in: packages/core/src/turn-detector.ts:66
Returns
Section titled “Returns”Required<TurnDetectionConfig>
Methods
Section titled “Methods”forceSpeechStart()
Section titled “forceSpeechStart()”forceSpeechStart(timestampMs): void;Defined in: packages/core/src/turn-detector.ts:71
Continue endpointing after another detector has already confirmed speech.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
timestampMs |
number |
Returns
Section titled “Returns”void
pushVolume()
Section titled “pushVolume()”pushVolume(volume, timestampMs): | TurnDetectorEvent | undefined;Defined in: packages/core/src/turn-detector.ts:86
Feed a volume sample. Returns an event when a boundary is crossed, else
undefined.
speech_start— sustained volume over threshold forminSpeechMs.speech_end— sustained silence forsilenceTimeoutMsafter speech.max_turn— speech has run longer thanmaxTurnMs(forced end).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
volume |
number |
timestampMs |
number |
Returns
Section titled “Returns”| TurnDetectorEvent
| undefined
reset()
Section titled “reset()”reset(): void;Defined in: packages/core/src/turn-detector.ts:127
Returns
Section titled “Returns”void
TypedEmitter
Section titled “TypedEmitter”Defined in: packages/core/src/emitter.ts:8
Minimal, dependency-free, strongly-typed event emitter.
EventMap maps event names to their payload type. on/once return an
unsubscribe function so callers never need to keep references to the
original callback.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
EventMap extends Record<string, unknown> |
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TypedEmitter<EventMap>(): TypedEmitter<EventMap>;Defined in: packages/core/src/emitter.ts:11
Returns
Section titled “Returns”TypedEmitter<EventMap>
Methods
Section titled “Methods”emit()
Section titled “emit()”emit<K>(event, payload): void;Defined in: packages/core/src/emitter.ts:49
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
K |
payload |
EventMap[K] |
Returns
Section titled “Returns”void
listenerCount()
Section titled “listenerCount()”listenerCount<K>(event): number;Defined in: packages/core/src/emitter.ts:59
Number of registered listeners for an event (primarily for testing).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
K |
Returns
Section titled “Returns”number
off<K>(event, cb): void;Defined in: packages/core/src/emitter.ts:39
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
K |
cb |
(payload) => void |
Returns
Section titled “Returns”void
on<K>(event, cb): () => void;Defined in: packages/core/src/emitter.ts:15
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
K |
cb |
(payload) => void |
Returns
Section titled “Returns”() => void
once()
Section titled “once()”once<K>(event, cb): () => void;Defined in: packages/core/src/emitter.ts:28
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends string | number | symbol |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
event |
K |
cb |
(payload) => void |
Returns
Section titled “Returns”() => void
removeAllListeners()
Section titled “removeAllListeners()”removeAllListeners(): void;Defined in: packages/core/src/emitter.ts:64
Drop every listener. Called when a session is disposed.
Returns
Section titled “Returns”void
UsageMeter
Section titled “UsageMeter”Defined in: packages/core/src/usage-meter.ts:7
Accumulates per-session usage. The SDK measures, it does not bill — business code consumes the VoiceUsageSnapshot to enforce quotas/plans.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new UsageMeter(now): UsageMeter;Defined in: packages/core/src/usage-meter.ts:19
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
now |
() => number |
Returns
Section titled “Returns”Methods
Section titled “Methods”addAsrAudioMs()
Section titled “addAsrAudioMs()”addAsrAudioMs(ms): void;Defined in: packages/core/src/usage-meter.ts:33
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ms |
number |
Returns
Section titled “Returns”void
addAssistantSpeechChars()
Section titled “addAssistantSpeechChars()”addAssistantSpeechChars(chars): void;Defined in: packages/core/src/usage-meter.ts:37
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
chars |
number |
Returns
Section titled “Returns”void
addLlmUsage()
Section titled “addLlmUsage()”addLlmUsage(usage): void;Defined in: packages/core/src/usage-meter.ts:45
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
usage |
| LLMUsage | undefined |
Returns
Section titled “Returns”void
addProviderCost()
Section titled “addProviderCost()”addProviderCost(provider, cost): void;Defined in: packages/core/src/usage-meter.ts:57
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
provider |
string |
cost |
number |
Returns
Section titled “Returns”void
addTtsChars()
Section titled “addTtsChars()”addTtsChars(chars): void;Defined in: packages/core/src/usage-meter.ts:41
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
chars |
number |
Returns
Section titled “Returns”void
addUserSpeechMs()
Section titled “addUserSpeechMs()”addUserSpeechMs(ms): void;Defined in: packages/core/src/usage-meter.ts:29
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ms |
number |
Returns
Section titled “Returns”void
endSession()
Section titled “endSession()”endSession(at?): void;Defined in: packages/core/src/usage-meter.ts:25
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
at |
number |
Returns
Section titled “Returns”void
snapshot()
Section titled “snapshot()”snapshot(): VoiceUsageSnapshot;Defined in: packages/core/src/usage-meter.ts:68
Returns
Section titled “Returns”startSession()
Section titled “startSession()”startSession(at?): void;Defined in: packages/core/src/usage-meter.ts:21
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
at |
number |
Returns
Section titled “Returns”void
VoiceError
Section titled “VoiceError”Defined in: packages/core/src/errors.ts:15
Typed error wrapper so a NormalizedVoiceError can flow through
throw/catch and Promise rejection while remaining structurally
inspectable.
Extends
Section titled “Extends”Error
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new VoiceError(error): VoiceError;Defined in: packages/core/src/errors.ts:28
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
error |
NormalizedVoiceError |
Normalized shape to wrap; retryable defaults from code when omitted. |
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructorProperties
Section titled “Properties”| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? |
public |
unknown |
The cause of the error. | Error.cause |
node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26 |
code |
readonly |
VoiceErrorCode |
Stable application error code. | - | packages/core/src/errors.ts:17 |
message |
public |
string |
Human-readable message suitable for logs (not always UI-safe). | NormalizedVoiceError.message Error.message |
node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077 |
name |
public |
string |
- | Error.name |
node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
provider? |
readonly |
string |
Provider name when the failure originated in an adapter. | - | packages/core/src/errors.ts:19 |
raw? |
readonly |
unknown |
Original thrown value or HTTP body, when available. | - | packages/core/src/errors.ts:23 |
retryable? |
readonly |
boolean |
Hint for UI retry; not enforced by the session. | - | packages/core/src/errors.ts:21 |
stack? |
public |
string |
- | Error.stack |
node_modules/.bun/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078 |
stackTraceLimit |
static |
number |
The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. |
Error.stackTraceLimit |
node_modules/.bun/@types+node@26.0.1/node_modules/@types/node/globals.d.ts:67 |
Methods
Section titled “Methods”toNormalized()
Section titled “toNormalized()”toNormalized(): NormalizedVoiceError;Defined in: packages/core/src/errors.ts:41
Flatten back to a plain NormalizedVoiceError for events / logs.
Returns
Section titled “Returns”captureStackTrace()
Section titled “captureStackTrace()”Call Signature
Section titled “Call Signature”static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/.bun/@types+node@26.0.1/node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns
a string representing the location in the code at which
Error.captureStackTrace() was called.
const myObject = {};Error.captureStackTrace(myObject);myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with
${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames
above constructorOpt, including constructorOpt, will be omitted from the
generated stack trace.
The constructorOpt argument is useful for hiding implementation
details of error generation from the user. For instance:
function a() { b();}
function b() { c();}
function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error;}
a();Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
targetObject |
object |
constructorOpt? |
Function |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Error.captureStackTraceCall Signature
Section titled “Call Signature”static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/.bun/bun-types@1.3.14/node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
targetObject |
object |
constructorOpt? |
Function |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Error.captureStackTraceisError()
Section titled “isError()”static isError(value): value is Error;Defined in: node_modules/.bun/bun-types@1.3.14/node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
unknown |
The value to check |
Returns
Section titled “Returns”value is Error
True if the value is an instance of Error, false otherwise
Inherited from
Section titled “Inherited from”Error.isErrorprepareStackTrace()
Section titled “prepareStackTrace()”static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/.bun/@types+node@26.0.1/node_modules/@types/node/globals.d.ts:55
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
err |
Error |
stackTraces |
CallSite[] |
Returns
Section titled “Returns”any
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Section titled “Inherited from”Error.prepareStackTraceVoiceSession
Section titled “VoiceSession”Defined in: packages/core/src/session.ts:69
Voice conversation session with automatic turn-taking and optional full-duplex barge-in.
Drives the loop: assistant speaks → listen → user speaks → ASR → LLM → assistant speaks → … It is platform-agnostic; audio I/O comes from the RuntimeAdapter and cloud capabilities from the providers, both supplied through VoiceSessionConfig.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new VoiceSession(config): VoiceSession;Defined in: packages/core/src/session.ts:107
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config |
VoiceSessionConfig |
Returns
Section titled “Returns”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get state(): VoiceSessionState;Defined in: packages/core/src/session.ts:156
Current finite-state machine value (see VoiceSessionState).
Returns
Section titled “Returns”Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose(): Promise<void>;Defined in: packages/core/src/session.ts:464
Tear everything down and drop all listeners. Safe to call multiple times.
Prefer VoiceSession.finish for a graceful end that emits finished.
Returns
Section titled “Returns”Promise<void>
endUserTurn()
Section titled “endUserTurn()”endUserTurn(): Promise<void>;Defined in: packages/core/src/session.ts:408
Manually end the current user turn (push-to-talk release, or a UI “done” button). Flushes the ASR session so its final result drives the loop.
Returns
Section titled “Returns”Promise<void>
finish()
Section titled “finish()”finish(reason?): Promise<void>;Defined in: packages/core/src/session.ts:456
End the session normally, emitting a final usage snapshot and finished.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
reason |
string |
'finished' |
Opaque reason string forwarded on the state transition. |
Returns
Section titled “Returns”Promise<void>
getTurns()
Section titled “getTurns()”getTurns(): VoiceTurn[];Defined in: packages/core/src/session.ts:200
Committed user/assistant turns recorded so far.
Returns
Section titled “Returns”getUsage()
Section titled “getUsage()”getUsage(): VoiceUsageSnapshot;Defined in: packages/core/src/session.ts:205
Aggregate usage meters for the active (or last) session.
Returns
Section titled “Returns”off<K>(event, cb): void;Defined in: packages/core/src/session.ts:192
Remove a previously registered handler.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends keyof VoiceSessionEventMap |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
K |
Event name from VoiceSessionEventMap. |
cb |
(payload) => void |
The same function reference passed to VoiceSession.on. |
Returns
Section titled “Returns”void
on<K>(event, cb): () => void;Defined in: packages/core/src/session.ts:166
Subscribe to a session event. Returns an unsubscribe function.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends keyof VoiceSessionEventMap |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
K |
Event name from VoiceSessionEventMap. |
cb |
(payload) => void |
Handler invoked with the typed payload for that event. |
Returns
Section titled “Returns”() => void
once()
Section titled “once()”once<K>(event, cb): () => void;Defined in: packages/core/src/session.ts:179
Subscribe for a single delivery, then auto-unsubscribe.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
K extends keyof VoiceSessionEventMap |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
K |
Event name from VoiceSessionEventMap. |
cb |
(payload) => void |
Handler invoked once with the typed payload. |
Returns
Section titled “Returns”() => void
pause()
Section titled “pause()”pause(): Promise<void>;Defined in: packages/core/src/session.ts:435
Pause the session: cancel in-flight replies, stop mic/ASR/playback, and
enter the paused state. No-op if the transition is illegal.
Returns
Section titled “Returns”Promise<void>
resume()
Section titled “resume()”resume(): Promise<void>;Defined in: packages/core/src/session.ts:446
Resume from paused by reopening the microphone for the next user turn.
Returns
Section titled “Returns”Promise<void>
start()
Section titled “start()”start(initialPrompt?): Promise<void>;Defined in: packages/core/src/session.ts:217
Begin the session. Speaks the initial assistant message (from the agent
plugin or initialPrompt) and then, unless disabled, opens the mic.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
initialPrompt? |
string |
Optional opening line when no agent plugin supplies one. |
Returns
Section titled “Returns”Promise<void>
startListening()
Section titled “startListening()”startListening(): Promise<void>;Defined in: packages/core/src/session.ts:246
Open the microphone and wire ASR for the next user turn.
Returns
Section titled “Returns”Promise<void>
submitUserText()
Section titled “submitUserText()”submitUserText(text): Promise<void>;Defined in: packages/core/src/session.ts:426
Inject user text directly, bypassing audio/ASR. Useful for text fallback and deterministic flows.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
text |
string |
Returns
Section titled “Returns”Promise<void>
Interfaces
Section titled “Interfaces”AddTurnInput
Section titled “AddTurnInput”Defined in: packages/core/src/transcript-buffer.ts:7
Input for TranscriptBuffer.add.
Prefer supplying id when the same id already appears on streaming events.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
audioUrl? |
string |
Optional playback URL when audio was recorded. | packages/core/src/transcript-buffer.ts:15 |
durationMs? |
number |
Explicit duration; otherwise derived from endedAt - startedAt when possible. |
packages/core/src/transcript-buffer.ts:21 |
endedAt? |
number |
Epoch millis when the turn ended. | packages/core/src/transcript-buffer.ts:19 |
id? |
string |
Supply a pre-generated id so event ids and turn ids stay in sync. | packages/core/src/transcript-buffer.ts:13 |
metadata? |
Record<string, unknown> |
Opaque app metadata attached to the turn. | packages/core/src/transcript-buffer.ts:23 |
role |
TurnRole |
Speaker role for the new turn. | packages/core/src/transcript-buffer.ts:9 |
startedAt? |
number |
Epoch millis when the turn started; defaults to now. | packages/core/src/transcript-buffer.ts:17 |
text |
string |
Final text content. | packages/core/src/transcript-buffer.ts:11 |
AgentSessionInput
Section titled “AgentSessionInput”Defined in: packages/core/src/types.ts:973
Arguments passed to VoiceAgentPlugin.shouldFinishSession and VoiceAgentPlugin.generateReport.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
turns |
VoiceTurn[] |
Completed turns in chronological order. | packages/core/src/types.ts:975 |
AgentTurnInput
Section titled “AgentTurnInput”Defined in: packages/core/src/types.ts:962
Arguments passed to VoiceAgentPlugin.generateNextAssistantMessage. Contains the full turn history plus the latest user utterance for convenience.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
lastUserText |
string |
Text of the most recent user turn. | packages/core/src/types.ts:966 |
turns |
VoiceTurn[] |
Completed turns in chronological order (includes the latest user turn). | packages/core/src/types.ts:964 |
ASRCapabilities
Section titled “ASRCapabilities”Defined in: packages/core/src/types.ts:219
Feature flags advertised by an ASRProvider. Core uses these to choose streaming vs batch capture and whether to expect partials / endpointing.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
batch |
boolean |
True when the provider expects complete turn audio (batch / rolling). | packages/core/src/types.ts:223 |
confidence? |
boolean |
Whether ASRResult.confidence may be populated. | packages/core/src/types.ts:229 |
endpointing? |
boolean |
Whether the provider can emit utterance-end / endpoint signals. | packages/core/src/types.ts:231 |
languages |
string[] |
BCP-47 language tags the provider claims to support (empty = unspecified). | packages/core/src/types.ts:233 |
partialResults |
boolean |
Whether provisional results are available via ASRSession.onPartial. | packages/core/src/types.ts:225 |
streaming |
boolean |
True when the provider accepts live chunked audio over a persistent session. | packages/core/src/types.ts:221 |
wordTimestamps? |
boolean |
Whether ASRResult.words may include timing. | packages/core/src/types.ts:227 |
ASRProvider
Section titled “ASRProvider”Defined in: packages/core/src/types.ts:333
Speech-to-text adapter. Implement this to plug a vendor ASR or a mock. Declare ASRCapabilities.streaming accurately so core chooses live chunks vs complete-turn audio.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
capabilities |
ASRCapabilities |
Declared feature flags used by the session when routing audio. | packages/core/src/types.ts:337 |
name |
string |
Stable provider id used in errors and usage (e.g. deepgram). |
packages/core/src/types.ts:335 |
Methods
Section titled “Methods”createSession()
Section titled “createSession()”createSession(options): Promise<ASRSession>;Defined in: packages/core/src/types.ts:343
Open a recognition session.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
ASRSessionOptions |
Language / encoding hints for this turn or call. |
Returns
Section titled “Returns”Promise<ASRSession>
ASRResult
Section titled “ASRResult”Defined in: packages/core/src/types.ts:267
A partial or final transcript emitted by an ASR session.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
confidence? |
number |
Provider confidence in [0, 1] when available. |
packages/core/src/types.ts:271 |
endMs? |
number |
Utterance end offset in milliseconds. | packages/core/src/types.ts:275 |
raw? |
unknown |
Raw provider payload for debugging. | packages/core/src/types.ts:279 |
startMs? |
number |
Utterance start offset in milliseconds. | packages/core/src/types.ts:273 |
text |
string |
Transcript text (accumulated for the current utterance). | packages/core/src/types.ts:269 |
words? |
ASRWord[] |
Optional word timestamps. | packages/core/src/types.ts:277 |
ASRSession
Section titled “ASRSession”Defined in: packages/core/src/types.ts:287
Live recognition session returned by ASRProvider.createSession. Core feeds audio via ASRSession.sendAudio and upserts UI from ASRSession.onPartial / ASRSession.onFinal.
Methods
Section titled “Methods”close()
Section titled “close()”close(): Promise<void>;Defined in: packages/core/src/types.ts:307
Tear down the underlying connection / resources.
Returns
Section titled “Returns”Promise<void>
onError()
Section titled “onError()”onError(cb): () => void;Defined in: packages/core/src/types.ts:325
Subscribe to provider failures.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
cb |
(error) => void |
Receives a NormalizedVoiceError; return value unsubscribes. |
Returns
Section titled “Returns”() => void
onFinal()
Section titled “onFinal()”onFinal(cb): () => void;Defined in: packages/core/src/types.ts:319
Subscribe to authoritative finals for the current utterance.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
cb |
(result) => void |
Invoked once per finalized segment; return value unsubscribes. |
Returns
Section titled “Returns”() => void
onPartial()
Section titled “onPartial()”onPartial(cb): () => void;Defined in: packages/core/src/types.ts:313
Subscribe to provisional transcripts.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
cb |
(result) => void |
Invoked on each partial; return value unsubscribes. |
Returns
Section titled “Returns”() => void
resetAudio()?
Section titled “resetAudio()?”optional resetAudio(): void | Promise<void>;Defined in: packages/core/src/types.ts:295
Drop buffered non-user audio while keeping the session connected.
Returns
Section titled “Returns”void | Promise<void>
sendAudio()
Section titled “sendAudio()”sendAudio(chunk): void | Promise<void>;Defined in: packages/core/src/types.ts:293
Push the next audio fragment to the provider.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
chunk |
ArrayBuffer |
Encoded or PCM bytes matching the session encoding. |
Returns
Section titled “Returns”void | Promise<void>
setInterimResultsEnabled()?
Section titled “setInterimResultsEnabled()?”optional setInterimResultsEnabled(enabled): void | Promise<void>;Defined in: packages/core/src/types.ts:303
Pause or resume provisional transcript work without affecting the final transcript. Batch-backed providers can use this to avoid paid rolling requests until voice activity confirms that the user is speaking.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
enabled |
boolean |
When false, skip rolling / interim work until re-enabled. |
Returns
Section titled “Returns”void | Promise<void>
stop()
Section titled “stop()”stop(): Promise<void>;Defined in: packages/core/src/types.ts:305
Signal end-of-audio and wait for a final transcript when applicable.
Returns
Section titled “Returns”Promise<void>
ASRSessionOptions
Section titled “ASRSessionOptions”Defined in: packages/core/src/types.ts:237
Options passed to ASRProvider.createSession.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
channels? |
number |
Channel count; typically 1 for voice. |
packages/core/src/types.ts:243 |
encoding? |
AudioEncoding |
Encoding of audio bytes sent via ASRSession.sendAudio. | packages/core/src/types.ts:245 |
endpointing? |
boolean |
Ask the provider to emit endpointing / utterance-end signals when available. | packages/core/src/types.ts:249 |
interimResults? |
boolean |
Request provisional partials when the provider supports them. | packages/core/src/types.ts:247 |
language? |
string |
Preferred recognition language (e.g. zh-CN). |
packages/core/src/types.ts:239 |
metadata? |
Record<string, unknown> |
Opaque metadata forwarded to the adapter (not interpreted by core). | packages/core/src/types.ts:251 |
sampleRate? |
number |
Input sample rate in Hz when the provider needs it (e.g. PCM streams). | packages/core/src/types.ts:241 |
ASRWord
Section titled “ASRWord”Defined in: packages/core/src/types.ts:255
Optional word-level timing from an ASR provider.
Properties
Section titled “Properties”AudioChunk
Section titled “AudioChunk”Defined in: packages/core/src/types.ts:681
Encoded or PCM audio fragment from AudioInputAdapter.
Properties
Section titled “Properties”AudioInputAdapter
Section titled “AudioInputAdapter”Defined in: packages/core/src/types.ts:703
Platform microphone capture injected via RuntimeAdapter.
Methods
Section titled “Methods”onChunk()
Section titled “onChunk()”onChunk(cb): () => void;Defined in: packages/core/src/types.ts:735
Subscribe to encoded / PCM chunks.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(chunk) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onError()
Section titled “onError()”onError(cb): () => void;Defined in: packages/core/src/types.ts:747
Subscribe to capture failures.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(error) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onVolume()?
Section titled “onVolume()?”optional onVolume(cb): () => void;Defined in: packages/core/src/types.ts:741
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
pause()?
Section titled “pause()?”optional pause(): Promise<void>;Defined in: packages/core/src/types.ts:727
Pause capture without tearing down permission / hardware (optional).
Returns
Section titled “Returns”Promise<void>
requestPermission()
Section titled “requestPermission()”requestPermission(): Promise<boolean>;Defined in: packages/core/src/types.ts:705
Prompt for mic permission; false should surface as a session error.
Returns
Section titled “Returns”Promise<boolean>
resume()?
Section titled “resume()?”optional resume(): Promise<void>;Defined in: packages/core/src/types.ts:729
Resume after pause.
Returns
Section titled “Returns”Promise<void>
resumeCapture()?
Section titled “resumeCapture()?”optional resumeCapture(options?): Promise<void>;Defined in: packages/core/src/types.ts:725
Resume encoded chunk capture after suspendCapture. Runtimes with a
barge-in pre-roll buffer may include it when includePreRoll is true.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options? |
{ includePreRoll?: boolean; } |
- |
options.includePreRoll? |
boolean |
Flush retained pre-roll into the next chunks. |
Returns
Section titled “Returns”Promise<void>
start()
Section titled “start()”start(options): Promise<void>;Defined in: packages/core/src/types.ts:711
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>
stop()
Section titled “stop()”stop(): Promise<void>;Defined in: packages/core/src/types.ts:713
Stop capture and release resources tied to the current start.
Returns
Section titled “Returns”Promise<void>
suspendCapture()?
Section titled “suspendCapture()?”optional suspendCapture(): Promise<void>;Defined in: packages/core/src/types.ts:718
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>
AudioInputOptions
Section titled “AudioInputOptions”Defined in: packages/core/src/types.ts:663
Capture hints passed to AudioInputAdapter.start. Runtimes may ignore unsupported fields (e.g. browser MediaRecorder encodings).
Properties
Section titled “Properties”AudioLLMAudioChunk
Section titled “AudioLLMAudioChunk”Defined in: packages/core/src/types.ts:442
Streaming PCM fragment from an AudioLLMProvider.
Properties
Section titled “Properties”AudioLLMGenerateInput
Section titled “AudioLLMGenerateInput”Defined in: packages/core/src/types.ts:454
Input for AudioLLMProvider.generate.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
audio |
ArrayBuffer |
Complete audio for the current VAD-delimited user turn. | packages/core/src/types.ts:456 |
format |
AudioLLMInputFormat |
Container / codec of audio. |
packages/core/src/types.ts:458 |
maxTokens? |
number |
Soft cap on output tokens (often shared by audio + transcript). | packages/core/src/types.ts:466 |
messages |
LLMMessage[] |
Text history from completed earlier turns. | packages/core/src/types.ts:460 |
metadata? |
Record<string, unknown> |
Opaque metadata forwarded to the adapter. | packages/core/src/types.ts:468 |
onAudioChunk? |
(chunk) => void | Promise<void> |
Receives decoded output audio while the model response is still streaming. | packages/core/src/types.ts:472 |
onTranscriptDelta? |
(text) => void | Promise<void> |
Receives the model’s spoken transcript while output audio is streaming. | packages/core/src/types.ts:474 |
signal? |
AbortSignal |
Cancels an in-flight provider request when this turn is superseded. | packages/core/src/types.ts:470 |
system? |
string |
Optional system instruction for this request. | packages/core/src/types.ts:462 |
temperature? |
number |
Sampling temperature; provider default when omitted. | packages/core/src/types.ts:464 |
AudioLLMGenerateOutput
Section titled “AudioLLMGenerateOutput”Defined in: packages/core/src/types.ts:478
Completed reply from AudioLLMProvider.generate.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
audioBuffer |
ArrayBuffer |
Full assistant audio buffer (may be empty if only streamed via callbacks). | packages/core/src/types.ts:482 |
mimeType |
string |
MIME type of audioBuffer. |
packages/core/src/types.ts:484 |
raw? |
unknown |
Provider timing/cost metadata, when available. | packages/core/src/types.ts:488 |
text |
string |
Transcript of the generated assistant audio. | packages/core/src/types.ts:480 |
usage? |
LLMUsage |
Token usage when reported. | packages/core/src/types.ts:486 |
AudioLLMProvider
Section titled “AudioLLMProvider”Defined in: packages/core/src/types.ts:495
A single model that consumes user audio and directly generates speech
(used when VoiceSessionConfig.pipeline is audio_llm).
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
name |
string |
Stable provider id used in errors and usage. | packages/core/src/types.ts:497 |
Methods
Section titled “Methods”generate()
Section titled “generate()”generate(input): Promise<AudioLLMGenerateOutput>;Defined in: packages/core/src/types.ts:503
Run one audio-in / audio-out turn.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
AudioLLMGenerateInput |
Completed user audio plus history and stream callbacks. |
Returns
Section titled “Returns”Promise<AudioLLMGenerateOutput>
AudioOutputAdapter
Section titled “AudioOutputAdapter”Defined in: packages/core/src/types.ts:795
Platform speaker / playback side injected via RuntimeAdapter.audioOutput. Supports one-shot AudioOutputAdapter.play and optional gapless AudioOutputAdapter.startPcmStream for streaming TTS / audio LLMs.
Methods
Section titled “Methods”onEnd()
Section titled “onEnd()”onEnd(cb): () => void;Defined in: packages/core/src/types.ts:835
Subscribe to playback end (natural finish or stop).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
() => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onError()
Section titled “onError()”onError(cb): () => void;Defined in: packages/core/src/types.ts:841
Subscribe to playback failures.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(error) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onStart()
Section titled “onStart()”onStart(cb): () => void;Defined in: packages/core/src/types.ts:829
Subscribe to playback start.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
() => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onVolume()?
Section titled “onVolume()?”optional onVolume(cb): () => void;Defined in: packages/core/src/types.ts:823
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
pause()?
Section titled “pause()?”optional pause(): Promise<void>;Defined in: packages/core/src/types.ts:814
Pause playback without discarding the current utterance (optional).
Returns
Section titled “Returns”Promise<void>
play()
Section titled “play()”play(input): Promise<void>;Defined in: packages/core/src/types.ts:803
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>
resume()?
Section titled “resume()?”optional resume(): Promise<void>;Defined in: packages/core/src/types.ts:816
Resume after AudioOutputAdapter.pause.
Returns
Section titled “Returns”Promise<void>
startPcmStream()?
Section titled “startPcmStream()?”optional startPcmStream(options): Promise<AudioOutputStream>;Defined in: packages/core/src/types.ts:810
Begin incremental raw-PCM playback for low-latency speech streaming.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
PcmAudioStreamOptions |
Encoding, sample rate, and channel layout for subsequent writes. |
Returns
Section titled “Returns”Promise<AudioOutputStream>
An AudioOutputStream that must be close()d.
stop()
Section titled “stop()”stop(): Promise<void>;Defined in: packages/core/src/types.ts:812
Stop current playback and cancel any open PCM stream.
Returns
Section titled “Returns”Promise<void>
unlock()?
Section titled “unlock()?”optional unlock(): Promise<void>;Defined in: packages/core/src/types.ts:797
Prime browser autoplay permission from a direct user gesture.
Returns
Section titled “Returns”Promise<void>
AudioOutputStream
Section titled “AudioOutputStream”Defined in: packages/core/src/types.ts:779
Incremental PCM writer returned by AudioOutputAdapter.startPcmStream. Call AudioOutputStream.write for each contiguous block, then AudioOutputStream.close when the utterance ends.
Methods
Section titled “Methods”close()
Section titled “close()”close(): Promise<void>;Defined in: packages/core/src/types.ts:787
Signal end-of-stream and resolve after all queued audio has played.
Returns
Section titled “Returns”Promise<void>
write()
Section titled “write()”write(data): Promise<void>;Defined in: packages/core/src/types.ts:785
Queue another contiguous PCM block for playback.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data |
ArrayBuffer |
Interleaved PCM matching the stream’s encoding / rate. |
Returns
Section titled “Returns”Promise<void>
AudioPlaybackInput
Section titled “AudioPlaybackInput”Defined in: packages/core/src/types.ts:751
Input for one-shot AudioOutputAdapter.play.
Properties
Section titled “Properties”BargeInSpeechGateOptions
Section titled “BargeInSpeechGateOptions”Defined in: packages/core/src/playback-echo-filter.ts:30
Tuning knobs for BargeInSpeechGate. Raise thresholds to reduce false barge-in from knocks; lower them for quieter speech.
Properties
Section titled “Properties”CreateVoiceErrorOptions
Section titled “CreateVoiceErrorOptions”Defined in: packages/core/src/errors.ts:57
Optional metadata for createVoiceError.
Omitted fields get sensible defaults (retryable from known network/ASR codes).
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
provider? |
string |
Provider name when the failure originated in an adapter. | packages/core/src/errors.ts:59 |
raw? |
unknown |
Original thrown value or HTTP body, when available. | packages/core/src/errors.ts:63 |
retryable? |
boolean |
Override the default retryability for VoiceErrorCode. | packages/core/src/errors.ts:61 |
LLMGenerateInput
Section titled “LLMGenerateInput”Defined in: packages/core/src/types.ts:369
Input for LLMProvider.generate / LLMProvider.stream.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
maxTokens? |
number |
Soft cap on completion tokens. | packages/core/src/types.ts:377 |
messages |
LLMMessage[] |
Chronological chat history for the model. | packages/core/src/types.ts:373 |
metadata? |
Record<string, unknown> |
Opaque metadata forwarded to the adapter. | packages/core/src/types.ts:381 |
responseFormat? |
"text" | "json" |
Prefer plain text or structured JSON when the model supports it. | packages/core/src/types.ts:379 |
signal? |
AbortSignal |
Cancels an in-flight provider request when this turn is superseded. | packages/core/src/types.ts:383 |
system? |
string |
Optional system instruction for this request. | packages/core/src/types.ts:371 |
temperature? |
number |
Sampling temperature; provider default when omitted. | packages/core/src/types.ts:375 |
LLMGenerateOutput
Section titled “LLMGenerateOutput”Defined in: packages/core/src/types.ts:387
Non-streaming completion from LLMProvider.generate.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
json? |
unknown |
Parsed JSON when responseFormat was json. |
packages/core/src/types.ts:391 |
raw? |
unknown |
Raw provider payload for debugging. | packages/core/src/types.ts:395 |
text |
string |
Assistant reply text. | packages/core/src/types.ts:389 |
usage? |
LLMUsage |
Token usage when reported. | packages/core/src/types.ts:393 |
LLMMessage
Section titled “LLMMessage”Defined in: packages/core/src/types.ts:351
One chat message forwarded to an LLMProvider.
Properties
Section titled “Properties”LLMProvider
Section titled “LLMProvider”Defined in: packages/core/src/types.ts:414
Text LLM used by the classic asr_llm_tts pipeline.
Prefer implementing LLMProvider.stream so the UI can show incremental text.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
name |
string |
Stable provider id used in errors and usage. | packages/core/src/types.ts:416 |
Methods
Section titled “Methods”generate()
Section titled “generate()”generate(input): Promise<LLMGenerateOutput>;Defined in: packages/core/src/types.ts:422
Produce a complete reply for the current turn.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
LLMGenerateInput |
System prompt, history, and generation knobs. |
Returns
Section titled “Returns”Promise<LLMGenerateOutput>
stream()?
Section titled “stream()?”optional stream(input): AsyncIterable<LLMStreamChunk>;Defined in: packages/core/src/types.ts:428
Optional token stream used when available (lower time-to-first-text).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
LLMGenerateInput |
Same shape as LLMProvider.generate. |
Returns
Section titled “Returns”AsyncIterable<LLMStreamChunk>
LLMStreamChunk
Section titled “LLMStreamChunk”Defined in: packages/core/src/types.ts:399
One chunk from LLMProvider.stream.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
error? |
NormalizedVoiceError |
Normalized failure for error. |
packages/core/src/types.ts:407 |
text? |
string |
New text for text_delta. |
packages/core/src/types.ts:403 |
type |
"error" | "text_delta" | "usage" | "done" |
Chunk kind: text fragment, usage update, completion, or error. | packages/core/src/types.ts:401 |
usage? |
LLMUsage |
Usage snapshot for usage / done. |
packages/core/src/types.ts:405 |
LLMUsage
Section titled “LLMUsage”Defined in: packages/core/src/types.ts:359
Optional token usage reported by an LLM or Audio LLM provider.
Properties
Section titled “Properties”LoggerAdapter
Section titled “LoggerAdapter”Defined in: packages/core/src/types.ts:925
Optional structured logger injected via RuntimeAdapter.logger.
Methods
Section titled “Methods”debug()
Section titled “debug()”debug(...args): void;Defined in: packages/core/src/types.ts:927
Verbose diagnostics (disabled in production by default).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…args |
unknown[] |
Returns
Section titled “Returns”void
error()
Section titled “error()”error(...args): void;Defined in: packages/core/src/types.ts:933
Failures that typically surface as session errors.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…args |
unknown[] |
Returns
Section titled “Returns”void
info()
Section titled “info()”info(...args): void;Defined in: packages/core/src/types.ts:929
Informational lifecycle messages.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…args |
unknown[] |
Returns
Section titled “Returns”void
warn()
Section titled “warn()”warn(...args): void;Defined in: packages/core/src/types.ts:931
Recoverable anomalies.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…args |
unknown[] |
Returns
Section titled “Returns”void
MockASROptions
Section titled “MockASROptions”Defined in: packages/core/src/providers/mock.ts:26
Options for createMockASR. Use when wiring tests or the developer profile without a live STT backend.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
emitPartials? |
boolean |
Emit a partial (half-length) result before each final. Default true. | packages/core/src/providers/mock.ts:30 |
failWith? |
NormalizedVoiceError |
When set, the next sendAudio triggers this error instead of a result. |
packages/core/src/providers/mock.ts:32 |
transcripts |
string[] |
Scripted final transcripts, emitted one per sendAudio call. |
packages/core/src/providers/mock.ts:28 |
MockAudioInputOptions
Section titled “MockAudioInputOptions”Defined in: packages/core/src/providers/mock-runtime.ts:15
Options for MockAudioInput. Use when constructing a mock mic for tests without a real capture device.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
permission? |
boolean |
Permission result returned by requestPermission. Default true. |
packages/core/src/providers/mock-runtime.ts:17 |
MockAudioOutputOptions
Section titled “MockAudioOutputOptions”Defined in: packages/core/src/providers/mock-runtime.ts:92
Options for MockAudioOutput.
Use when tests need to control whether play auto-completes or fails.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
autoComplete? |
boolean |
Auto-fire start/end around play. Default true. |
packages/core/src/providers/mock-runtime.ts:94 |
failWith? |
NormalizedVoiceError |
When set, play rejects with this error. |
packages/core/src/providers/mock-runtime.ts:96 |
MockLLMOptions
Section titled “MockLLMOptions”Defined in: packages/core/src/providers/mock.ts:114
Options for createMockLLM. Use in tests or demos that need a deterministic text reply without a live LLM.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
failWith? |
NormalizedVoiceError |
When set, generate/stream reject with this error. |
packages/core/src/providers/mock.ts:123 |
reply? |
(input, callIndex) => string |
Reply generator. Receives the input and 0-based call index. Defaults to echoing the last user message. | packages/core/src/providers/mock.ts:119 |
usage? |
LLMUsage |
Token usage returned on every generate / stream completion. |
packages/core/src/providers/mock.ts:121 |
MockPronunciationOptions
Section titled “MockPronunciationOptions”Defined in: packages/core/src/providers/mock.ts:239
Options for createMockPronunciation. Use when pronunciation scoring is optional in tests but the provider slot must still be filled.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
failWith? |
NormalizedVoiceError |
When set, assess rejects with this error. |
packages/core/src/providers/mock.ts:243 |
score? |
number |
Overall / per-dimension score returned for every assessment. Default 80. | packages/core/src/providers/mock.ts:241 |
MockRuntime
Section titled “MockRuntime”Defined in: packages/core/src/providers/mock-runtime.ts:194
In-memory RuntimeAdapter with typed mock input/output adapters. Prefer createMockRuntime over constructing this shape by hand.
Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Type | Description | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|
audioInput |
MockAudioInput |
Controllable mock microphone. | RuntimeAdapter.audioInput |
- | packages/core/src/providers/mock-runtime.ts:196 |
audioOutput |
MockAudioOutput |
Controllable mock speaker. | RuntimeAdapter.audioOutput |
- | packages/core/src/providers/mock-runtime.ts:198 |
logger? |
LoggerAdapter |
Optional logger; core uses it sparingly. | - | RuntimeAdapter.logger |
packages/core/src/types.ts:951 |
network? |
NetworkAdapter |
Optional HTTP/WebSocket hooks for providers. | - | RuntimeAdapter.network |
packages/core/src/types.ts:947 |
storage? |
RuntimeStorageAdapter |
Optional persistence for caches. | - | RuntimeAdapter.storage |
packages/core/src/types.ts:949 |
MockRuntimeOptions
Section titled “MockRuntimeOptions”Defined in: packages/core/src/providers/mock-runtime.ts:183
Options for createMockRuntime. Forwards into MockAudioInput / MockAudioOutput constructors.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
input? |
MockAudioInputOptions |
Microphone mock options. See MockAudioInputOptions. | packages/core/src/providers/mock-runtime.ts:185 |
output? |
MockAudioOutputOptions |
Speaker mock options. See MockAudioOutputOptions. | packages/core/src/providers/mock-runtime.ts:187 |
MockTTSOptions
Section titled “MockTTSOptions”Defined in: packages/core/src/providers/mock.ts:189
Options for createMockTTS. Use when tests need a TTS adapter that returns synthetic audio bytes.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
durationMsPerChar? |
number |
Estimated playback duration in ms; defaults to 60ms per character. | packages/core/src/providers/mock.ts:191 |
failWith? |
NormalizedVoiceError |
When set, synthesize rejects with this error. |
packages/core/src/providers/mock.ts:193 |
NetworkAdapter
Section titled “NetworkAdapter”Defined in: packages/core/src/types.ts:889
Platform HTTP / WebSocket hooks used by providers that need them.
Methods
Section titled “Methods”createWebSocket()
Section titled “createWebSocket()”createWebSocket(url, protocols?): RuntimeWebSocket;Defined in: packages/core/src/types.ts:903
Open a WebSocket for streaming providers.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
url |
string |
WebSocket URL. |
protocols? |
string | string[] |
Optional subprotocol(s). |
Returns
Section titled “Returns”fetch()
Section titled “fetch()”fetch(input, init?): Promise<Response>;Defined in: packages/core/src/types.ts:896
Fetch implementation (browser fetch, undici, etc.).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
RequestInfo | URL |
Request URL or RequestInfo. |
init? |
RequestInit |
Optional fetch init. |
Returns
Section titled “Returns”Promise<Response>
NormalizedVoiceError
Section titled “NormalizedVoiceError”Defined in: packages/core/src/types.ts:69
Vendor-neutral error shape used by session events, providers, and VoiceError.
Construct via createVoiceError when possible so retryable defaults apply.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
code |
VoiceErrorCode |
Stable application error code. | packages/core/src/types.ts:71 |
message |
string |
Human-readable message suitable for logs (not always UI-safe). | packages/core/src/types.ts:73 |
provider? |
string |
Provider name when the failure originated in an adapter. | packages/core/src/types.ts:75 |
raw? |
unknown |
Original thrown value or HTTP body, when available. | packages/core/src/types.ts:79 |
retryable? |
boolean |
Hint for UI retry; not enforced by the session. | packages/core/src/types.ts:77 |
PcmAudioStreamOptions
Section titled “PcmAudioStreamOptions”Defined in: packages/core/src/types.ts:763
Options for AudioOutputAdapter.startPcmStream.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”PlaybackEchoFilterOptions
Section titled “PlaybackEchoFilterOptions”Defined in: packages/core/src/playback-echo-filter.ts:6
Tuning knobs for PlaybackEchoFilter. Use when default delay/warmup margins are too aggressive or too timid for a given device or speaker layout.
Properties
Section titled “Properties”PronunciationInput
Section titled “PronunciationInput”Defined in: packages/core/src/types.ts:600
Input for optional pronunciation / speaking assessment providers.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
audio? |
string | ArrayBuffer |
Raw audio bytes or a remote URL the provider can fetch. | packages/core/src/types.ts:602 |
durationMs? |
number |
Spoken duration in milliseconds when known. | packages/core/src/types.ts:610 |
language? |
string |
BCP-47 language for scoring models. | packages/core/src/types.ts:608 |
metadata? |
Record<string, unknown> |
Opaque adapter metadata. | packages/core/src/types.ts:614 |
referenceText? |
string |
Expected reference sentence when scoring against a prompt. | packages/core/src/types.ts:606 |
transcript |
string |
Recognized or user-submitted spoken text. | packages/core/src/types.ts:604 |
words? |
ASRWord[] |
Optional word timings from ASR to align scoring. | packages/core/src/types.ts:612 |
PronunciationProvider
Section titled “PronunciationProvider”Defined in: packages/core/src/types.ts:643
Optional adapter for scoring user pronunciation after a turn.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
name |
string |
Stable provider id used in errors and usage. | packages/core/src/types.ts:645 |
Methods
Section titled “Methods”assess()
Section titled “assess()”assess(input): Promise<PronunciationResult>;Defined in: packages/core/src/types.ts:652
Score a spoken utterance.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
PronunciationInput |
Audio and/or transcript to assess. |
Returns
Section titled “Returns”Promise<PronunciationResult>
Normalized PronunciationResult.
PronunciationResult
Section titled “PronunciationResult”Defined in: packages/core/src/types.ts:618
Normalized scores from a PronunciationProvider.
Properties
Section titled “Properties”ProviderProfile
Section titled “ProviderProfile”Defined in: packages/core/src/provider-router.ts:23
Provider-id recipe for one product mode. String values are registry keys resolved by ProviderRegistry into concrete adapters — never vendor SDK imports.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
asr |
string |
Registered ASR provider id. | packages/core/src/provider-router.ts:27 |
llmConversation |
string |
Registered LLM used for conversational turns. | packages/core/src/provider-router.ts:29 |
llmScoring? |
string |
Optional LLM used for scoring / reports; defaults to conversation LLM. | packages/core/src/provider-router.ts:31 |
name |
string |
Stable profile id (usually matches a ProviderProfileName). | packages/core/src/provider-router.ts:25 |
pronunciation? |
string |
Optional pronunciation / assessment provider id. | packages/core/src/provider-router.ts:35 |
tts? |
string |
Optional TTS provider id for the classic pipeline. | packages/core/src/provider-router.ts:33 |
ProviderRoutingContext
Section titled “ProviderRoutingContext”Defined in: packages/core/src/provider-router.ts:97
Inputs for resolveProfile. Prefer setting ProviderRoutingContext.region and ProviderRoutingContext.plan; latency/cost are forward-compatible knobs.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
costPreference? |
"low" | "balanced" | "quality" |
Prefer lower cost when a future policy uses it. | packages/core/src/provider-router.ts:107 |
feature? |
ProviderFeature |
Feature being selected (optional; ignored by the default policy). | packages/core/src/provider-router.ts:103 |
latencyPreference? |
"low" | "balanced" | "quality" |
Prefer lower latency when a future policy uses it. | packages/core/src/provider-router.ts:105 |
plan? |
ProviderPlan |
Subscription tier. | packages/core/src/provider-router.ts:101 |
region? |
ProviderRegion |
User / deployment region. | packages/core/src/provider-router.ts:99 |
RegisteredProviders
Section titled “RegisteredProviders”Defined in: packages/core/src/provider-router.ts:123
Initial map of provider ids → instances for the ProviderRegistry constructor. Keys must match those used in ProviderProfile.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
asr? |
Record<string, ASRProvider> |
ASR adapters keyed by profile asr id. |
packages/core/src/provider-router.ts:125 |
llm? |
Record<string, LLMProvider> |
LLM adapters keyed by conversation / scoring ids. | packages/core/src/provider-router.ts:127 |
pronunciation? |
Record<string, PronunciationProvider> |
Pronunciation adapters keyed by profile pronunciation id. |
packages/core/src/provider-router.ts:131 |
tts? |
Record<string, TTSProvider> |
TTS adapters keyed by profile tts id. |
packages/core/src/provider-router.ts:129 |
ResolvedProviders
Section titled “ResolvedProviders”Defined in: packages/core/src/provider-router.ts:138
Concrete provider bundle produced by ProviderRegistry.resolve. Ready to pass into a import(‘./session’).VoiceSession config.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
asr |
ASRProvider |
Live ASR for the classic pipeline. | packages/core/src/provider-router.ts:140 |
llm |
LLMProvider |
Conversational text LLM. | packages/core/src/provider-router.ts:142 |
llmScoring |
LLMProvider |
LLM used for scoring / reports (may alias ResolvedProviders.llm). | packages/core/src/provider-router.ts:144 |
pronunciation? |
PronunciationProvider |
Optional pronunciation assessor. | packages/core/src/provider-router.ts:148 |
tts? |
TTSProvider |
Optional TTS when synthesizing speech separately. | packages/core/src/provider-router.ts:146 |
RuntimeAdapter
Section titled “RuntimeAdapter”Defined in: packages/core/src/types.ts:941
Platform boundary: microphone + playback (+ optional network/storage/logger).
Created by @ottervoice/runtime-web, runtime-react-native, runtime-node,
or createMockRuntime.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
audioInput |
AudioInputAdapter |
Microphone / capture side. | packages/core/src/types.ts:943 |
audioOutput |
AudioOutputAdapter |
Speaker / playback side. | packages/core/src/types.ts:945 |
logger? |
LoggerAdapter |
Optional logger; core uses it sparingly. | packages/core/src/types.ts:951 |
network? |
NetworkAdapter |
Optional HTTP/WebSocket hooks for providers. | packages/core/src/types.ts:947 |
storage? |
RuntimeStorageAdapter |
Optional persistence for caches. | packages/core/src/types.ts:949 |
RuntimeStorageAdapter
Section titled “RuntimeStorageAdapter”Defined in: packages/core/src/types.ts:907
Optional key/value store for adapter caches (not required by core).
Methods
Section titled “Methods”get(key): Promise<string | null>;Defined in: packages/core/src/types.ts:912
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
key |
string |
Storage key. |
Returns
Section titled “Returns”Promise<string | null>
Stored string or null when missing.
remove()
Section titled “remove()”remove(key): Promise<void>;Defined in: packages/core/src/types.ts:921
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
key |
string |
Storage key to delete. |
Returns
Section titled “Returns”Promise<void>
set(key, value): Promise<void>;Defined in: packages/core/src/types.ts:917
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
key |
string |
Storage key. |
value |
string |
Value to persist. |
Returns
Section titled “Returns”Promise<void>
RuntimeWebSocket
Section titled “RuntimeWebSocket”Defined in: packages/core/src/types.ts:848
Minimal WebSocket surface returned by NetworkAdapter.createWebSocket.
Keeps providers free of DOM/ws type coupling; subscribe via the on* helpers.
Methods
Section titled “Methods”close()
Section titled “close()”close(code?, reason?): void;Defined in: packages/core/src/types.ts:861
Close the socket.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
code? |
number |
Optional WebSocket close code. |
reason? |
string |
Optional human-readable reason. |
Returns
Section titled “Returns”void
onClose()
Section titled “onClose()”onClose(cb): () => void;Defined in: packages/core/src/types.ts:885
Subscribe to close.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
() => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onError()
Section titled “onError()”onError(cb): () => void;Defined in: packages/core/src/types.ts:879
Subscribe to socket-level errors.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(error) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onMessage()
Section titled “onMessage()”onMessage(cb): () => void;Defined in: packages/core/src/types.ts:873
Subscribe to inbound frames.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
(data) => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
onOpen()
Section titled “onOpen()”onOpen(cb): () => void;Defined in: packages/core/src/types.ts:867
Subscribe to the open event.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
cb |
() => void |
Returns
Section titled “Returns”Unsubscribe function.
() => void
send()
Section titled “send()”send(data): void;Defined in: packages/core/src/types.ts:854
Send a text or binary frame.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data |
string | ArrayBuffer |
UTF-8 text or binary payload. |
Returns
Section titled “Returns”void
TTSCapabilities
Section titled “TTSCapabilities”Defined in: packages/core/src/types.ts:531
Declared voices / formats for a TTSProvider.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
formats |
TTSFormat[] |
Output formats the adapter can produce. | packages/core/src/types.ts:537 |
languages |
string[] |
BCP-47 language tags supported for synthesis. | packages/core/src/types.ts:539 |
streaming |
boolean |
Whether the provider can stream partial audio (future use). | packages/core/src/types.ts:533 |
voices |
TTSVoice[] |
Voices advertised by the adapter. | packages/core/src/types.ts:535 |
TTSInput
Section titled “TTSInput”Defined in: packages/core/src/types.ts:543
Input for TTSProvider.synthesize.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
cacheKey? |
string |
Optional cache key for adapters that memoize synthesis. | packages/core/src/types.ts:557 |
format? |
TTSFormat |
Preferred output container / codec. | packages/core/src/types.ts:555 |
language? |
string |
Preferred language for multilingual voices. | packages/core/src/types.ts:549 |
metadata? |
Record<string, unknown> |
Opaque metadata forwarded to the adapter. | packages/core/src/types.ts:559 |
pitch? |
number |
Pitch adjustment (provider-specific scale). | packages/core/src/types.ts:553 |
speed? |
number |
Speaking rate multiplier (provider-specific scale). | packages/core/src/types.ts:551 |
text |
string |
Text to speak. | packages/core/src/types.ts:545 |
voice? |
string |
Provider voice id / name. | packages/core/src/types.ts:547 |
TTSOutput
Section titled “TTSOutput”Defined in: packages/core/src/types.ts:563
Audio returned by TTSProvider.synthesize.
Properties
Section titled “Properties”TTSProvider
Section titled “TTSProvider”Defined in: packages/core/src/types.ts:582
Text-to-speech adapter for the classic asr_llm_tts pipeline.
Required when VoiceSessionConfig.pipeline is asr_llm_tts.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
capabilities |
TTSCapabilities |
Declared voices and formats. | packages/core/src/types.ts:586 |
name |
string |
Stable provider id used in errors and usage. | packages/core/src/types.ts:584 |
Methods
Section titled “Methods”synthesize()
Section titled “synthesize()”synthesize(input): Promise<TTSOutput>;Defined in: packages/core/src/types.ts:592
Synthesize speech for the given text.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
TTSInput |
Text plus optional voice / format hints. |
Returns
Section titled “Returns”Promise<TTSOutput>
TTSVoice
Section titled “TTSVoice”Defined in: packages/core/src/types.ts:517
A synthesizable voice advertised by a TTSProvider.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
gender? |
"male" | "female" | "neutral" |
Optional gender metadata for filtering. | packages/core/src/types.ts:525 |
id |
string |
Stable voice id passed to TTSInput.voice. | packages/core/src/types.ts:519 |
language |
string |
Primary BCP-47 language for this voice. | packages/core/src/types.ts:523 |
name |
string |
Human-readable display name for UI pickers. | packages/core/src/types.ts:521 |
style? |
string[] |
Optional style tags (e.g. cheerful, news). |
packages/core/src/types.ts:527 |
TurnDetectionConfig
Section titled “TurnDetectionConfig”Defined in: packages/core/src/types.ts:1027
Voice-activity and endpointing knobs while listening for the user. Passed via VoiceSessionConfig.turnDetection; pair with VoiceSessionConfig.interruptionDetection for barge-in thresholds.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
maxTurnMs? |
number |
Hard cap on a single user turn length. | packages/core/src/types.ts:1035 |
minSpeechMs? |
number |
Minimum voiced time before speech is considered started. | packages/core/src/types.ts:1031 |
silenceTimeoutMs? |
number |
Quiet time after speech before the turn is closed. | packages/core/src/types.ts:1033 |
strategy |
TurnDetectionStrategy |
How end-of-utterance is decided. | packages/core/src/types.ts:1029 |
volumeThreshold? |
number |
RMS threshold when using volume-based strategies (≈0–1). | packages/core/src/types.ts:1037 |
VoiceAgentPlugin
Section titled “VoiceAgentPlugin”Defined in: packages/core/src/types.ts:982
Optional higher-level dialog controller (opening line, next line, finish rule). When set, the session may call these instead of / in addition to a raw LLM.
Methods
Section titled “Methods”generateNextAssistantMessage()
Section titled “generateNextAssistantMessage()”generateNextAssistantMessage(input): Promise<string>;Defined in: packages/core/src/types.ts:990
Produce the next assistant line after a completed user turn.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
AgentTurnInput |
Full history plus the latest user text. |
Returns
Section titled “Returns”Promise<string>
generateReport()?
Section titled “generateReport()?”optional generateReport(input): Promise<unknown>;Defined in: packages/core/src/types.ts:1002
Optional end-of-session artifact (scores, summary, etc.).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
AgentSessionInput |
Full turn history. |
Returns
Section titled “Returns”Promise<unknown>
getInitialAssistantMessage()
Section titled “getInitialAssistantMessage()”getInitialAssistantMessage(): Promise<string>;Defined in: packages/core/src/types.ts:984
Spoken (or displayed) opening line after VoiceSession.start.
Returns
Section titled “Returns”Promise<string>
shouldFinishSession()
Section titled “shouldFinishSession()”shouldFinishSession(input): boolean;Defined in: packages/core/src/types.ts:996
Return true to end the session after the latest turn.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input |
AgentSessionInput |
Full turn history. |
Returns
Section titled “Returns”boolean
VoiceSessionConfig
Section titled “VoiceSessionConfig”Defined in: packages/core/src/types.ts:1085
Top-level configuration for createVoiceSession / VoiceSession. Create at the application composition root; keep provider credentials out of UI code.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
agent? |
VoiceAgentPlugin |
Optional higher-level dialog plugin (opening line, next line, finish rule). | packages/core/src/types.ts:1129 |
asrPartial? |
boolean |
Emit provisional asr_partial results. Defaults to true. Disabling this does not affect the authoritative asr_final transcript. |
packages/core/src/types.ts:1096 |
audioLlmMaxTokens? |
number |
Cap native audio LLM output tokens (audio + transcript share this budget). Omit to use the model’s default maximum — required for long-form speech. | packages/core/src/types.ts:1103 |
audioLlmStartTiming? |
"after_audio" | "after_asr_final" |
Choose when an Audio LLM request begins. after_audio starts as soon as VAD finalizes the user audio and runs caption ASR in parallel for the lowest response latency. after_asr_final waits for the authoritative caption first, avoiding provider spend when a natural pause is superseded. Defaults to after_asr_final. |
packages/core/src/types.ts:1111 |
audioLlmSystemPrompt? |
string |
Optional system instruction forwarded to a native audio LLM. | packages/core/src/types.ts:1098 |
generateId? |
() => string |
Override id generation (useful for deterministic tests). | packages/core/src/types.ts:1141 |
interruptionDetection? |
Partial<Omit<TurnDetectionConfig, "strategy">> |
Stricter VAD used only while assistant audio is playing. Keeping this separate prevents taps and playback echo from triggering barge-in without making normal listening less sensitive. | packages/core/src/types.ts:1137 |
language? |
string |
Preferred ASR language; omit to let compatible providers auto-detect. | packages/core/src/types.ts:1113 |
metadata? |
Record<string, unknown> |
Opaque app metadata (not interpreted by core). | packages/core/src/types.ts:1145 |
mode |
VoiceSessionMode |
Duplex / PTT mode. See VoiceSessionMode. | packages/core/src/types.ts:1089 |
now? |
() => number |
Override the clock (useful for deterministic tests). | packages/core/src/types.ts:1143 |
pipeline? |
"asr_llm_tts" | "audio_llm" |
Defaults to the classic ASR -> LLM -> TTS cascade. | packages/core/src/types.ts:1091 |
policy? |
VoiceSessionPolicy |
Session-level timers and barge-in recovery knobs. | packages/core/src/types.ts:1139 |
providers |
{ asr: ASRProvider; audioLlm?: AudioLLMProvider; llm: LLMProvider; pronunciation?: PronunciationProvider; tts?: TTSProvider; } |
- | packages/core/src/types.ts:1116 |
providers.asr |
ASRProvider |
Speech-to-text provider (required for live captions / classic pipeline). | packages/core/src/types.ts:1118 |
providers.audioLlm? |
AudioLLMProvider |
Required when pipeline is audio_llm; ASR supplies captions while request timing follows VoiceSessionConfig.audioLlmStartTiming. |
packages/core/src/types.ts:1124 |
providers.llm |
LLMProvider |
Text LLM used by asr_llm_tts (and optional agents). |
packages/core/src/types.ts:1120 |
providers.pronunciation? |
PronunciationProvider |
Optional pronunciation scoring after a user turn. | packages/core/src/types.ts:1126 |
providers.tts? |
TTSProvider |
Text-to-speech; required when pipeline is asr_llm_tts. |
packages/core/src/types.ts:1122 |
runtime |
RuntimeAdapter |
Platform audio (and optional network/storage/logger) adapter. | packages/core/src/types.ts:1115 |
turnDetection? |
TurnDetectionConfig |
VAD / endpointing while listening for the user. | packages/core/src/types.ts:1131 |
VoiceSessionPolicy
Section titled “VoiceSessionPolicy”Defined in: packages/core/src/types.ts:1058
Session-level timers and barge-in recovery knobs.
Properties
Section titled “Properties”VoiceTurn
Section titled “VoiceTurn”Defined in: packages/core/src/types.ts:93
One conversation turn recorded by the session / TranscriptBuffer.
Emitted on turn / turn_end events and available via transcript APIs.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
audioUrl? |
string |
Optional local or remote playback URL when recorded. | packages/core/src/types.ts:101 |
durationMs? |
number |
Convenience duration (endedAt - startedAt) when known. |
packages/core/src/types.ts:107 |
endedAt? |
number |
Epoch millis when the turn ended. | packages/core/src/types.ts:105 |
id |
string |
Stable turn id shared with streaming events. | packages/core/src/types.ts:95 |
metadata? |
Record<string, unknown> |
Opaque app metadata attached to the turn. | packages/core/src/types.ts:109 |
role |
TurnRole |
Who spoke this turn. | packages/core/src/types.ts:97 |
startedAt |
number |
Epoch millis when the turn started. | packages/core/src/types.ts:103 |
text |
string |
Final transcript or assistant text for the turn. | packages/core/src/types.ts:99 |
VoiceUsageSnapshot
Section titled “VoiceUsageSnapshot”Defined in: packages/core/src/types.ts:116
Cumulative usage counters for a live VoiceSession. Emitted periodically / on finish for cost and latency dashboards.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
asrAudioMs |
number |
Audio milliseconds forwarded to ASR. | packages/core/src/types.ts:124 |
assistantSpeechChars |
number |
Assistant spoken character count (approx). | packages/core/src/types.ts:122 |
llmInputTokens? |
number |
Accumulated LLM prompt tokens when providers report usage. | packages/core/src/types.ts:128 |
llmOutputTokens? |
number |
Accumulated LLM completion tokens when providers report usage. | packages/core/src/types.ts:130 |
providerCosts? |
Record<string, number> |
Optional per-provider cost estimates in billable units. | packages/core/src/types.ts:132 |
sessionDurationMs |
number |
Wall time since VoiceSession.start. | packages/core/src/types.ts:118 |
ttsChars |
number |
Characters sent to TTS. | packages/core/src/types.ts:126 |
userSpeechMs |
number |
Accumulated user speech duration when runtimes report chunk durations. | packages/core/src/types.ts:120 |
Type Aliases
Section titled “Type Aliases”AudioEncoding
Section titled “AudioEncoding”type AudioEncoding = "pcm_s16le" | "opus" | "webm" | "wav" | "mp3";Defined in: packages/core/src/types.ts:212
Wire encoding of audio bytes sent to ASR / Audio LLM adapters. Runtimes stamp this on AudioChunk; providers may narrow further.
AudioLLMInputFormat
Section titled “AudioLLMInputFormat”type AudioLLMInputFormat = "webm" | "wav" | "mp3" | "opus";Defined in: packages/core/src/types.ts:439
Container / codec accepted by AudioLLMGenerateInput.format.
WebM/Opus often need a runtime prepareAudio step before OpenAI-style APIs.
ProviderFeature
Section titled “ProviderFeature”type ProviderFeature = "conversation" | "transcription" | "scoring" | "pronunciation";Defined in: packages/core/src/provider-router.ts:86
Feature being routed (reserved for finer policy; resolveProfile currently keys primarily on region / plan).
ProviderPlan
Section titled “ProviderPlan”type ProviderPlan = "free" | "basic" | "pro";Defined in: packages/core/src/provider-router.ts:81
Commercial plan hint for resolveProfile.
ProviderProfileName
Section titled “ProviderProfileName”type ProviderProfileName = "global_budget" | "global_pro" | "china_fallback" | "developer_test";Defined in: packages/core/src/provider-router.ts:13
Built-in named stacks in providerProfiles. Pass to ProviderRegistry.resolve or resolveProfile.
ProviderRegion
Section titled “ProviderRegion”type ProviderRegion = "global" | "china" | "unknown";Defined in: packages/core/src/provider-router.ts:79
Deployment region hint for resolveProfile.
TTSFormat
Section titled “TTSFormat”type TTSFormat = "mp3" | "wav" | "ogg" | "opus" | "pcm";Defined in: packages/core/src/types.ts:514
Output audio container requested from a TTSProvider. Passed via TTSInput.format and listed in TTSCapabilities.formats.
TurnDetectionStrategy
Section titled “TurnDetectionStrategy”type TurnDetectionStrategy = "volume" | "asr_endpointing" | "manual" | "hybrid";Defined in: packages/core/src/types.ts:1016
How end-of-utterance is decided while listening:
volume— local RMS VAD (TurnDetectionConfig.volumeThreshold)asr_endpointing— trust provider utterance-end signalsmanual— caller drives VoiceSession.endUserTurnhybrid— combine ASR speech confirmation / endpointing with local silence
TurnDetectorEvent
Section titled “TurnDetectorEvent”type TurnDetectorEvent = "speech_start" | "speech_end" | "max_turn";Defined in: packages/core/src/turn-detector.ts:39
Boundary event returned by TurnDetector.pushVolume when a threshold
is crossed (undefined when the sample does not change state).
TurnRole
Section titled “TurnRole”type TurnRole = "user" | "assistant" | "system";Defined in: packages/core/src/types.ts:87
Speaker role for a VoiceTurn in the transcript.
VoiceErrorCode
Section titled “VoiceErrorCode”type VoiceErrorCode = | "permission_denied" | "microphone_unavailable" | "network_error" | "asr_connection_failed" | "asr_timeout" | "llm_failed" | "tts_failed" | "audio_playback_failed" | "provider_rate_limited" | "provider_quota_exceeded" | "unsupported_runtime" | "invalid_state" | "aborted" | "unknown";Defined in: packages/core/src/types.ts:49
Stable application error codes for voice sessions and providers. Prefer these over free-form strings when building NormalizedVoiceError or createVoiceError.
VoiceSessionEventMap
Section titled “VoiceSessionEventMap”type VoiceSessionEventMap = { asr_final: { confidence?: number; durationMs?: number; text: string; turnId: string; }; asr_partial: { confidence?: number; text: string; turnId: string; }; assistant_audio_end: { turnId: string; }; assistant_audio_start: { turnId: string; }; assistant_text: { text: string; turnId: string; }; assistant_text_delta: { delta: string; text: string; turnId: string; }; error: NormalizedVoiceError; finished: { turns: VoiceTurn[]; }; statechange: { from: VoiceSessionState; reason?: string; to: VoiceSessionState; }; turn: { turn: VoiceTurn; }; usage: VoiceUsageSnapshot; user_audio_end: { at: number; turnId: string; };};Defined in: packages/core/src/types.ts:143
Strongly typed event payloads for VoiceSession.
Subscribe with session.on('eventName', handler).
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
asr_final |
{ confidence?: number; durationMs?: number; text: string; turnId: string; } |
Authoritative user transcript for the turn. | packages/core/src/types.ts:158 |
asr_final.confidence? |
number |
- | packages/core/src/types.ts:161 |
asr_final.durationMs? |
number |
- | packages/core/src/types.ts:162 |
asr_final.text |
string |
- | packages/core/src/types.ts:159 |
asr_final.turnId |
string |
- | packages/core/src/types.ts:160 |
asr_partial |
{ confidence?: number; text: string; turnId: string; } |
Provisional ASR caption; upsert by turnId. |
packages/core/src/types.ts:151 |
asr_partial.confidence? |
number |
- | packages/core/src/types.ts:155 |
asr_partial.text |
string |
Accumulated provisional transcript. | packages/core/src/types.ts:153 |
asr_partial.turnId |
string |
- | packages/core/src/types.ts:154 |
assistant_audio_end |
{ turnId: string; } |
Assistant audio playback ended (completed or interrupted). | packages/core/src/types.ts:187 |
assistant_audio_end.turnId |
string |
- | packages/core/src/types.ts:188 |
assistant_audio_start |
{ turnId: string; } |
Assistant audio playback began for this turn. | packages/core/src/types.ts:183 |
assistant_audio_start.turnId |
string |
- | packages/core/src/types.ts:184 |
assistant_text |
{ text: string; turnId: string; } |
Final assistant text for the turn (may normalize streaming text). | packages/core/src/types.ts:170 |
assistant_text.text |
string |
- | packages/core/src/types.ts:171 |
assistant_text.turnId |
string |
- | packages/core/src/types.ts:172 |
assistant_text_delta |
{ delta: string; text: string; turnId: string; } |
Incremental assistant transcript emitted before assistant_text. |
packages/core/src/types.ts:175 |
assistant_text_delta.delta |
string |
Newly received text fragment. | packages/core/src/types.ts:177 |
assistant_text_delta.text |
string |
Complete assistant text accumulated for this turn so far. | packages/core/src/types.ts:179 |
assistant_text_delta.turnId |
string |
- | packages/core/src/types.ts:180 |
error |
NormalizedVoiceError |
Normalized failure; see NormalizedVoiceError. | packages/core/src/types.ts:201 |
finished |
{ turns: VoiceTurn[]; } |
Session completed gracefully; turns are the full history. | packages/core/src/types.ts:197 |
finished.turns |
VoiceTurn[] |
- | packages/core/src/types.ts:198 |
statechange |
{ from: VoiceSessionState; reason?: string; to: VoiceSessionState; } |
FSM transition with optional reason string. | packages/core/src/types.ts:145 |
statechange.from |
VoiceSessionState |
- | packages/core/src/types.ts:146 |
statechange.reason? |
string |
- | packages/core/src/types.ts:148 |
statechange.to |
VoiceSessionState |
- | packages/core/src/types.ts:147 |
turn |
{ turn: VoiceTurn; } |
A committed VoiceTurn was added to history. | packages/core/src/types.ts:191 |
turn.turn |
VoiceTurn |
- | packages/core/src/types.ts:192 |
usage |
VoiceUsageSnapshot |
Latest usage meters. | packages/core/src/types.ts:195 |
user_audio_end |
{ at: number; turnId: string; } |
VAD/manual boundary used as the response-latency start point. | packages/core/src/types.ts:165 |
user_audio_end.at |
number |
- | packages/core/src/types.ts:167 |
user_audio_end.turnId |
string |
- | packages/core/src/types.ts:166 |
VoiceSessionMode
Section titled “VoiceSessionMode”type VoiceSessionMode = "half_duplex" | "full_duplex" | "push_to_talk" | "streaming_transcript";Defined in: packages/core/src/types.ts:1051
Conversation duplex mode:
half_duplex— listen only after assistant playback finishesfull_duplex— keep listening (and allow barge-in) while speakingpush_to_talk— caller drives VoiceSession.endUserTurnstreaming_transcript— captions without the full reply loop
VoiceSessionState
Section titled “VoiceSessionState”type VoiceSessionState = | "idle" | "starting" | "assistant_speaking" | "listening" | "user_speaking" | "processing" | "scoring" | "paused" | "finished" | "error";Defined in: packages/core/src/types.ts:18
Finite-state machine states for VoiceSession.
Subscribe via the statechange event on VoiceSessionEventMap.
Variables
Section titled “Variables”DEFAULT_TURN_DETECTION
Section titled “DEFAULT_TURN_DETECTION”const DEFAULT_TURN_DETECTION: Required<TurnDetectionConfig>;Defined in: packages/core/src/turn-detector.ts:7
Default TurnDetectionConfig values used by resolveTurnDetection and TurnDetector when the session omits knobs.
providerProfiles
Section titled “providerProfiles”const providerProfiles: { china_fallback: { asr: string; llmConversation: string; llmScoring: string; name: string; pronunciation: string; tts: string; }; developer_test: { asr: string; llmConversation: string; llmScoring: string; name: string; pronunciation: string; tts: string; }; global_budget: { asr: string; llmConversation: string; llmScoring: string; name: string; pronunciation: string; tts: string; }; global_pro: { asr: string; llmConversation: string; llmScoring: string; name: string; pronunciation: string; tts: string; };};Defined in: packages/core/src/provider-router.ts:43
Built-in profiles. The string values are provider ids that a ProviderRegistry resolves into concrete provider instances — the router never imports a vendor SDK itself.
Type Declaration
Section titled “Type Declaration”Functions
Section titled “Functions”canTransition()
Section titled “canTransition()”function canTransition(from, to): boolean;Defined in: packages/core/src/state-machine.ts:65
Whether a direct transition from from → to is allowed by the session FSM.
Same-state transitions always return false.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
from |
VoiceSessionState |
Current state. |
to |
VoiceSessionState |
Desired next state. |
Returns
Section titled “Returns”boolean
createIdGenerator()
Section titled “createIdGenerator()”function createIdGenerator(prefix?): () => string;Defined in: packages/core/src/internal/ids.ts:5
Default monotonic-ish id generator. Avoids a crypto dependency so the core stays runtime-agnostic; sessions may inject their own via config.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
prefix |
string |
'id' |
Returns
Section titled “Returns”() => string
createMockASR()
Section titled “createMockASR()”function createMockASR(options): ASRProvider;Defined in: packages/core/src/providers/mock.ts:42
Deterministic ASR for tests and the developer profile. Each sendAudio
advances through transcripts; partial + final callbacks fire synchronously.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
MockASROptions |
Scripted transcripts and failure overrides. See MockASROptions. |
Returns
Section titled “Returns”An ASRProvider with name mock_asr.
createMockLLM()
Section titled “createMockLLM()”function createMockLLM(options?): LLMProvider;Defined in: packages/core/src/providers/mock.ts:141
Deterministic LLMProvider for tests and the developer profile.
generate returns a full string; stream yields word-sized text deltas.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
MockLLMOptions |
Reply, usage, and failure overrides. See MockLLMOptions. |
Returns
Section titled “Returns”An LLMProvider with name mock_llm.
createMockPronunciation()
Section titled “createMockPronunciation()”function createMockPronunciation(options?): PronunciationProvider;Defined in: packages/core/src/providers/mock.ts:254
Deterministic PronunciationProvider for tests and demos. Splits the transcript into words and assigns MockPronunciationOptions.score to each dimension.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
MockPronunciationOptions |
Score and failure overrides. See MockPronunciationOptions. |
Returns
Section titled “Returns”A PronunciationProvider with name mock_pronunciation.
createMockRuntime()
Section titled “createMockRuntime()”function createMockRuntime(options?): MockRuntime;Defined in: packages/core/src/providers/mock-runtime.ts:207
Assemble a fully in-memory RuntimeAdapter for tests and Node demos.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
MockRuntimeOptions |
Optional input/output mock knobs. See MockRuntimeOptions. |
Returns
Section titled “Returns”A MockRuntime with MockAudioInput and MockAudioOutput.
createMockTTS()
Section titled “createMockTTS()”function createMockTTS(options?): TTSProvider;Defined in: packages/core/src/providers/mock.ts:204
Deterministic TTSProvider for tests and demos. Encodes the input text as UTF-8 bytes and reports a duration from MockTTSOptions.durationMsPerChar.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
MockTTSOptions |
Duration and failure overrides. See MockTTSOptions. |
Returns
Section titled “Returns”A TTSProvider with name mock_tts.
createVoiceError()
Section titled “createVoiceError()”function createVoiceError( code, message, options?): NormalizedVoiceError;Defined in: packages/core/src/errors.ts:74
Build a NormalizedVoiceError with sensible retryable defaults.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
code |
VoiceErrorCode |
Stable VoiceErrorCode. |
message |
string |
Human-readable message for logs. |
options |
CreateVoiceErrorOptions |
Optional provider, retryable, and raw. See CreateVoiceErrorOptions. |
Returns
Section titled “Returns”A plain NormalizedVoiceError (not a thrown Error).
createVoiceSession()
Section titled “createVoiceSession()”function createVoiceSession(config): VoiceSession;Defined in: packages/core/src/session.ts:1703
Create a VoiceSession from a fully wired VoiceSessionConfig.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config |
VoiceSessionConfig |
Runtime adapter, providers, mode/pipeline, VAD, and policy. |
Returns
Section titled “Returns”A session that must be dispose()d when finished.
defaultNow()
Section titled “defaultNow()”function defaultNow(): number;Defined in: packages/core/src/internal/ids.ts:15
Default wall-clock used by sessions when no now override is injected.
Returns
Section titled “Returns”number
isTerminal()
Section titled “isTerminal()”function isTerminal(state): boolean;Defined in: packages/core/src/state-machine.ts:54
Whether state ends the session lifecycle (currently only finished).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
state |
VoiceSessionState |
Candidate VoiceSessionState. |
Returns
Section titled “Returns”boolean
normalizeError()
Section titled “normalizeError()”function normalizeError( value, fallbackCode?, provider?): NormalizedVoiceError;Defined in: packages/core/src/errors.ts:129
Coerce an arbitrary thrown value into a NormalizedVoiceError.
Used by the session and provider adapters so that every error surfaced to consumers shares one shape, regardless of where it originated.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
value |
unknown |
undefined |
Unknown thrown/rejected value. |
fallbackCode |
VoiceErrorCode |
'unknown' |
Code used when value has no recognized shape. Defaults to unknown. |
provider? |
string |
undefined |
Optional provider name attached when missing on value. |
Returns
Section titled “Returns”A NormalizedVoiceError suitable for session error events.
resolveProfile()
Section titled “resolveProfile()”function resolveProfile(ctx?): ProviderProfileName;Defined in: packages/core/src/provider-router.ts:111
Default policy: China routes to the fallback profile, Pro plans to pro.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ctx |
ProviderRoutingContext |
Returns
Section titled “Returns”resolveTurnDetection()
Section titled “resolveTurnDetection()”function resolveTurnDetection(config?): Required<TurnDetectionConfig>;Defined in: packages/core/src/turn-detector.ts:21
Merge a partial TurnDetectionConfig with DEFAULT_TURN_DETECTION.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
config? |
TurnDetectionConfig |
Optional overrides from import(‘./types’).VoiceSessionConfig.turnDetection. |
Returns
Section titled “Returns”Required<TurnDetectionConfig>
A fully populated config object (no missing fields).