AbsoluteJS

Runtime

Runtime configuration, session lifecycle, adapter contracts, media handling, reconnect, turn detection, and call-control hooks.

#Runtime Plugin

TS
import { Elysia } from "elysia";
import { createVoiceMemoryStore, voice } from "@absolutejs/voice";
import { deepgram } from "@absolutejs/voice-deepgram";
import { elevenlabs } from "@absolutejs/voice-elevenlabs";

const sessions = createVoiceMemoryStore();
const stt = deepgram({ apiKey: process.env.DEEPGRAM_API_KEY! });
const tts = elevenlabs({
	apiKey: process.env.ELEVENLABS_API_KEY!,
	voiceId: process.env.ELEVENLABS_VOICE_ID!
});

new Elysia()
	.use(voice({
		path: "/voice/realtime",
		session: sessions,
		stt,
		tts,
		greeting: "Hi, how can I help?",
		context: async ({ session }) => ({ sessionId: session.id }),
		onTurn: async (_session, turn, api) => {
			await api.say(`You said: ${turn.text}`);
		}
	}))
	.listen(3000);

console.log("voice websocket: ws://localhost:3000/voice/realtime");

#VoicePluginConfig Options

OptionMeaning
amdAnswering-machine detection driver for phone routes.
assistantModeResolved mode for realtime or split STT/TTS operation.
audioConditioningInput normalization, resampling, gating, and conditioning before STT.
bargeInMinPartialWordsMinimum partial transcript word count before cancelling assistant audio.
contextRoute/context resolver that builds app-specific session context.
costTelemetryCost attribution hooks for provider usage, call runtime, and turn-level accounting.
defaultSilentTurnAckSpoken acknowledgement for tool-only or otherwise silent assistant turns.
fillerDelayMsDelay before static latency filler is allowed to play.
fillerForContent-aware filler callback for short acknowledgements.
fillerForTimeoutMsTimeout for the content-aware filler callback.
fillerPhrasesStatic latency filler phrases spoken while the assistant response is pending.
greetingStatic or per-session first assistant message.
handoffTransfer, escalation, voicemail, no-answer, and completion hooks.
htmxEnables HTMX-oriented runtime attributes and responses.
languageStrategyFixed, auto-detect, or allow-switching language plan passed to providers.
lexiconStatic or context-resolved pronunciation/domain lexicon.
liveOpsRuntime control-state resolver for live operator actions.
loggerStructured runtime logger hook.
modalitiesAudio/text modality list passed to realtime providers.
monitorLive monitor registry binding for listen/control sockets.
noiseSuppressorOptional @absolutejs/media-compatible noise suppressor.
noiseSuppressorFormatAudioFormat expected by the noise suppressor.
onTurnRequired handler or assistant invocation for committed user turns.
opsOperations task, review, sink, webhook, and event integration.
pathRequired WebSocket path for the main voice runtime.
phraseHintsStatic or context-resolved STT phrase hints.
presetRuntime preset that fills common defaults for profile, language, turn detection, and carrier behavior.
profileSwitchGuardRuntime guard that audits, blocks, or auto-applies profile-switch recommendations.
prosodyTTS speed, pitch, emphasis, and style hints.
realtimeFull-duplex realtime adapter for unified input and output.
realtimeInputFormatAudioFormat for realtime input when it differs from the route default.
reconnectClient reconnect/resume behavior and continuity policy.
recordingRecording store and channel capture policy.
redactTranscript redactor applied before storage, traces, and sinks.
routeOnTurnTimeoutMsHard timeout for one onTurn call.
scenarioIdScenario identifier used by simulation, proof, and profiles.
semanticTurnDetectorModel or heuristic semantic turn detector for natural turn completion.
sessionRequired session store used to create, read, update, and persist VoiceSessionRecord values.
sessionMetadataAdditional metadata attached to the runtime session.
sttStreaming speech-to-text adapter used in split STT/TTS mode.
sttFallbackFallback STT policy for empty or low-confidence turns.
sttLifecycleProvider lifecycle hooks for STT session open, events, errors, and close.
traceTrace event store used by diagnostics, timelines, proofs, and ops.
ttsStreaming text-to-speech adapter used for assistant audio output.
turnDetectionSilence, vendor, manual, semantic, or hybrid end-of-turn policy.

#Adapter Contracts

STTAdapter.open() creates sessions that receive audio chunks and emit partial, final, endOfTurn, error, and close events.
TTSAdapter.open() creates sessions that receive text and emit audio, error, and close events; optional cancel() supports barge-in.
RealtimeAdapter.open() accepts audio or text and emits both transcript and audio events.
AudioFormat covers raw alaw, mulaw, and pcm_s16le with sample rate and mono/stereo channel count.
Language strategy supports fixed language, auto-detect with allow-list, or allow-switching.

#Example Routing

The example exposes two runtime paths: /voice/intake for cascaded STT+TTS and /voice/realtime for OpenAI Realtime. The frontend chooses the route with an engine query parameter and passes stable sessionId values so every audio frame belongs to one server-side session.

TS
export const getVoiceRoutePath = (
	scenarioId: "guided" | "general",
	provider?: "openai" | "anthropic" | "gemini" | "deterministic",
	routing?: "balanced" | "fastest" | "cheapest" | "quality",
	engine: "cascaded" | "openai-realtime" = "cascaded",
	profileId?: string,
	sessionId?: string
) => {
	const params = new URLSearchParams({ scenarioId });
	if (provider) params.set("provider", provider);
	if (routing) params.set("routing", routing);
	if (profileId) params.set("voiceProfile", profileId);
	if (sessionId) params.set("sessionId", sessionId);
	const path = engine === "openai-realtime" ? "/voice/realtime" : "/voice/intake";
	return `${path}?${params.toString()}`;
};

#Turns And Media

Turn detection can use vendor events, silence windows, manual end_turn messages, semantic VAD, or hybrids.
STT fallback can replay audio to secondary providers on empty or low-confidence turns.
Audio conditioning and noise suppression run before STT.
Barge-in cancels active assistant audio based on partial transcript thresholds.
Latency filler can be static phrases or content-aware fillerFor() acknowledgements with timeout fallback.
Recording captures assistant and/or user channels into a configured recording store.

#Follow one call through the runtime

Browser, phone, realtime, and synthetic callers converge on the same observable session contract.

  1. Connect
    Accept a WebSocket, telephony media stream, provider realtime session, or tester connection.
  2. Resolve
    Resolve tenant context, assistant, language, provider route, policy, and live-ops state.
  3. Understand
    Condition audio, detect turns, transcribe or stream realtime input, and invoke the assistant.
  4. Respond
    Execute tools, synthesize audio, support barge-in, or transfer through typed handoff policy.
  5. Prove
    Persist trace, cost, audit, recording, delivery, SLO, and proof evidence for the same session.

Continue toward an outcome

These playbooks show where this package fits, how to verify the combined system, and what changes before production.