UNPKG

@audin.ai/operator-sdk

Version:

Headless browser SDK for the Audin operator softphone — make and receive calls over the Audin operator WebSockets.

38 lines (37 loc) 2.08 kB
/** * AudioWorklet processor source for the operator softphone. * * IMPORTANT: an `AudioWorkletProcessor` runs in `AudioWorkletGlobalScope`, a * separate realm with NO module system and NO access to the SDK's other * modules. So everything it needs — μ-law codec and linear resampling — is * inlined here as a single self-contained source STRING. At runtime the SDK * turns this string into a `Blob` URL and `audioWorklet.addModule()`s it (see * `audio-client.ts`). Keeping it as an exported string (rather than a separate * `.js` asset) means the published bundle is a single file with no asset paths * to resolve — the right shape for an embeddable SDK. * * Two responsibilities, one processor instance: * * - CAPTURE: `process()` receives 128-frame Float32 blocks at the context * sample rate (typically 48 kHz). It buffers them, resamples down to * 8 kHz, μ-law-encodes, and `postMessage`s the resulting bytes to the main * thread, which forwards them on the audio WebSocket. * - PLAYBACK: the main thread `postMessage`s μ-law bytes received from the * WebSocket; the processor decodes them, upsamples 8 kHz → context rate, * and queues PCM that `process()` drains into the output. A small jitter * buffer smooths network arrival; underflow emits silence. * * The μ-law tables/logic here are byte-for-byte the same algorithm as * `src/codec/mulaw.ts` (kept in sync; the codec KAT guards the canonical * source). The inline copy exists only because the worklet realm can't import. */ /** Registered name of the worklet processor. */ export declare const OPERATOR_WORKLET_NAME = "audin-operator-audio-processor"; /** The processor source with its registered name substituted in. */ export declare const OPERATOR_WORKLET_SOURCE: string; /** * Build a Blob URL for the worklet module. The caller is responsible for * `URL.revokeObjectURL` after `addModule` resolves. Lives here (not in * audio-client) so the source string and its packaging stay together. */ export declare function createWorkletBlobUrl(): string;