omnivad 0.2.5 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +228 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -19
- package/dist/index.d.ts +152 -19
- package/dist/index.js +227 -50
- package/dist/index.js.map +1 -1
- package/dist/wasm/omnivad.cjs +1 -1
- package/dist/wasm/omnivad.js +1 -1
- package/dist/wasm/omnivad.wasm +0 -0
- package/package.json +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/wasm-binding.ts","../src/vad.ts","../src/stream-vad.ts","../src/aed.ts"],"names":["resp","SAMPLE_RATE","prepareAudio","int16ToNormalizedFloat32"],"mappings":";;;;AAQA,IAAI,OAAA,GAAmC,IAAA;AACvC,IAAI,QAAA,GAA6C,IAAA;AAajD,IAAM,kBAAA,GAAqB,EAAA;AAC3B,IAAM,yBAAyB,CAAA,GAAI,kBAAA;AACnC,IAAM,cAAA,GAAiB,CAAA;AACvB,IAAM,kBAAA,GAAqB,EAAA;AAC3B,IAAM,kBAAA,GAAqB,EAAA;AAGpB,IAAM,OAAA,GAAU;AAGhB,IAAM,gBAAA,GAAmB,wCAAwC,OAAO,CAAA,OAAA;AAGxE,IAAM,WAAA,GAAc;AAAA,EACzB,GAAA,EAAK,aAAA;AAAA,EACL,YAAA,EAAc,oBAAA;AAAA,EACd,GAAA,EAAK;AACP;AAQA,eAAsB,SACpB,WAAA,EAC2B;AAC3B,EAAA,IAAI,SAAS,OAAO,OAAA;AACpB,EAAA,IAAI,UAAU,OAAO,QAAA;AAErB,EAAA,QAAA,GAAA,CAAY,YAAY;AAEtB,IAAA,IAAI,aAAA;AACJ,IAAA,IAAI,iBAAA;AAEJ,IAAA,IAAI,OAAO,UAAA,CAAW,OAAA,EAAS,QAAA,EAAU,SAAS,QAAA,EAAU;AAE1D,MAAA,MAAM,EAAE,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AG,OAAA,GAAU,QAAQ,CAAA,GAAI,GAAG,CAAA,GAAI,GAAA;AAAA,EACpE;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * Low-level WASM binding for omnivad C API.\n * Loads the Emscripten module and provides typed wrappers.\n */\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype EmscriptenModule = any;\n\nlet _module: EmscriptenModule | null = null;\nlet _loading: Promise<EmscriptenModule> | null = null;\n\n/** Post-processing config matching C struct OmniPostConfig (7 x i32/float, 28 bytes) */\nexport interface PostConfig {\n threshold: number;\n smoothWindowSize: number;\n minSpeechFrames: number;\n minSilenceFrames: number;\n maxSpeechFrames: number;\n mergeSilenceFrames: number;\n extendSpeechFrames: number;\n}\n\nconst SIZEOF_POST_CONFIG = 28; // 7 * 4 bytes\nconst SIZEOF_AED_POST_CONFIG = 3 * SIZEOF_POST_CONFIG; // 84 bytes\nconst SIZEOF_SEGMENT = 8; // start(f32) + end(f32)\nconst SIZEOF_AED_SEGMENT = 16; // start(f32) + end(f32) + cls(i32) + confidence(f32)\nconst OMNI_ERR_NO_FRAMES = -7;\n\n/** Package version — used to construct default CDN URLs. */\nexport const VERSION = \"0.2.5\";\n\n/** Default CDN base for model files (jsDelivr serves npm package contents). */\nexport const DEFAULT_CDN_BASE = `https://cdn.jsdelivr.net/npm/omnivad@${VERSION}/models`;\n\n/** Model filenames keyed by type. */\nexport const MODEL_FILES = {\n vad: \"vad.omnivad\",\n \"stream-vad\": \"stream-vad.omnivad\",\n aed: \"aed.omnivad\",\n} as const;\n\nexport type ModelType = keyof typeof MODEL_FILES;\n\n/**\n * Initialize the WASM module. Call once before using any other functions.\n * Safe to call multiple times (returns cached module).\n */\nexport async function initWasm(\n wasmLocator?: (filename: string) => string,\n): Promise<EmscriptenModule> {\n if (_module) return _module;\n if (_loading) return _loading;\n\n _loading = (async () => {\n // Dynamic import of the Emscripten glue\n let createOmniVAD: (opts?: Record<string, unknown>) => Promise<EmscriptenModule>;\n let defaultLocateFile: ((filename: string) => string) | undefined;\n\n if (typeof globalThis.process?.versions?.node === \"string\") {\n // Node.js: use require for .cjs (avoids ESM detection issues)\n const { createRequire } = await import(/* webpackIgnore: true */ \"module\");\n const { dirname, join } = await import(\"path\");\n const req = createRequire(import.meta.url);\n const gluePath = req.resolve(\"../dist/wasm/omnivad.cjs\");\n const wasmDir = dirname(gluePath);\n createOmniVAD = req(gluePath);\n defaultLocateFile = (filename: string) => join(wasmDir, filename);\n } else {\n // Browser: dynamic import\n const glueUrl = new URL(\"../dist/wasm/omnivad.js\", import.meta.url);\n const mod = await import(/* webpackIgnore: true */ glueUrl.href);\n createOmniVAD = mod.default || mod;\n const wasmBaseUrl = new URL(\"./\", glueUrl);\n defaultLocateFile = (filename: string) => new URL(filename, wasmBaseUrl).toString();\n }\n\n const opts: Record<string, unknown> = {};\n const locateFile = wasmLocator ?? defaultLocateFile;\n if (locateFile) {\n opts.locateFile = (path: string) => locateFile(path);\n }\n\n _module = await createOmniVAD(opts);\n return _module!;\n })();\n\n return _loading;\n}\n\n/**\n * Load a model file as ArrayBuffer.\n *\n * Resolution order:\n * 1. modelData (ArrayBuffer) — use directly\n * 2. modelUrl (string/URL) — fetch from that URL\n * 3. Node.js — read from npm package's models/ directory\n * 4. Browser — fetch from jsDelivr CDN\n */\nexport async function loadModel(\n modelType: ModelType,\n modelUrl?: string | URL,\n modelData?: ArrayBuffer,\n): Promise<ArrayBuffer> {\n if (modelData) return modelData;\n\n if (modelUrl) {\n const resp = await fetch(modelUrl.toString());\n if (!resp.ok) throw new Error(`Failed to fetch model from ${modelUrl}: ${resp.status}`);\n return resp.arrayBuffer();\n }\n\n const filename = MODEL_FILES[modelType];\n\n if (typeof globalThis.process?.versions?.node === \"string\") {\n // Node.js: read from package's models/ directory\n const { createRequire } = await import(/* webpackIgnore: true */ \"module\");\n const { dirname, join } = await import(\"path\");\n const { readFile } = await import(\"fs/promises\");\n const req = createRequire(import.meta.url);\n const pkgDir = dirname(req.resolve(\"../package.json\"));\n const modelPath = join(pkgDir, \"models\", filename);\n const buf = await readFile(modelPath);\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n }\n\n // Browser: fetch from CDN\n const url = `${DEFAULT_CDN_BASE}/${filename}`;\n const resp = await fetch(url);\n if (!resp.ok) throw new Error(`Failed to fetch model from ${url}: ${resp.status}`);\n return resp.arrayBuffer();\n}\n\n/** Get the initialized WASM module (throws if not initialized) */\nexport function getModule(): EmscriptenModule {\n if (!_module) throw new Error(\"WASM not initialized. Call initWasm() first.\");\n return _module;\n}\n\nfunction readNativeError(M: EmscriptenModule, code: number): string {\n const msg = M.ccall(\"omni_error_string\", \"string\", [\"number\"], [code]);\n return msg ? `${msg} (${code})` : `error ${code}`;\n}\n\n/** Shared helper: call a C create function with out_error, throw on failure. */\nfunction createModel(\n M: EmscriptenModule,\n fnName: string,\n argTypes: string[],\n args: unknown[],\n label: string,\n): number {\n const errPtr = M._malloc(4);\n try {\n const handle = M.ccall(fnName, \"number\", [...argTypes, \"number\"], [...args, errPtr]);\n if (!handle) {\n const err = M.getValue(errPtr, \"i32\");\n throw new Error(`Failed to create ${label} model: ${readNativeError(M, err)}`);\n }\n return handle;\n } finally {\n M._free(errPtr);\n }\n}\n\n// -------------------------------------------------------------------------- //\n// Memory helpers //\n// -------------------------------------------------------------------------- //\n\n/** Copy Float32Array audio into WASM heap, returns pointer. Caller must free. */\nexport function copyAudioToHeap(M: EmscriptenModule, audio: Float32Array): number {\n const ptr = M._malloc(audio.length * 4);\n const heap = new Float32Array(M.HEAPU8.buffer, ptr, audio.length);\n heap.set(audio);\n return ptr;\n}\n\n/** Write PostConfig struct to WASM heap at ptr */\nexport function writePostConfig(M: EmscriptenModule, ptr: number, cfg: PostConfig): void {\n M.setValue(ptr + 0, cfg.threshold, \"float\");\n M.setValue(ptr + 4, cfg.smoothWindowSize, \"i32\");\n M.setValue(ptr + 8, cfg.minSpeechFrames, \"i32\");\n M.setValue(ptr + 12, cfg.minSilenceFrames, \"i32\");\n M.setValue(ptr + 16, cfg.maxSpeechFrames, \"i32\");\n M.setValue(ptr + 20, cfg.mergeSilenceFrames, \"i32\");\n M.setValue(ptr + 24, cfg.extendSpeechFrames, \"i32\");\n}\n\nexport const DEFAULT_VAD_CONFIG: PostConfig = {\n threshold: 0.4,\n smoothWindowSize: 5,\n minSpeechFrames: 20,\n minSilenceFrames: 20,\n maxSpeechFrames: 2000,\n mergeSilenceFrames: 0,\n extendSpeechFrames: 0,\n};\n\n// -------------------------------------------------------------------------- //\n// Non-stream VAD //\n// -------------------------------------------------------------------------- //\n\nexport function vadCreate(M: EmscriptenModule, modelBuffer: ArrayBuffer): number {\n const bytes = new Uint8Array(modelBuffer);\n const ptr = M._malloc(bytes.length);\n M.HEAPU8.set(bytes, ptr);\n try {\n return createModel(M, \"omni_vad_create_from_buffer\", [\"number\", \"number\"], [ptr, bytes.length], \"VAD\");\n } finally {\n M._free(ptr);\n }\n}\n\n/**\n * Audio format: two types only.\n * \"f32\" — float* in [-1.0, 1.0] (Web Audio API, soundfile, torch)\n * \"int16\" — int16_t* PCM (WAV files, microphones)\n */\nexport type AudioFormat = \"f32\" | \"int16\";\n\nfunction readSegments(M: EmscriptenModule, segPtrPtr: number, countPtr: number): Array<[number, number]> {\n const count = M.getValue(countPtr, \"i32\");\n const segPtr = M.getValue(segPtrPtr, \"i32\");\n const segments: Array<[number, number]> = [];\n for (let i = 0; i < count; i++) {\n const base = segPtr + i * SIZEOF_SEGMENT;\n segments.push([\n Math.round(M.getValue(base, \"float\") * 1000) / 1000,\n Math.round(M.getValue(base + 4, \"float\") * 1000) / 1000,\n ]);\n }\n if (segPtr) M._free(segPtr);\n return segments;\n}\n\nexport function vadDetect(\n M: EmscriptenModule,\n handle: number,\n audioPtr: number,\n numSamples: number,\n cfg: PostConfig,\n format: AudioFormat = \"f32\",\n): Array<[number, number]> {\n const cfgPtr = M._malloc(SIZEOF_POST_CONFIG);\n const segPtrPtr = M._malloc(4);\n const countPtr = M._malloc(4);\n const fn = format === \"int16\" ? \"omni_vad_detect_int16\" : \"omni_vad_detect\";\n\n try {\n writePostConfig(M, cfgPtr, cfg);\n const ret = M.ccall(\n fn,\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\", \"number\"],\n [handle, audioPtr, numSamples, cfgPtr, segPtrPtr, countPtr],\n );\n if (ret !== 0) throw new Error(`VAD detect failed: ${ret}`);\n return readSegments(M, segPtrPtr, countPtr);\n } finally {\n M._free(cfgPtr);\n M._free(segPtrPtr);\n M._free(countPtr);\n }\n}\n\nexport function vadDestroy(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_vad_destroy\", null, [\"number\"], [handle]);\n}\n\n// -------------------------------------------------------------------------- //\n// Non-stream AED //\n// -------------------------------------------------------------------------- //\n\nconst AED_CLASSES: Record<number, string> = { 0: \"speech\", 1: \"singing\", 2: \"music\" };\n\nexport function aedCreate(M: EmscriptenModule, modelBuffer: ArrayBuffer): number {\n const bytes = new Uint8Array(modelBuffer);\n const ptr = M._malloc(bytes.length);\n M.HEAPU8.set(bytes, ptr);\n try {\n return createModel(M, \"omni_aed_create_from_buffer\", [\"number\", \"number\"], [ptr, bytes.length], \"AED\");\n } finally {\n M._free(ptr);\n }\n}\n\nexport interface AedPostConfig {\n speech: PostConfig;\n singing: PostConfig;\n music: PostConfig;\n}\n\nexport function aedDetect(\n M: EmscriptenModule,\n handle: number,\n audioPtr: number,\n numSamples: number,\n cfg: AedPostConfig,\n format: AudioFormat = \"f32\",\n): Record<string, Array<[number, number]>> {\n const cfgPtr = M._malloc(SIZEOF_AED_POST_CONFIG);\n const segPtrPtr = M._malloc(4);\n const countPtr = M._malloc(4);\n const fn = format === \"int16\" ? \"omni_aed_detect_int16\" : \"omni_aed_detect\";\n\n try {\n writePostConfig(M, cfgPtr, cfg.speech);\n writePostConfig(M, cfgPtr + SIZEOF_POST_CONFIG, cfg.singing);\n writePostConfig(M, cfgPtr + 2 * SIZEOF_POST_CONFIG, cfg.music);\n\n const ret = M.ccall(\n fn,\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\", \"number\"],\n [handle, audioPtr, numSamples, cfgPtr, segPtrPtr, countPtr],\n );\n if (ret !== 0) throw new Error(`AED detect failed: ${ret}`);\n\n const count = M.getValue(countPtr, \"i32\");\n const segPtr = M.getValue(segPtrPtr, \"i32\");\n const events: Record<string, Array<[number, number]>> = {\n speech: [],\n singing: [],\n music: [],\n };\n for (let i = 0; i < count; i++) {\n const base = segPtr + i * SIZEOF_AED_SEGMENT;\n const cls = M.getValue(base + 8, \"i32\");\n const name = AED_CLASSES[cls];\n if (name && events[name]) {\n events[name].push([\n Math.round(M.getValue(base, \"float\") * 1000) / 1000,\n Math.round(M.getValue(base + 4, \"float\") * 1000) / 1000,\n ]);\n }\n }\n if (segPtr) M._free(segPtr);\n return events;\n } finally {\n M._free(cfgPtr);\n M._free(segPtrPtr);\n M._free(countPtr);\n }\n}\n\nexport function aedDestroy(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_aed_destroy\", null, [\"number\"], [handle]);\n}\n\n// -------------------------------------------------------------------------- //\n// Stream VAD //\n// -------------------------------------------------------------------------- //\n\nexport function streamVadCreate(\n M: EmscriptenModule,\n modelBuffer: ArrayBuffer,\n threshold = 0.5,\n): number {\n const bytes = new Uint8Array(modelBuffer);\n const ptr = M._malloc(bytes.length);\n M.HEAPU8.set(bytes, ptr);\n try {\n return createModel(\n M,\n \"omni_stream_vad_create_from_buffer\",\n [\"number\", \"number\", \"number\"],\n [ptr, bytes.length, threshold],\n \"StreamVAD\",\n );\n } finally {\n M._free(ptr);\n }\n}\n\nexport interface StreamVadResult {\n confidence: number;\n isSpeech: boolean;\n frameOffset: number;\n}\n\n/** Process one chunk of int16 PCM (160 samples = 10ms). Returns null if buffering. */\nexport function streamVadProcess(\n M: EmscriptenModule,\n handle: number,\n pcm16Ptr: number,\n numSamples: number,\n): StreamVadResult | null {\n // OmniStreamVadResult: { float confidence, bool is_speech, int frame_offset } = 12 bytes\n const resultPtr = M._malloc(12);\n try {\n const ret = M.ccall(\n \"omni_stream_vad_process\",\n \"number\",\n [\"number\", \"number\", \"number\", \"number\"],\n [handle, pcm16Ptr, numSamples, resultPtr],\n );\n if (ret === OMNI_ERR_NO_FRAMES) return null;\n if (ret !== 0) throw new Error(`StreamVAD process failed: ${ret}`);\n return {\n confidence: M.getValue(resultPtr, \"float\"),\n isSpeech: M.getValue(resultPtr + 4, \"i8\") !== 0,\n frameOffset: M.getValue(resultPtr + 8, \"i32\"),\n };\n } finally {\n M._free(resultPtr);\n }\n}\n\n/** Clone a stream VAD handle (shares model weights, fresh per-instance state). */\nexport function streamVadClone(M: EmscriptenModule, handle: number): number {\n const errPtr = M._malloc(4);\n try {\n const newHandle = M.ccall(\n \"omni_stream_vad_clone\",\n \"number\",\n [\"number\", \"number\"],\n [handle, errPtr],\n );\n if (!newHandle) {\n const err = M.getValue(errPtr, \"i32\");\n throw new Error(`StreamVAD clone failed: ${readNativeError(M, err)}`);\n }\n return newHandle;\n } finally {\n M._free(errPtr);\n }\n}\n\nexport function streamVadReset(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_stream_vad_reset\", null, [\"number\"], [handle]);\n}\n\nexport function streamVadDestroy(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_stream_vad_destroy\", null, [\"number\"], [handle]);\n}\n","/**\n * Non-streaming Voice Activity Detection (WASM/ncnn backend).\n *\n * Audio format:\n * - Int16Array: raw 16-bit PCM, converted to normalized float internally\n * - Float32Array in [-1.0, 1.0]: normalized audio (Web Audio API format)\n */\n\nimport type { VADConfig, VADResult } from \"./types.js\";\nimport {\n initWasm,\n getModule,\n copyAudioToHeap,\n loadModel,\n vadCreate,\n vadDetect,\n vadDestroy,\n DEFAULT_VAD_CONFIG,\n type AudioFormat,\n type PostConfig,\n} from \"./wasm-binding.js\";\n\nconst SAMPLE_RATE = 16000;\n\nexport class OmniVAD {\n private handle: number;\n private config: PostConfig;\n\n private constructor(handle: number, config: PostConfig) {\n this.handle = handle;\n this.config = config;\n }\n\n /**\n * Create a new OmniVAD instance.\n * Loads model from CDN (browser), local package (Node.js), or custom source.\n */\n static async create(options: VADConfig = {}): Promise<OmniVAD> {\n await initWasm();\n const M = getModule();\n const modelBuffer = await loadModel(\"vad\", options.modelUrl, options.modelData);\n const handle = vadCreate(M, modelBuffer);\n const config: PostConfig = {\n threshold: options.speechThreshold ?? DEFAULT_VAD_CONFIG.threshold,\n smoothWindowSize: options.smoothWindowSize ?? DEFAULT_VAD_CONFIG.smoothWindowSize,\n minSpeechFrames: options.minSpeechFrames ?? DEFAULT_VAD_CONFIG.minSpeechFrames,\n minSilenceFrames: options.minSilenceFrames ?? DEFAULT_VAD_CONFIG.minSilenceFrames,\n maxSpeechFrames: options.maxSpeechFrames ?? DEFAULT_VAD_CONFIG.maxSpeechFrames,\n mergeSilenceFrames: options.mergeSilenceFrames ?? DEFAULT_VAD_CONFIG.mergeSilenceFrames,\n extendSpeechFrames: options.extendSpeechFrames ?? DEFAULT_VAD_CONFIG.extendSpeechFrames,\n };\n return new OmniVAD(handle, config);\n }\n\n /**\n * Detect speech segments in audio.\n *\n * Accepts Int16Array (PCM) or normalized Float32Array in [-1, 1].\n */\n detect(audio: Float32Array | Int16Array): VADResult {\n const M = getModule();\n const { ptr, length, format } = prepareAudio(M, audio);\n\n try {\n const timestamps = vadDetect(M, this.handle, ptr, length, this.config, format);\n return {\n duration: Math.round((length / SAMPLE_RATE) * 1000) / 1000,\n timestamps,\n };\n } finally {\n M._free(ptr);\n }\n }\n\n /** Release native resources. */\n dispose(): void {\n if (this.handle) {\n vadDestroy(getModule(), this.handle);\n this.handle = 0;\n }\n }\n}\n\n/** Copy audio to WASM heap as normalized float audio. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction prepareAudio(M: any, audio: Float32Array | Int16Array): { ptr: number; length: number; format: AudioFormat } {\n const f32 = audio instanceof Int16Array ? int16ToNormalizedFloat32(audio) : audio;\n const ptr = copyAudioToHeap(M, f32);\n return { ptr, length: f32.length, format: \"f32\" };\n}\n\nfunction int16ToNormalizedFloat32(i16: Int16Array): Float32Array {\n const f32 = new Float32Array(i16.length);\n for (let i = 0; i < i16.length; i++) f32[i] = i16[i] / 32768;\n return f32;\n}\n","/**\n * Streaming Voice Activity Detection (WASM/ncnn backend).\n * Processes audio frame-by-frame (10ms chunks of 160 samples @ 16kHz).\n */\n\nimport type { StreamVADConfig, StreamVADFrameResult, StreamVADFullResult } from \"./types.js\";\nimport {\n initWasm,\n getModule,\n copyAudioToHeap,\n loadModel,\n streamVadCreate,\n streamVadClone,\n streamVadProcess,\n streamVadReset,\n streamVadDestroy,\n} from \"./wasm-binding.js\";\n\nconst SAMPLE_RATE = 16000;\n\nexport class OmniStreamVAD {\n private handle: number;\n private inSpeech = false;\n private speechStartFrame = 0;\n\n private constructor(handle: number) {\n this.handle = handle;\n }\n\n /**\n * Create a new OmniStreamVAD instance.\n * Loads model from CDN (browser), local package (Node.js), or custom source.\n */\n static async create(options: StreamVADConfig = {}): Promise<OmniStreamVAD> {\n await initWasm();\n const M = getModule();\n const modelBuffer = await loadModel(\"stream-vad\", options.modelUrl, options.modelData);\n const threshold = options.speechThreshold ?? 0.5;\n const handle = streamVadCreate(M, modelBuffer, threshold);\n return new OmniStreamVAD(handle);\n }\n\n /**\n * Create a lightweight clone sharing the same underlying model weights.\n * The clone has fresh per-instance state (empty audio buffer, zeroed cache).\n * This is synchronous and extremely fast — ideal for multi-stream scenarios\n * (e.g., handling multiple WebRTC tracks or concurrent audio sessions).\n */\n clone(): OmniStreamVAD {\n if (!this.handle) throw new Error(\"Cannot clone a disposed instance.\");\n const M = getModule();\n const newHandle = streamVadClone(M, this.handle);\n return new OmniStreamVAD(newHandle);\n }\n\n /**\n * Process one frame of audio (160 int16 samples = 10ms @ 16kHz).\n * Returns null until enough audio is accumulated.\n */\n processFrame(pcm160: Int16Array): StreamVADFrameResult | null {\n const M = getModule();\n const ptr = M._malloc(pcm160.length * 2);\n const heap16 = new Int16Array(M.HEAPU8.buffer, ptr, pcm160.length);\n heap16.set(pcm160);\n\n try {\n const result = streamVadProcess(M, this.handle, ptr, pcm160.length);\n if (!result || result.frameOffset === 0) return null;\n\n const frameIndex = result.frameOffset;\n const isSpeechStart = result.isSpeech && !this.inSpeech;\n const isSpeechEnd = !result.isSpeech && this.inSpeech;\n\n if (isSpeechStart) {\n this.speechStartFrame = frameIndex;\n }\n\n const activeSpeechStartFrame = isSpeechEnd ? this.speechStartFrame : result.isSpeech ? this.speechStartFrame : 0;\n const speechEndFrame = isSpeechEnd ? Math.max(1, frameIndex - 1) : 0;\n\n this.inSpeech = result.isSpeech;\n if (isSpeechEnd) {\n this.speechStartFrame = 0;\n }\n\n return {\n confidence: result.confidence,\n smoothedConfidence: result.confidence,\n isSpeech: result.isSpeech,\n frameIndex,\n isSpeechStart,\n isSpeechEnd,\n speechStartFrame: activeSpeechStartFrame,\n speechEndFrame,\n };\n } finally {\n M._free(ptr);\n }\n }\n\n /**\n * Process entire audio at once and return per-frame probabilities.\n * @param audio - Float32Array in [-1, 1] or Int16Array of 16kHz mono PCM\n */\n detectFull(audio: Float32Array | Int16Array): StreamVADFullResult {\n const M = getModule();\n const f32 = prepareDetectFullAudio(audio);\n const audioPtr = copyAudioToHeap(M, f32);\n const probsPtrPtr = M._malloc(4);\n const framesPtr = M._malloc(4);\n\n try {\n const ret = M.ccall(\n \"omni_stream_vad_detect_full\",\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\"],\n [this.handle, audioPtr, f32.length, probsPtrPtr, framesPtr],\n );\n if (ret !== 0) throw new Error(`StreamVAD detectFull failed: ${ret}`);\n\n const numFrames = M.getValue(framesPtr, \"i32\");\n const probsPtr = M.getValue(probsPtrPtr, \"i32\");\n const probabilities = probsPtr\n ? new Float32Array(new Float32Array(M.HEAPU8.buffer, probsPtr, numFrames))\n : new Float32Array(0);\n if (probsPtr) M._free(probsPtr);\n\n return {\n probabilities,\n numFrames,\n duration: Math.round((f32.length / SAMPLE_RATE) * 1000) / 1000,\n };\n } finally {\n M._free(audioPtr);\n M._free(probsPtrPtr);\n M._free(framesPtr);\n }\n }\n\n /** Reset all internal state. */\n reset(): void {\n streamVadReset(getModule(), this.handle);\n this.inSpeech = false;\n this.speechStartFrame = 0;\n }\n\n /** Release native resources. */\n dispose(): void {\n if (this.handle) {\n streamVadDestroy(getModule(), this.handle);\n this.handle = 0;\n }\n this.inSpeech = false;\n this.speechStartFrame = 0;\n }\n}\n\nfunction int16ToFloat32(i16: Int16Array): Float32Array {\n const f32 = new Float32Array(i16.length);\n for (let i = 0; i < i16.length; i++) f32[i] = i16[i];\n return f32;\n}\n\nfunction prepareDetectFullAudio(audio: Float32Array | Int16Array): Float32Array {\n if (audio instanceof Int16Array) {\n return int16ToFloat32(audio);\n }\n if (isNormalizedFloat(audio)) {\n const scaled = new Float32Array(audio.length);\n for (let i = 0; i < audio.length; i++) scaled[i] = audio[i] * 32768;\n return scaled;\n }\n return audio;\n}\n\nfunction isNormalizedFloat(audio: Float32Array): boolean {\n const step = Math.max(1, Math.floor(audio.length / 1000));\n let maxAbs = 0;\n for (let i = 0; i < audio.length; i += step) {\n const v = Math.abs(audio[i]);\n if (v > maxAbs) maxAbs = v;\n }\n return maxAbs <= 1.0;\n}\n","/**\n * Audio Event Detection: speech, singing, music (WASM/ncnn backend).\n *\n * Audio format: same as OmniVAD — Int16Array or normalized Float32Array [-1, 1].\n */\n\nimport type { AEDConfig, AEDResult } from \"./types.js\";\nimport {\n initWasm,\n getModule,\n loadModel,\n aedCreate,\n aedDetect,\n aedDestroy,\n DEFAULT_VAD_CONFIG,\n type AudioFormat,\n type AedPostConfig,\n} from \"./wasm-binding.js\";\n\nconst SAMPLE_RATE = 16000;\n\nexport class OmniAED {\n private handle: number;\n private config: AedPostConfig;\n\n private constructor(handle: number, config: AedPostConfig) {\n this.handle = handle;\n this.config = config;\n }\n\n /**\n * Create a new OmniAED instance.\n * Loads model from CDN (browser), local package (Node.js), or custom source.\n */\n static async create(options: AEDConfig = {}): Promise<OmniAED> {\n await initWasm();\n const M = getModule();\n const modelBuffer = await loadModel(\"aed\", options.modelUrl, options.modelData);\n const handle = aedCreate(M, modelBuffer);\n\n const base = {\n smoothWindowSize: options.smoothWindowSize ?? DEFAULT_VAD_CONFIG.smoothWindowSize,\n minSpeechFrames: options.minSpeechFrames ?? DEFAULT_VAD_CONFIG.minSpeechFrames,\n minSilenceFrames: options.minSilenceFrames ?? DEFAULT_VAD_CONFIG.minSilenceFrames,\n maxSpeechFrames: options.maxSpeechFrames ?? DEFAULT_VAD_CONFIG.maxSpeechFrames,\n mergeSilenceFrames: options.mergeSilenceFrames ?? DEFAULT_VAD_CONFIG.mergeSilenceFrames,\n extendSpeechFrames: options.extendSpeechFrames ?? DEFAULT_VAD_CONFIG.extendSpeechFrames,\n };\n\n const config: AedPostConfig = {\n speech: { ...base, threshold: options.speechThreshold ?? 0.4 },\n singing: { ...base, threshold: options.singingThreshold ?? 0.5 },\n music: { ...base, threshold: options.musicThreshold ?? 0.5 },\n };\n return new OmniAED(handle, config);\n }\n\n /**\n * Detect audio events (speech, singing, music).\n *\n * Accepts Int16Array (PCM) or normalized Float32Array in [-1, 1].\n */\n detect(audio: Float32Array | Int16Array): AEDResult {\n const M = getModule();\n const { ptr, length, format } = prepareAudio(M, audio);\n const duration = Math.round((length / SAMPLE_RATE) * 1000) / 1000;\n\n try {\n const events = aedDetect(M, this.handle, ptr, length, this.config, format);\n return {\n duration,\n events,\n ratios: computeCoverageRatios(events, duration),\n };\n } finally {\n M._free(ptr);\n }\n }\n\n /** Release native resources. */\n dispose(): void {\n if (this.handle) {\n aedDestroy(getModule(), this.handle);\n this.handle = 0;\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction prepareAudio(M: any, audio: Float32Array | Int16Array): { ptr: number; length: number; format: AudioFormat } {\n const f32 = audio instanceof Int16Array ? int16ToNormalizedFloat32(audio) : audio;\n const ptr = M._malloc(f32.length * 4);\n const heap = new Float32Array(M.HEAPU8.buffer, ptr, f32.length);\n heap.set(f32);\n return { ptr, length: f32.length, format: \"f32\" };\n}\n\nfunction int16ToNormalizedFloat32(i16: Int16Array): Float32Array {\n const f32 = new Float32Array(i16.length);\n for (let i = 0; i < i16.length; i++) f32[i] = i16[i] / 32768;\n return f32;\n}\n\nfunction computeCoverageRatios(\n events: Record<string, Array<[number, number]>>,\n duration: number,\n): Record<string, number> {\n const ratios: Record<string, number> = {\n speech: 0,\n singing: 0,\n music: 0,\n };\n\n if (duration <= 0) return ratios;\n\n for (const cls of Object.keys(ratios)) {\n const covered = (events[cls] ?? []).reduce((sum, [start, end]) => sum + Math.max(0, end - start), 0);\n ratios[cls] = Math.round(Math.min(1, covered / duration) * 1e6) / 1e6;\n }\n\n return ratios;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/wasm-binding.ts","../src/vad.ts","../src/stream-vad.ts","../src/aed.ts","../src/chunking.ts"],"names":["resp","SAMPLE_RATE","prepareAudio","int16ToNormalizedFloat32"],"mappings":";;;;AAQA,IAAI,OAAA,GAAmC,IAAA;AACvC,IAAI,QAAA,GAA6C,IAAA;AAWjD,SAAS,WAAW,GAAA,EAA4B;AAE9C,EAAA,IAAI,OAAO,UAAA,CAAW,QAAA,KAAa,WAAA,EAAa;AAC9C,IAAA,OAAO,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC5C,MAAA,IAAI;AAEF,QAAA,MAAM,gBAAiB,UAAA,CAAmB,aAAA;AAG1C,QAAA,IAAI,OAAO,kBAAkB,UAAA,EAAY;AACvC,UAAA,MAAM,IAAI,KAAA;AAAA,YACR;AAAA,WACF;AAAA,QACF;AACA,QAAA,aAAA,CAAc,GAAG,CAAA;AACjB,QAAA,OAAA,EAAQ;AAAA,MACV,SAAS,GAAA,EAAK;AACZ,QAAA,MAAA,CAAO,GAAA,YAAe,QAAQ,GAAA,GAAM,IAAI,MAAM,M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,CAAQ,aAAA,IAAmB,oBAAA,CAAqB,aAAA;AAAA,IACjE,cAAA,EAAiB,OAAA,CAAQ,cAAA,IAAmB,oBAAA,CAAqB,cAAA;AAAA,IACjE,IAAA,EAAiB,OAAA,CAAQ,IAAA,IAAmB,oBAAA,CAAqB;AAAA,GACnE;AAEA,EAAA,MAAM,OAAA,GAAU,UAAA,CAAW,CAAA,EAAG,QAAA,EAAU,GAAG,CAAA;AAC3C,EAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,MAAO;AAAA,IACzB,OAAO,CAAA,CAAE,KAAA;AAAA,IACT,KAAK,CAAA,CAAE,GAAA;AAAA,IACP,aAAa,CAAA,CAAE,WAAA;AAAA,IACf,UAAU,CAAA,CAAE;AAAA,GACd,CAAE,CAAA;AACJ","file":"index.cjs","sourcesContent":["/**\n * Low-level WASM binding for omnivad C API.\n * Loads the Emscripten module and provides typed wrappers.\n */\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype EmscriptenModule = any;\n\nlet _module: EmscriptenModule | null = null;\nlet _loading: Promise<EmscriptenModule> | null = null;\n\n/**\n * Browser-side classic-script loader. Used to pull in Emscripten's IIFE\n * glue (`var createOmniVAD = (() => {...})()`) without going through\n * `import()` — see initWasm()'s long comment.\n *\n * Works in both DOM contexts (main thread) and worker contexts: in a\n * Worker we fall back to `importScripts(url)` which is synchronous but\n * still wrapped in a Promise for API uniformity.\n */\nfunction loadScript(url: string): Promise<void> {\n // Worker path.\n if (typeof globalThis.document === \"undefined\") {\n return new Promise<void>((resolve, reject) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const importScripts = (globalThis as any).importScripts as\n | ((u: string) => void)\n | undefined;\n if (typeof importScripts !== \"function\") {\n throw new Error(\n \"omnivad: cannot load glue script — no document and no importScripts\",\n );\n }\n importScripts(url);\n resolve();\n } catch (err) {\n reject(err instanceof Error ? err : new Error(String(err)));\n }\n });\n }\n // Main thread path.\n return new Promise<void>((resolve, reject) => {\n const s = globalThis.document!.createElement(\"script\");\n s.src = url;\n s.async = true;\n s.crossOrigin = \"anonymous\";\n s.onload = () => resolve();\n s.onerror = () =>\n reject(new Error(`Failed to load omnivad glue script: ${url}`));\n globalThis.document!.head.appendChild(s);\n });\n}\n\n/** Post-processing config matching C struct OmniPostConfig (7 x i32/float, 28 bytes) */\nexport interface PostConfig {\n threshold: number;\n smoothWindowSize: number;\n minSpeechFrames: number;\n minSilenceFrames: number;\n maxSpeechFrames: number;\n mergeSilenceFrames: number;\n extendSpeechFrames: number;\n}\n\nconst SIZEOF_POST_CONFIG = 28; // 7 * 4 bytes\nconst SIZEOF_AED_POST_CONFIG = 3 * SIZEOF_POST_CONFIG; // 84 bytes\nconst SIZEOF_SEGMENT = 8; // start(f32) + end(f32)\nconst SIZEOF_AED_SEGMENT = 16; // start(f32) + end(f32) + cls(i32) + confidence(f32)\nconst SIZEOF_CHUNK_CONFIG = 28; // 6 floats + 1 i32 mode\nconst SIZEOF_CHUNK = 16; // start(f32) + end(f32) + seg_start_idx(i32) + seg_count(i32)\n\n/** Re-exported for ABI self-tests. */\nexport const _SIZEOF_CHUNK_CONFIG = SIZEOF_CHUNK_CONFIG;\nexport const _SIZEOF_CHUNK = SIZEOF_CHUNK;\nconst OMNI_ERR_NO_FRAMES = -7;\n\n/** Package version — used to construct default CDN URLs. */\nexport const VERSION = \"0.2.8\";\n\n/** Default CDN base for model files (jsDelivr serves npm package contents). */\nexport const DEFAULT_CDN_BASE = `https://cdn.jsdelivr.net/npm/omnivad@${VERSION}/models`;\n\n/** Model filenames keyed by type. */\nexport const MODEL_FILES = {\n vad: \"vad.omnivad\",\n \"stream-vad\": \"stream-vad.omnivad\",\n aed: \"aed.omnivad\",\n} as const;\n\nexport type ModelType = keyof typeof MODEL_FILES;\n\n/**\n * Initialize the WASM module. Call once before using any other functions.\n * Safe to call multiple times (returns cached module).\n */\nexport async function initWasm(\n wasmLocator?: (filename: string) => string,\n): Promise<EmscriptenModule> {\n if (_module) return _module;\n if (_loading) return _loading;\n\n _loading = (async () => {\n // Dynamic import of the Emscripten glue\n let createOmniVAD: (opts?: Record<string, unknown>) => Promise<EmscriptenModule>;\n let defaultLocateFile: ((filename: string) => string) | undefined;\n\n if (typeof globalThis.process?.versions?.node === \"string\") {\n // Node.js: use require for .cjs (avoids ESM detection issues)\n const { createRequire } = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ \"module\");\n const { dirname, join } = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ \"path\");\n const req = createRequire(import.meta.url);\n const gluePath = req.resolve(\"../dist/wasm/omnivad.cjs\");\n const wasmDir = dirname(gluePath);\n createOmniVAD = req(gluePath);\n defaultLocateFile = (filename: string) => join(wasmDir, filename);\n } else {\n // Browser. We can't `await import()` the glue: Emscripten with\n // MODULARIZE=1 (no EXPORT_ES6=1) emits an IIFE\n // var createOmniVAD = (() => { ... })();\n // which has zero ES exports, so dynamic import yields an empty\n // module record and `mod.default || mod` is the empty namespace\n // object → `createOmniVAD()` throws \"is not a function\".\n //\n // Solution: classic <script> injection, then read the global the\n // IIFE wrote to (`globalThis.createOmniVAD`). Caches via the global\n // so repeat callers don't re-fetch the script.\n let glueUrlStr: string;\n if (wasmLocator) {\n glueUrlStr = wasmLocator(\"omnivad.js\");\n } else {\n // Native ESM resolution path (when consumed without a bundler).\n glueUrlStr = new URL(\"../dist/wasm/omnivad.js\", import.meta.url).href;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const g = globalThis as any;\n let factory: ((opts?: Record<string, unknown>) => Promise<EmscriptenModule>) | undefined =\n g.createOmniVAD;\n if (typeof factory !== \"function\") {\n await loadScript(glueUrlStr);\n factory = g.createOmniVAD;\n }\n if (typeof factory !== \"function\") {\n throw new Error(\n `omnivad.js loaded from ${glueUrlStr} but globalThis.createOmniVAD is missing`,\n );\n }\n createOmniVAD = factory;\n // glueUrlStr may already be absolute (when wasmLocator returns a\n // full URL) or relative (native ESM mode). new URL(\"./\", abs) is\n // safe; new URL(\"./\", path-relative) throws — guard with a base.\n const baseHref =\n typeof globalThis.location !== \"undefined\"\n ? globalThis.location.href\n : \"file:///\";\n const absGlue = new URL(glueUrlStr, baseHref);\n const wasmBaseUrl = new URL(\"./\", absGlue);\n defaultLocateFile = (filename: string) => new URL(filename, wasmBaseUrl).toString();\n }\n\n const opts: Record<string, unknown> = {};\n const locateFile = wasmLocator ?? defaultLocateFile;\n if (locateFile) {\n opts.locateFile = (path: string) => locateFile(path);\n }\n\n _module = await createOmniVAD(opts);\n return _module!;\n })();\n\n return _loading;\n}\n\n/**\n * Load a model file as ArrayBuffer.\n *\n * Resolution order:\n * 1. modelData (ArrayBuffer) — use directly\n * 2. modelUrl (string/URL) — fetch from that URL\n * 3. Node.js — read from npm package's models/ directory\n * 4. Browser — fetch from jsDelivr CDN\n */\nexport async function loadModel(\n modelType: ModelType,\n modelUrl?: string | URL,\n modelData?: ArrayBuffer,\n): Promise<ArrayBuffer> {\n if (modelData) return modelData;\n\n if (modelUrl) {\n const resp = await fetch(modelUrl.toString());\n if (!resp.ok) throw new Error(`Failed to fetch model from ${modelUrl}: ${resp.status}`);\n return resp.arrayBuffer();\n }\n\n const filename = MODEL_FILES[modelType];\n\n if (typeof globalThis.process?.versions?.node === \"string\") {\n // Node.js: read from package's models/ directory\n const { createRequire } = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ \"module\");\n const { dirname, join } = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ \"path\");\n const { readFile } = await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ \"fs/promises\");\n const req = createRequire(import.meta.url);\n const pkgDir = dirname(req.resolve(\"../package.json\"));\n const modelPath = join(pkgDir, \"models\", filename);\n const buf = await readFile(modelPath);\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n }\n\n // Browser: fetch from CDN\n const url = `${DEFAULT_CDN_BASE}/${filename}`;\n const resp = await fetch(url);\n if (!resp.ok) throw new Error(`Failed to fetch model from ${url}: ${resp.status}`);\n return resp.arrayBuffer();\n}\n\n/** Get the initialized WASM module (throws if not initialized) */\nexport function getModule(): EmscriptenModule {\n if (!_module) throw new Error(\"WASM not initialized. Call initWasm() first.\");\n return _module;\n}\n\nfunction readNativeError(M: EmscriptenModule, code: number): string {\n const msg = M.ccall(\"omni_error_string\", \"string\", [\"number\"], [code]);\n return msg ? `${msg} (${code})` : `error ${code}`;\n}\n\n/** Shared helper: call a C create function with out_error, throw on failure. */\nfunction createModel(\n M: EmscriptenModule,\n fnName: string,\n argTypes: string[],\n args: unknown[],\n label: string,\n): number {\n const errPtr = M._malloc(4);\n try {\n const handle = M.ccall(fnName, \"number\", [...argTypes, \"number\"], [...args, errPtr]);\n if (!handle) {\n const err = M.getValue(errPtr, \"i32\");\n throw new Error(`Failed to create ${label} model: ${readNativeError(M, err)}`);\n }\n return handle;\n } finally {\n M._free(errPtr);\n }\n}\n\n// -------------------------------------------------------------------------- //\n// Memory helpers //\n// -------------------------------------------------------------------------- //\n\n/** Copy Float32Array audio into WASM heap, returns pointer. Caller must free. */\nexport function copyAudioToHeap(M: EmscriptenModule, audio: Float32Array): number {\n const ptr = M._malloc(audio.length * 4);\n const heap = new Float32Array(M.HEAPU8.buffer, ptr, audio.length);\n heap.set(audio);\n return ptr;\n}\n\n/** Write PostConfig struct to WASM heap at ptr */\nexport function writePostConfig(M: EmscriptenModule, ptr: number, cfg: PostConfig): void {\n M.setValue(ptr + 0, cfg.threshold, \"float\");\n M.setValue(ptr + 4, cfg.smoothWindowSize, \"i32\");\n M.setValue(ptr + 8, cfg.minSpeechFrames, \"i32\");\n M.setValue(ptr + 12, cfg.minSilenceFrames, \"i32\");\n M.setValue(ptr + 16, cfg.maxSpeechFrames, \"i32\");\n M.setValue(ptr + 20, cfg.mergeSilenceFrames, \"i32\");\n M.setValue(ptr + 24, cfg.extendSpeechFrames, \"i32\");\n}\n\nexport const DEFAULT_VAD_CONFIG: PostConfig = {\n threshold: 0.4,\n smoothWindowSize: 5,\n minSpeechFrames: 20,\n minSilenceFrames: 20,\n maxSpeechFrames: 3000,\n mergeSilenceFrames: 0,\n extendSpeechFrames: 0,\n};\n\n// -------------------------------------------------------------------------- //\n// Chunking (pure-algorithm, mirrors omnivad.h's omni_merge_chunks) //\n// -------------------------------------------------------------------------- //\n\n/** OmniChunkMode enum values (must match native/include/omnivad.h). */\nexport const OMNI_CHUNK_GREEDY = 0;\nexport const OMNI_CHUNK_LONGEST_GAP = 1;\n\n/**\n * Chunking strategy:\n * - \"greedy\" — sequential append. Recommended for fixed-length-input ASR\n * (Whisper / whisperX, which pad to 30s anyway).\n * - \"longest_gap\" — recursive split at longest pause; falls back to hard-split\n * when a single segment exceeds maxChunkSecs. Recommended for\n * variable-length-input models (forced alignment, TTS,\n * encoder-style ASR); no fixed-length padding required.\n */\nexport type ChunkMode = \"greedy\" | \"longest_gap\";\n\n/** Configuration for omni_merge_chunks (matches C struct OmniChunkConfig, 28 bytes) */\nexport interface ChunkConfig {\n maxChunkSecs: number; // hard upper bound on chunk duration (seconds), > 0\n maxGapSecs: number; // split if gap > this. Infinity disables. Honored by both modes.\n padOnsetSecs: number; // extend chunk start backward (clamped >= 0)\n padOffsetSecs: number; // extend chunk end forward\n minSpeechSecs: number; // drop input segments shorter than this; pairs with VAD minSpeechFrames\n minSilenceSecs: number; // pre-merge gaps shorter than this; pairs with VAD minSilenceFrames\n mode: ChunkMode; // packing strategy (default \"greedy\")\n}\n\n/**\n * Default chunk config. Mirrors C-side omni_chunk_config_default(); kept in\n * TS so callers don't need a roundtrip into WASM just to read defaults.\n *\n * Defaults: max_chunk_secs matches Whisper's 30s input window.\n */\nexport const DEFAULT_CHUNK_CONFIG: ChunkConfig = {\n maxChunkSecs: 30.0,\n maxGapSecs: Infinity,\n padOnsetSecs: 0.04,\n padOffsetSecs: 0.04,\n minSpeechSecs: 0.0,\n minSilenceSecs: 0.20, // matches VAD minSilenceFrames=20 @ 10ms shift\n mode: \"greedy\",\n};\n\nfunction modeToInt(m: ChunkMode): number {\n switch (m) {\n case \"greedy\": return OMNI_CHUNK_GREEDY;\n case \"longest_gap\": return OMNI_CHUNK_LONGEST_GAP;\n default: throw new Error(`Unknown chunking mode: ${String(m)}`);\n }\n}\n\n/** Write ChunkConfig struct to WASM heap at ptr (must be SIZEOF_CHUNK_CONFIG bytes). */\nexport function writeChunkConfig(M: EmscriptenModule, ptr: number, cfg: ChunkConfig): void {\n M.setValue(ptr + 0, cfg.maxChunkSecs, \"float\");\n M.setValue(ptr + 4, cfg.maxGapSecs, \"float\");\n M.setValue(ptr + 8, cfg.padOnsetSecs, \"float\");\n M.setValue(ptr + 12, cfg.padOffsetSecs, \"float\");\n M.setValue(ptr + 16, cfg.minSpeechSecs, \"float\");\n M.setValue(ptr + 20, cfg.minSilenceSecs, \"float\");\n M.setValue(ptr + 24, modeToInt(cfg.mode), \"i32\");\n}\n\nexport interface ChunkRecord {\n start: number;\n end: number;\n segStartIdx: number;\n segCount: number;\n}\n\n/**\n * Call omni_merge_chunks via the WASM module.\n *\n * @param segments array of [start, end] pairs, sorted by start (caller's contract)\n * @param config chunking configuration\n * @returns array of ChunkRecord. On C error, throws.\n */\nexport function chunkMerge(\n M: EmscriptenModule,\n segments: Array<[number, number]>,\n config: ChunkConfig,\n): ChunkRecord[] {\n const numSegments = segments.length;\n\n const segPtr = numSegments > 0 ? M._malloc(numSegments * SIZEOF_SEGMENT) : 0;\n const cfgPtr = M._malloc(SIZEOF_CHUNK_CONFIG);\n const outPtrPtr = M._malloc(4); // pointer to OmniChunk*\n const outCountPtr = M._malloc(4);\n\n try {\n for (let i = 0; i < numSegments; i++) {\n const base = segPtr + i * SIZEOF_SEGMENT;\n M.setValue(base + 0, segments[i][0], \"float\");\n M.setValue(base + 4, segments[i][1], \"float\");\n }\n writeChunkConfig(M, cfgPtr, config);\n M.setValue(outPtrPtr, 0, \"i32\");\n M.setValue(outCountPtr, 0, \"i32\");\n\n const rc = M.ccall(\n \"omni_merge_chunks\",\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\"],\n [segPtr, numSegments, cfgPtr, outPtrPtr, outCountPtr],\n );\n if (rc !== 0) {\n throw new Error(`omni_merge_chunks failed: ${readNativeError(M, rc)}`);\n }\n\n const count = M.getValue(outCountPtr, \"i32\");\n const chunkPtr = M.getValue(outPtrPtr, \"i32\");\n const chunks: ChunkRecord[] = [];\n for (let i = 0; i < count; i++) {\n const base = chunkPtr + i * SIZEOF_CHUNK;\n chunks.push({\n start: M.getValue(base + 0, \"float\"),\n end: M.getValue(base + 4, \"float\"),\n segStartIdx: M.getValue(base + 8, \"i32\"),\n segCount: M.getValue(base + 12, \"i32\"),\n });\n }\n if (chunkPtr) M._free(chunkPtr);\n return chunks;\n } finally {\n if (segPtr) M._free(segPtr);\n M._free(cfgPtr);\n M._free(outPtrPtr);\n M._free(outCountPtr);\n }\n}\n\n// -------------------------------------------------------------------------- //\n// Non-stream VAD //\n// -------------------------------------------------------------------------- //\n\nexport function vadCreate(M: EmscriptenModule, modelBuffer: ArrayBuffer): number {\n const bytes = new Uint8Array(modelBuffer);\n const ptr = M._malloc(bytes.length);\n M.HEAPU8.set(bytes, ptr);\n try {\n return createModel(M, \"omni_vad_create_from_buffer\", [\"number\", \"number\"], [ptr, bytes.length], \"VAD\");\n } finally {\n M._free(ptr);\n }\n}\n\n/**\n * Audio format: two types only.\n * \"f32\" — float* in [-1.0, 1.0] (Web Audio API, soundfile, torch)\n * \"int16\" — int16_t* PCM (WAV files, microphones)\n */\nexport type AudioFormat = \"f32\" | \"int16\";\n\nfunction readSegments(M: EmscriptenModule, segPtrPtr: number, countPtr: number): Array<[number, number]> {\n const count = M.getValue(countPtr, \"i32\");\n const segPtr = M.getValue(segPtrPtr, \"i32\");\n const segments: Array<[number, number]> = [];\n for (let i = 0; i < count; i++) {\n const base = segPtr + i * SIZEOF_SEGMENT;\n segments.push([\n Math.round(M.getValue(base, \"float\") * 1000) / 1000,\n Math.round(M.getValue(base + 4, \"float\") * 1000) / 1000,\n ]);\n }\n if (segPtr) M._free(segPtr);\n return segments;\n}\n\nexport function vadDetect(\n M: EmscriptenModule,\n handle: number,\n audioPtr: number,\n numSamples: number,\n cfg: PostConfig,\n format: AudioFormat = \"f32\",\n): Array<[number, number]> {\n const cfgPtr = M._malloc(SIZEOF_POST_CONFIG);\n const segPtrPtr = M._malloc(4);\n const countPtr = M._malloc(4);\n const fn = format === \"int16\" ? \"omni_vad_detect_int16\" : \"omni_vad_detect\";\n\n try {\n writePostConfig(M, cfgPtr, cfg);\n const ret = M.ccall(\n fn,\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\", \"number\"],\n [handle, audioPtr, numSamples, cfgPtr, segPtrPtr, countPtr],\n );\n if (ret !== 0) throw new Error(`VAD detect failed: ${ret}`);\n return readSegments(M, segPtrPtr, countPtr);\n } finally {\n M._free(cfgPtr);\n M._free(segPtrPtr);\n M._free(countPtr);\n }\n}\n\nexport function vadDestroy(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_vad_destroy\", null, [\"number\"], [handle]);\n}\n\n// -------------------------------------------------------------------------- //\n// Non-stream AED //\n// -------------------------------------------------------------------------- //\n\nconst AED_CLASSES: Record<number, string> = { 0: \"speech\", 1: \"singing\", 2: \"music\" };\n\nexport function aedCreate(M: EmscriptenModule, modelBuffer: ArrayBuffer): number {\n const bytes = new Uint8Array(modelBuffer);\n const ptr = M._malloc(bytes.length);\n M.HEAPU8.set(bytes, ptr);\n try {\n return createModel(M, \"omni_aed_create_from_buffer\", [\"number\", \"number\"], [ptr, bytes.length], \"AED\");\n } finally {\n M._free(ptr);\n }\n}\n\nexport interface AedPostConfig {\n speech: PostConfig;\n singing: PostConfig;\n music: PostConfig;\n}\n\nexport function aedDetect(\n M: EmscriptenModule,\n handle: number,\n audioPtr: number,\n numSamples: number,\n cfg: AedPostConfig,\n format: AudioFormat = \"f32\",\n): Record<string, Array<[number, number]>> {\n const cfgPtr = M._malloc(SIZEOF_AED_POST_CONFIG);\n const segPtrPtr = M._malloc(4);\n const countPtr = M._malloc(4);\n const fn = format === \"int16\" ? \"omni_aed_detect_int16\" : \"omni_aed_detect\";\n\n try {\n writePostConfig(M, cfgPtr, cfg.speech);\n writePostConfig(M, cfgPtr + SIZEOF_POST_CONFIG, cfg.singing);\n writePostConfig(M, cfgPtr + 2 * SIZEOF_POST_CONFIG, cfg.music);\n\n const ret = M.ccall(\n fn,\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\", \"number\"],\n [handle, audioPtr, numSamples, cfgPtr, segPtrPtr, countPtr],\n );\n if (ret !== 0) throw new Error(`AED detect failed: ${ret}`);\n\n const count = M.getValue(countPtr, \"i32\");\n const segPtr = M.getValue(segPtrPtr, \"i32\");\n const events: Record<string, Array<[number, number]>> = {\n speech: [],\n singing: [],\n music: [],\n };\n for (let i = 0; i < count; i++) {\n const base = segPtr + i * SIZEOF_AED_SEGMENT;\n const cls = M.getValue(base + 8, \"i32\");\n const name = AED_CLASSES[cls];\n if (name && events[name]) {\n events[name].push([\n Math.round(M.getValue(base, \"float\") * 1000) / 1000,\n Math.round(M.getValue(base + 4, \"float\") * 1000) / 1000,\n ]);\n }\n }\n if (segPtr) M._free(segPtr);\n return events;\n } finally {\n M._free(cfgPtr);\n M._free(segPtrPtr);\n M._free(countPtr);\n }\n}\n\nexport function aedDestroy(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_aed_destroy\", null, [\"number\"], [handle]);\n}\n\n// -------------------------------------------------------------------------- //\n// Stream VAD //\n// -------------------------------------------------------------------------- //\n\n/** OmniStreamVadConfig — bit-identical to upstream FireRedStreamVadConfig. */\nexport interface StreamVadConfig {\n threshold: number;\n smoothWindowSize: number;\n padStartFrame: number;\n minSpeechFrame: number;\n maxSpeechFrame: number;\n minSilenceFrame: number;\n}\n\n/** Defaults match upstream FireRedStreamVadConfig. */\nexport const DEFAULT_STREAM_VAD_CONFIG: StreamVadConfig = {\n threshold: 0.5,\n smoothWindowSize: 5,\n padStartFrame: 5,\n minSpeechFrame: 8,\n maxSpeechFrame: 2000,\n minSilenceFrame: 20,\n};\n\nconst SIZEOF_STREAM_VAD_CONFIG = 24; // float + 5 i32\n\nfunction writeStreamVadConfig(M: EmscriptenModule, ptr: number, cfg: StreamVadConfig): void {\n M.setValue(ptr + 0, cfg.threshold, \"float\");\n M.setValue(ptr + 4, cfg.smoothWindowSize, \"i32\");\n M.setValue(ptr + 8, cfg.padStartFrame, \"i32\");\n M.setValue(ptr + 12, cfg.minSpeechFrame, \"i32\");\n M.setValue(ptr + 16, cfg.maxSpeechFrame, \"i32\");\n M.setValue(ptr + 20, cfg.minSilenceFrame, \"i32\");\n}\n\nexport function streamVadCreate(\n M: EmscriptenModule,\n modelBuffer: ArrayBuffer,\n config: Partial<StreamVadConfig> = {},\n): number {\n // Skip undefined overrides — callers often relay optional kwargs that may\n // be `undefined`, and spreading those would clobber the upstream defaults.\n const overrides = Object.fromEntries(\n Object.entries(config).filter(([, v]) => v !== undefined),\n );\n const cfg: StreamVadConfig = { ...DEFAULT_STREAM_VAD_CONFIG, ...overrides };\n const bytes = new Uint8Array(modelBuffer);\n const dataPtr = M._malloc(bytes.length);\n M.HEAPU8.set(bytes, dataPtr);\n const cfgPtr = M._malloc(SIZEOF_STREAM_VAD_CONFIG);\n try {\n writeStreamVadConfig(M, cfgPtr, cfg);\n return createModel(\n M,\n \"omni_stream_vad_create_from_buffer\",\n [\"number\", \"number\", \"number\"],\n [dataPtr, bytes.length, cfgPtr],\n \"StreamVAD\",\n );\n } finally {\n M._free(dataPtr);\n M._free(cfgPtr);\n }\n}\n\n/** Per-frame result from streaming VAD. Bit-identical to upstream\n * StreamVadFrameResult: includes segment-boundary events. */\nexport interface StreamVadResult {\n confidence: number;\n smoothedProb: number;\n isSpeech: boolean;\n isSpeechStart: boolean;\n isSpeechEnd: boolean;\n frameIdx: number;\n speechStartFrame: number;\n speechEndFrame: number;\n}\n\nconst SIZEOF_STREAM_VAD_RESULT = 24; // 2*float + 3*bool + 1pad + 3*i32\n\n/** Process one chunk of int16 PCM (160 samples = 10ms). Returns null if buffering. */\nexport function streamVadProcess(\n M: EmscriptenModule,\n handle: number,\n pcm16Ptr: number,\n numSamples: number,\n): StreamVadResult | null {\n const resultPtr = M._malloc(SIZEOF_STREAM_VAD_RESULT);\n try {\n const ret = M.ccall(\n \"omni_stream_vad_process\",\n \"number\",\n [\"number\", \"number\", \"number\", \"number\"],\n [handle, pcm16Ptr, numSamples, resultPtr],\n );\n if (ret === OMNI_ERR_NO_FRAMES) return null;\n if (ret !== 0) throw new Error(`StreamVAD process failed: ${ret}`);\n return {\n confidence: M.getValue(resultPtr + 0, \"float\"),\n smoothedProb: M.getValue(resultPtr + 4, \"float\"),\n isSpeech: M.getValue(resultPtr + 8, \"i8\") !== 0,\n isSpeechStart: M.getValue(resultPtr + 9, \"i8\") !== 0,\n isSpeechEnd: M.getValue(resultPtr + 10, \"i8\") !== 0,\n frameIdx: M.getValue(resultPtr + 12, \"i32\"),\n speechStartFrame: M.getValue(resultPtr + 16, \"i32\"),\n speechEndFrame: M.getValue(resultPtr + 20, \"i32\"),\n };\n } finally {\n M._free(resultPtr);\n }\n}\n\n/** Clone a stream VAD handle (shares model weights, fresh per-instance state). */\nexport function streamVadClone(M: EmscriptenModule, handle: number): number {\n const errPtr = M._malloc(4);\n try {\n const newHandle = M.ccall(\n \"omni_stream_vad_clone\",\n \"number\",\n [\"number\", \"number\"],\n [handle, errPtr],\n );\n if (!newHandle) {\n const err = M.getValue(errPtr, \"i32\");\n throw new Error(`StreamVAD clone failed: ${readNativeError(M, err)}`);\n }\n return newHandle;\n } finally {\n M._free(errPtr);\n }\n}\n\nexport function streamVadReset(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_stream_vad_reset\", null, [\"number\"], [handle]);\n}\n\nexport function streamVadDestroy(M: EmscriptenModule, handle: number): void {\n M.ccall(\"omni_stream_vad_destroy\", null, [\"number\"], [handle]);\n}\n","/**\n * Non-streaming Voice Activity Detection (WASM/ncnn backend).\n *\n * Audio format:\n * - Int16Array: raw 16-bit PCM, converted to normalized float internally\n * - Float32Array in [-1.0, 1.0]: normalized audio (Web Audio API format)\n */\n\nimport type { VADConfig, VADResult } from \"./types.js\";\nimport {\n initWasm,\n getModule,\n copyAudioToHeap,\n loadModel,\n vadCreate,\n vadDetect,\n vadDestroy,\n DEFAULT_VAD_CONFIG,\n type AudioFormat,\n type PostConfig,\n} from \"./wasm-binding.js\";\n\nconst SAMPLE_RATE = 16000;\n\nexport class OmniVAD {\n private handle: number;\n private config: PostConfig;\n\n private constructor(handle: number, config: PostConfig) {\n this.handle = handle;\n this.config = config;\n }\n\n /**\n * Create a new OmniVAD instance.\n * Loads model from CDN (browser), local package (Node.js), or custom source.\n */\n static async create(options: VADConfig = {}): Promise<OmniVAD> {\n await initWasm();\n const M = getModule();\n const modelBuffer = await loadModel(\"vad\", options.modelUrl, options.modelData);\n const handle = vadCreate(M, modelBuffer);\n const config: PostConfig = {\n threshold: options.speechThreshold ?? DEFAULT_VAD_CONFIG.threshold,\n smoothWindowSize: options.smoothWindowSize ?? DEFAULT_VAD_CONFIG.smoothWindowSize,\n minSpeechFrames: options.minSpeechFrames ?? DEFAULT_VAD_CONFIG.minSpeechFrames,\n minSilenceFrames: options.minSilenceFrames ?? DEFAULT_VAD_CONFIG.minSilenceFrames,\n maxSpeechFrames: options.maxSpeechFrames ?? DEFAULT_VAD_CONFIG.maxSpeechFrames,\n mergeSilenceFrames: options.mergeSilenceFrames ?? DEFAULT_VAD_CONFIG.mergeSilenceFrames,\n extendSpeechFrames: options.extendSpeechFrames ?? DEFAULT_VAD_CONFIG.extendSpeechFrames,\n };\n return new OmniVAD(handle, config);\n }\n\n /**\n * Detect speech segments in audio.\n *\n * Accepts Int16Array (PCM) or normalized Float32Array in [-1, 1].\n */\n detect(audio: Float32Array | Int16Array): VADResult {\n const M = getModule();\n const { ptr, length, format } = prepareAudio(M, audio);\n\n try {\n const timestamps = vadDetect(M, this.handle, ptr, length, this.config, format);\n return {\n duration: Math.round((length / SAMPLE_RATE) * 1000) / 1000,\n timestamps,\n };\n } finally {\n M._free(ptr);\n }\n }\n\n /** Release native resources. */\n dispose(): void {\n if (this.handle) {\n vadDestroy(getModule(), this.handle);\n this.handle = 0;\n }\n }\n}\n\n/** Copy audio to WASM heap as normalized float audio. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction prepareAudio(M: any, audio: Float32Array | Int16Array): { ptr: number; length: number; format: AudioFormat } {\n const f32 = audio instanceof Int16Array ? int16ToNormalizedFloat32(audio) : audio;\n const ptr = copyAudioToHeap(M, f32);\n return { ptr, length: f32.length, format: \"f32\" };\n}\n\nfunction int16ToNormalizedFloat32(i16: Int16Array): Float32Array {\n const f32 = new Float32Array(i16.length);\n for (let i = 0; i < i16.length; i++) f32[i] = i16[i] / 32768;\n return f32;\n}\n","/**\n * Streaming Voice Activity Detection (WASM/ncnn backend).\n * Processes audio frame-by-frame (10ms chunks of 160 samples @ 16kHz).\n */\n\nimport type { StreamVADConfig, StreamVADFrameResult, StreamVADFullResult } from \"./types.js\";\nimport {\n initWasm,\n getModule,\n copyAudioToHeap,\n loadModel,\n streamVadCreate,\n streamVadClone,\n streamVadProcess,\n streamVadReset,\n streamVadDestroy,\n} from \"./wasm-binding.js\";\n\nconst SAMPLE_RATE = 16000;\n\nexport class OmniStreamVAD {\n private handle: number;\n\n private constructor(handle: number) {\n this.handle = handle;\n }\n\n /**\n * Create a new OmniStreamVAD instance.\n * Loads model from CDN (browser), local package (Node.js), or custom source.\n */\n static async create(options: StreamVADConfig = {}): Promise<OmniStreamVAD> {\n await initWasm();\n const M = getModule();\n const modelBuffer = await loadModel(\"stream-vad\", options.modelUrl, options.modelData);\n const handle = streamVadCreate(M, modelBuffer, {\n threshold: options.threshold,\n smoothWindowSize: options.smoothWindowSize,\n padStartFrame: options.padStartFrame,\n minSpeechFrame: options.minSpeechFrame,\n maxSpeechFrame: options.maxSpeechFrame,\n minSilenceFrame: options.minSilenceFrame,\n });\n return new OmniStreamVAD(handle);\n }\n\n /**\n * Create a lightweight clone sharing the same underlying model weights.\n * The clone has fresh per-instance state (empty audio buffer, zeroed cache).\n * This is synchronous and extremely fast — ideal for multi-stream scenarios\n * (e.g., handling multiple WebRTC tracks or concurrent audio sessions).\n */\n clone(): OmniStreamVAD {\n if (!this.handle) throw new Error(\"Cannot clone a disposed instance.\");\n const M = getModule();\n const newHandle = streamVadClone(M, this.handle);\n return new OmniStreamVAD(newHandle);\n }\n\n /**\n * Process one frame of audio (160 int16 samples = 10ms @ 16kHz).\n * Returns null until enough audio is accumulated.\n *\n * Segment-boundary events (isSpeechStart / isSpeechEnd and the matching\n * speech_*_frame indices) come straight from the C-layer state machine\n * (bit-identical to upstream FireRedVAD) — the wrapper is just a marshaller.\n */\n processFrame(pcm160: Int16Array): StreamVADFrameResult | null {\n const M = getModule();\n const ptr = M._malloc(pcm160.length * 2);\n const heap16 = new Int16Array(M.HEAPU8.buffer, ptr, pcm160.length);\n heap16.set(pcm160);\n\n try {\n const result = streamVadProcess(M, this.handle, ptr, pcm160.length);\n if (!result) return null;\n\n return {\n confidence: result.confidence,\n smoothedProb: result.smoothedProb,\n isSpeech: result.isSpeech,\n frameIndex: result.frameIdx,\n isSpeechStart: result.isSpeechStart,\n isSpeechEnd: result.isSpeechEnd,\n speechStartFrame: result.speechStartFrame,\n speechEndFrame: result.speechEndFrame,\n };\n } finally {\n M._free(ptr);\n }\n }\n\n /**\n * Process entire audio at once and return per-frame probabilities.\n * @param audio - Float32Array in [-1, 1] or Int16Array of 16kHz mono PCM\n */\n detectFull(audio: Float32Array | Int16Array): StreamVADFullResult {\n const M = getModule();\n const f32 = prepareDetectFullAudio(audio);\n const audioPtr = copyAudioToHeap(M, f32);\n const probsPtrPtr = M._malloc(4);\n const framesPtr = M._malloc(4);\n\n try {\n const ret = M.ccall(\n \"omni_stream_vad_detect_full\",\n \"number\",\n [\"number\", \"number\", \"number\", \"number\", \"number\"],\n [this.handle, audioPtr, f32.length, probsPtrPtr, framesPtr],\n );\n if (ret !== 0) throw new Error(`StreamVAD detectFull failed: ${ret}`);\n\n const numFrames = M.getValue(framesPtr, \"i32\");\n const probsPtr = M.getValue(probsPtrPtr, \"i32\");\n const probabilities = probsPtr\n ? new Float32Array(new Float32Array(M.HEAPU8.buffer, probsPtr, numFrames))\n : new Float32Array(0);\n if (probsPtr) M._free(probsPtr);\n\n return {\n probabilities,\n numFrames,\n duration: Math.round((f32.length / SAMPLE_RATE) * 1000) / 1000,\n };\n } finally {\n M._free(audioPtr);\n M._free(probsPtrPtr);\n M._free(framesPtr);\n }\n }\n\n /** Reset all internal state (model cache, audio buffer, postprocessor). */\n reset(): void {\n streamVadReset(getModule(), this.handle);\n }\n\n /** Release native resources. */\n dispose(): void {\n if (this.handle) {\n streamVadDestroy(getModule(), this.handle);\n this.handle = 0;\n }\n }\n}\n\nfunction int16ToFloat32(i16: Int16Array): Float32Array {\n const f32 = new Float32Array(i16.length);\n for (let i = 0; i < i16.length; i++) f32[i] = i16[i];\n return f32;\n}\n\nfunction prepareDetectFullAudio(audio: Float32Array | Int16Array): Float32Array {\n if (audio instanceof Int16Array) {\n return int16ToFloat32(audio);\n }\n if (isNormalizedFloat(audio)) {\n const scaled = new Float32Array(audio.length);\n for (let i = 0; i < audio.length; i++) scaled[i] = audio[i] * 32768;\n return scaled;\n }\n return audio;\n}\n\nfunction isNormalizedFloat(audio: Float32Array): boolean {\n const step = Math.max(1, Math.floor(audio.length / 1000));\n let maxAbs = 0;\n for (let i = 0; i < audio.length; i += step) {\n const v = Math.abs(audio[i]);\n if (v > maxAbs) maxAbs = v;\n }\n return maxAbs <= 1.0;\n}\n","/**\n * Audio Event Detection: speech, singing, music (WASM/ncnn backend).\n *\n * Audio format: same as OmniVAD — Int16Array or normalized Float32Array [-1, 1].\n */\n\nimport type { AEDConfig, AEDResult } from \"./types.js\";\nimport {\n initWasm,\n getModule,\n loadModel,\n aedCreate,\n aedDetect,\n aedDestroy,\n DEFAULT_VAD_CONFIG,\n type AudioFormat,\n type AedPostConfig,\n} from \"./wasm-binding.js\";\n\nconst SAMPLE_RATE = 16000;\n\nexport class OmniAED {\n private handle: number;\n private config: AedPostConfig;\n\n private constructor(handle: number, config: AedPostConfig) {\n this.handle = handle;\n this.config = config;\n }\n\n /**\n * Create a new OmniAED instance.\n * Loads model from CDN (browser), local package (Node.js), or custom source.\n */\n static async create(options: AEDConfig = {}): Promise<OmniAED> {\n await initWasm();\n const M = getModule();\n const modelBuffer = await loadModel(\"aed\", options.modelUrl, options.modelData);\n const handle = aedCreate(M, modelBuffer);\n\n const base = {\n smoothWindowSize: options.smoothWindowSize ?? DEFAULT_VAD_CONFIG.smoothWindowSize,\n minSpeechFrames: options.minSpeechFrames ?? DEFAULT_VAD_CONFIG.minSpeechFrames,\n minSilenceFrames: options.minSilenceFrames ?? DEFAULT_VAD_CONFIG.minSilenceFrames,\n maxSpeechFrames: options.maxSpeechFrames ?? DEFAULT_VAD_CONFIG.maxSpeechFrames,\n mergeSilenceFrames: options.mergeSilenceFrames ?? DEFAULT_VAD_CONFIG.mergeSilenceFrames,\n extendSpeechFrames: options.extendSpeechFrames ?? DEFAULT_VAD_CONFIG.extendSpeechFrames,\n };\n\n const config: AedPostConfig = {\n speech: { ...base, threshold: options.speechThreshold ?? 0.4 },\n singing: { ...base, threshold: options.singingThreshold ?? 0.5 },\n music: { ...base, threshold: options.musicThreshold ?? 0.5 },\n };\n return new OmniAED(handle, config);\n }\n\n /**\n * Detect audio events (speech, singing, music).\n *\n * Accepts Int16Array (PCM) or normalized Float32Array in [-1, 1].\n */\n detect(audio: Float32Array | Int16Array): AEDResult {\n const M = getModule();\n const { ptr, length, format } = prepareAudio(M, audio);\n const duration = Math.round((length / SAMPLE_RATE) * 1000) / 1000;\n\n try {\n const events = aedDetect(M, this.handle, ptr, length, this.config, format);\n return {\n duration,\n events,\n ratios: computeCoverageRatios(events, duration),\n };\n } finally {\n M._free(ptr);\n }\n }\n\n /** Release native resources. */\n dispose(): void {\n if (this.handle) {\n aedDestroy(getModule(), this.handle);\n this.handle = 0;\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction prepareAudio(M: any, audio: Float32Array | Int16Array): { ptr: number; length: number; format: AudioFormat } {\n const f32 = audio instanceof Int16Array ? int16ToNormalizedFloat32(audio) : audio;\n const ptr = M._malloc(f32.length * 4);\n const heap = new Float32Array(M.HEAPU8.buffer, ptr, f32.length);\n heap.set(f32);\n return { ptr, length: f32.length, format: \"f32\" };\n}\n\nfunction int16ToNormalizedFloat32(i16: Int16Array): Float32Array {\n const f32 = new Float32Array(i16.length);\n for (let i = 0; i < i16.length; i++) f32[i] = i16[i] / 32768;\n return f32;\n}\n\nfunction computeCoverageRatios(\n events: Record<string, Array<[number, number]>>,\n duration: number,\n): Record<string, number> {\n const ratios: Record<string, number> = {\n speech: 0,\n singing: 0,\n music: 0,\n };\n\n if (duration <= 0) return ratios;\n\n for (const cls of Object.keys(ratios)) {\n const covered = (events[cls] ?? []).reduce((sum, [start, end]) => sum + Math.max(0, end - start), 0);\n ratios[cls] = Math.round(Math.min(1, covered / duration) * 1e6) / 1e6;\n }\n\n return ratios;\n}\n","/**\n * Pure-algorithm chunking utility — wraps the C function omni_merge_chunks\n * compiled into the WASM module.\n *\n * WhisperX-style binarize+merge, minus the binarize half because OmniVAD\n * already returns binarized timestamps.\n *\n * Usage:\n *\n * import { mergeChunks } from \"omnivad\";\n *\n * const chunks = await mergeChunks(\n * [[0.0, 5.0], [6.0, 10.0]],\n * { maxChunkSecs: 30.0, maxGapSecs: 2.0 }\n * );\n * // [{ start: 0, end: 10, segStartIdx: 0, segCount: 2 }]\n */\n\nimport type { ChunkOptions, ChunkResult } from \"./types.js\";\nimport {\n chunkMerge,\n DEFAULT_CHUNK_CONFIG,\n getModule,\n initWasm,\n type ChunkConfig,\n} from \"./wasm-binding.js\";\n\n/**\n * Merge a sorted array of [start, end] speech segments into duration-bounded\n * chunks.\n *\n * Lazily initializes the WASM module on first call (so the caller doesn't have\n * to await `initWasm()` separately). Subsequent calls reuse the cached module.\n *\n * @param segments array of [start, end] pairs in seconds, sorted by start\n * @param options chunking configuration; missing fields fall back to\n * {@link DEFAULT_CHUNK_CONFIG}\n */\nexport async function mergeChunks(\n segments: Array<[number, number]>,\n options: ChunkOptions = {},\n): Promise<ChunkResult[]> {\n await initWasm();\n const M = getModule();\n\n const cfg: ChunkConfig = {\n maxChunkSecs: options.maxChunkSecs ?? DEFAULT_CHUNK_CONFIG.maxChunkSecs,\n maxGapSecs: options.maxGapSecs ?? DEFAULT_CHUNK_CONFIG.maxGapSecs,\n padOnsetSecs: options.padOnsetSecs ?? DEFAULT_CHUNK_CONFIG.padOnsetSecs,\n padOffsetSecs: options.padOffsetSecs ?? DEFAULT_CHUNK_CONFIG.padOffsetSecs,\n minSpeechSecs: options.minSpeechSecs ?? DEFAULT_CHUNK_CONFIG.minSpeechSecs,\n minSilenceSecs: options.minSilenceSecs ?? DEFAULT_CHUNK_CONFIG.minSilenceSecs,\n mode: options.mode ?? DEFAULT_CHUNK_CONFIG.mode,\n };\n\n const records = chunkMerge(M, segments, cfg);\n return records.map((r) => ({\n start: r.start,\n end: r.end,\n segStartIdx: r.segStartIdx,\n segCount: r.segCount,\n }));\n}\n\nexport { DEFAULT_CHUNK_CONFIG } from \"./wasm-binding.js\";\nexport type { ChunkOptions, ChunkResult } from \"./types.js\";\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -14,23 +14,27 @@ interface AEDResult {
|
|
|
14
14
|
/** Detected duration coverage ratio for each event type */
|
|
15
15
|
ratios: Record<string, number>;
|
|
16
16
|
}
|
|
17
|
-
/** Per-frame result from streaming VAD
|
|
17
|
+
/** Per-frame result from streaming VAD.
|
|
18
|
+
*
|
|
19
|
+
* Bit-identical to upstream FireRedVAD's StreamVadFrameResult: every
|
|
20
|
+
* successful processFrame() call carries both per-frame probabilities
|
|
21
|
+
* AND segment-boundary events (no external segmenter needed). */
|
|
18
22
|
interface StreamVADFrameResult {
|
|
19
|
-
/** Raw probability from model output */
|
|
23
|
+
/** Raw probability from model output [0, 1] */
|
|
20
24
|
confidence: number;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/**
|
|
25
|
+
/** Causal moving-average of confidence (window = smoothWindowSize) */
|
|
26
|
+
smoothedProb: number;
|
|
27
|
+
/** smoothedProb >= threshold */
|
|
24
28
|
isSpeech: boolean;
|
|
25
29
|
/** 1-based frame index of the emitted frame */
|
|
26
30
|
frameIndex: number;
|
|
27
|
-
/** True
|
|
31
|
+
/** True on the frame that confirms a new SPEECH segment */
|
|
28
32
|
isSpeechStart: boolean;
|
|
29
|
-
/** True
|
|
33
|
+
/** True on the frame that confirms a SPEECH segment end */
|
|
30
34
|
isSpeechEnd: boolean;
|
|
31
|
-
/**
|
|
35
|
+
/** 1-based start frame of the segment when isSpeechStart, else -1 */
|
|
32
36
|
speechStartFrame: number;
|
|
33
|
-
/**
|
|
37
|
+
/** 1-based end frame of the segment when isSpeechEnd, else -1 */
|
|
34
38
|
speechEndFrame: number;
|
|
35
39
|
}
|
|
36
40
|
/** Full-audio streaming-model output */
|
|
@@ -57,7 +61,7 @@ interface VADConfig extends ModelSource {
|
|
|
57
61
|
smoothWindowSize?: number;
|
|
58
62
|
/** Minimum speech segment length in frames (default: 20) */
|
|
59
63
|
minSpeechFrames?: number;
|
|
60
|
-
/** Maximum speech segment length in frames before splitting (default:
|
|
64
|
+
/** Maximum speech segment length in frames before splitting (default: 3000 = 30s; matches Whisper) */
|
|
61
65
|
maxSpeechFrames?: number;
|
|
62
66
|
/** Minimum silence segment length in frames for state machine (default: 20) */
|
|
63
67
|
minSilenceFrames?: number;
|
|
@@ -73,10 +77,79 @@ interface AEDConfig extends VADConfig {
|
|
|
73
77
|
/** Music probability threshold (default: 0.5) */
|
|
74
78
|
musicThreshold?: number;
|
|
75
79
|
}
|
|
76
|
-
/** Configuration for streaming VAD
|
|
80
|
+
/** Configuration for streaming VAD.
|
|
81
|
+
*
|
|
82
|
+
* Bit-identical to upstream FireRedStreamVadConfig — every parameter
|
|
83
|
+
* has the same name (without the speech_ prefix) and the same default. */
|
|
77
84
|
interface StreamVADConfig extends ModelSource {
|
|
78
|
-
/** Speech
|
|
79
|
-
|
|
85
|
+
/** Speech activation threshold [0, 1] (default: 0.5). */
|
|
86
|
+
threshold?: number;
|
|
87
|
+
/** Causal moving-average window in frames (default: 5). */
|
|
88
|
+
smoothWindowSize?: number;
|
|
89
|
+
/** Extend confirmed segment START backward by N frames (default: 5;
|
|
90
|
+
* clamped to >= smoothWindowSize internally). */
|
|
91
|
+
padStartFrame?: number;
|
|
92
|
+
/** Min continuous speech frames to confirm START (default: 8 = 80ms). */
|
|
93
|
+
minSpeechFrame?: number;
|
|
94
|
+
/** Force-split when SPEECH-state count hits this (default: 2000 = 20s). */
|
|
95
|
+
maxSpeechFrame?: number;
|
|
96
|
+
/** Min continuous silence frames to confirm END (default: 20 = 200ms). */
|
|
97
|
+
minSilenceFrame?: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Chunk packing strategy. Both modes honor `maxChunkSecs` and `maxGapSecs` as
|
|
101
|
+
* hard constraints — they only differ in WHERE the cut lands.
|
|
102
|
+
*
|
|
103
|
+
* - `"greedy"` — sequential append; cuts at the first point that violates
|
|
104
|
+
* a constraint. Recommended for **fixed-length-input ASR** like Whisper /
|
|
105
|
+
* whisperX (which pad to 30s anyway).
|
|
106
|
+
* - `"longest_gap"` — recursive split at the longest internal pause until
|
|
107
|
+
* every chunk satisfies both constraints. Falls back to equal hard-split
|
|
108
|
+
* when a single segment exceeds `maxChunkSecs`. Recommended for
|
|
109
|
+
* **variable-length-input models** (forced alignment, TTS, encoder-style
|
|
110
|
+
* ASR) — splits at natural pauses, no fixed-length padding required.
|
|
111
|
+
* **NOTE: This is NOT how WhisperX packs chunks** — WhisperX uses greedy
|
|
112
|
+
* packing (`Binarize(max_duration=...)` + sequential append). For
|
|
113
|
+
* WhisperX-equivalent behavior pass `mode: "greedy"` (the default).
|
|
114
|
+
*/
|
|
115
|
+
type ChunkMode$1 = "greedy" | "longest_gap";
|
|
116
|
+
/**
|
|
117
|
+
* Configuration for {@link mergeChunks}. Mirrors C struct OmniChunkConfig.
|
|
118
|
+
* All fields are optional in the public API; defaults match
|
|
119
|
+
* {@link DEFAULT_CHUNK_CONFIG}.
|
|
120
|
+
*/
|
|
121
|
+
interface ChunkOptions {
|
|
122
|
+
/** Hard upper bound on chunk duration in seconds. Must be > 0. Default: 30. */
|
|
123
|
+
maxChunkSecs?: number;
|
|
124
|
+
/** Split if the gap between adjacent segments exceeds this. Pass `Infinity`
|
|
125
|
+
* to disable. Default: `Infinity`. Honored by both modes. */
|
|
126
|
+
maxGapSecs?: number;
|
|
127
|
+
/** Extend each chunk start backward by this many seconds (clamped to >= 0).
|
|
128
|
+
* Default: 0.04. */
|
|
129
|
+
padOnsetSecs?: number;
|
|
130
|
+
/** Extend each chunk end forward by this many seconds. Default: 0.04. */
|
|
131
|
+
padOffsetSecs?: number;
|
|
132
|
+
/** Drop input segments shorter than this many seconds. Default: 0.0.
|
|
133
|
+
* Pairs with VAD `minSpeechFrames` (frame-domain equivalent). */
|
|
134
|
+
minSpeechSecs?: number;
|
|
135
|
+
/** Pre-merge consecutive segments whose silence gap is shorter than this.
|
|
136
|
+
* Default: 0.20 (matches VAD `minSilenceFrames=20` @ 10ms frame shift). */
|
|
137
|
+
minSilenceSecs?: number;
|
|
138
|
+
/** Packing strategy. Default: `"greedy"`. */
|
|
139
|
+
mode?: ChunkMode$1;
|
|
140
|
+
}
|
|
141
|
+
/** A single chunk emitted by {@link mergeChunks}. */
|
|
142
|
+
interface ChunkResult {
|
|
143
|
+
/** Chunk start time (seconds), with `padOnsetSecs` applied (clamped to >= 0). */
|
|
144
|
+
start: number;
|
|
145
|
+
/** Chunk end time (seconds), with `padOffsetSecs` applied. */
|
|
146
|
+
end: number;
|
|
147
|
+
/** Index of the first input segment included in this chunk. Refers to the
|
|
148
|
+
* *post-filter* segment list — segments dropped by `minSpeechSecs` and
|
|
149
|
+
* pre-merged by `minSilenceSecs` are not counted. */
|
|
150
|
+
segStartIdx: number;
|
|
151
|
+
/** Number of input segments included in this chunk. */
|
|
152
|
+
segCount: number;
|
|
80
153
|
}
|
|
81
154
|
|
|
82
155
|
/**
|
|
@@ -113,8 +186,6 @@ declare class OmniVAD {
|
|
|
113
186
|
|
|
114
187
|
declare class OmniStreamVAD {
|
|
115
188
|
private handle;
|
|
116
|
-
private inSpeech;
|
|
117
|
-
private speechStartFrame;
|
|
118
189
|
private constructor();
|
|
119
190
|
/**
|
|
120
191
|
* Create a new OmniStreamVAD instance.
|
|
@@ -131,6 +202,10 @@ declare class OmniStreamVAD {
|
|
|
131
202
|
/**
|
|
132
203
|
* Process one frame of audio (160 int16 samples = 10ms @ 16kHz).
|
|
133
204
|
* Returns null until enough audio is accumulated.
|
|
205
|
+
*
|
|
206
|
+
* Segment-boundary events (isSpeechStart / isSpeechEnd and the matching
|
|
207
|
+
* speech_*_frame indices) come straight from the C-layer state machine
|
|
208
|
+
* (bit-identical to upstream FireRedVAD) — the wrapper is just a marshaller.
|
|
134
209
|
*/
|
|
135
210
|
processFrame(pcm160: Int16Array): StreamVADFrameResult | null;
|
|
136
211
|
/**
|
|
@@ -138,7 +213,7 @@ declare class OmniStreamVAD {
|
|
|
138
213
|
* @param audio - Float32Array in [-1, 1] or Int16Array of 16kHz mono PCM
|
|
139
214
|
*/
|
|
140
215
|
detectFull(audio: Float32Array | Int16Array): StreamVADFullResult;
|
|
141
|
-
/** Reset all internal state. */
|
|
216
|
+
/** Reset all internal state (model cache, audio buffer, postprocessor). */
|
|
142
217
|
reset(): void;
|
|
143
218
|
/** Release native resources. */
|
|
144
219
|
dispose(): void;
|
|
@@ -175,9 +250,9 @@ declare class OmniAED {
|
|
|
175
250
|
*/
|
|
176
251
|
type EmscriptenModule = any;
|
|
177
252
|
/** Package version — used to construct default CDN URLs. */
|
|
178
|
-
declare const VERSION = "0.2.
|
|
253
|
+
declare const VERSION = "0.2.8";
|
|
179
254
|
/** Default CDN base for model files (jsDelivr serves npm package contents). */
|
|
180
|
-
declare const DEFAULT_CDN_BASE = "https://cdn.jsdelivr.net/npm/omnivad@0.2.
|
|
255
|
+
declare const DEFAULT_CDN_BASE = "https://cdn.jsdelivr.net/npm/omnivad@0.2.8/models";
|
|
181
256
|
/** Model filenames keyed by type. */
|
|
182
257
|
declare const MODEL_FILES: {
|
|
183
258
|
readonly vad: "vad.omnivad";
|
|
@@ -200,5 +275,63 @@ declare function initWasm(wasmLocator?: (filename: string) => string): Promise<E
|
|
|
200
275
|
* 4. Browser — fetch from jsDelivr CDN
|
|
201
276
|
*/
|
|
202
277
|
declare function loadModel(modelType: ModelType, modelUrl?: string | URL, modelData?: ArrayBuffer): Promise<ArrayBuffer>;
|
|
278
|
+
/**
|
|
279
|
+
* Chunking strategy:
|
|
280
|
+
* - "greedy" — sequential append. Recommended for fixed-length-input ASR
|
|
281
|
+
* (Whisper / whisperX, which pad to 30s anyway).
|
|
282
|
+
* - "longest_gap" — recursive split at longest pause; falls back to hard-split
|
|
283
|
+
* when a single segment exceeds maxChunkSecs. Recommended for
|
|
284
|
+
* variable-length-input models (forced alignment, TTS,
|
|
285
|
+
* encoder-style ASR); no fixed-length padding required.
|
|
286
|
+
*/
|
|
287
|
+
type ChunkMode = "greedy" | "longest_gap";
|
|
288
|
+
/** Configuration for omni_merge_chunks (matches C struct OmniChunkConfig, 28 bytes) */
|
|
289
|
+
interface ChunkConfig {
|
|
290
|
+
maxChunkSecs: number;
|
|
291
|
+
maxGapSecs: number;
|
|
292
|
+
padOnsetSecs: number;
|
|
293
|
+
padOffsetSecs: number;
|
|
294
|
+
minSpeechSecs: number;
|
|
295
|
+
minSilenceSecs: number;
|
|
296
|
+
mode: ChunkMode;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Default chunk config. Mirrors C-side omni_chunk_config_default(); kept in
|
|
300
|
+
* TS so callers don't need a roundtrip into WASM just to read defaults.
|
|
301
|
+
*
|
|
302
|
+
* Defaults: max_chunk_secs matches Whisper's 30s input window.
|
|
303
|
+
*/
|
|
304
|
+
declare const DEFAULT_CHUNK_CONFIG: ChunkConfig;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Pure-algorithm chunking utility — wraps the C function omni_merge_chunks
|
|
308
|
+
* compiled into the WASM module.
|
|
309
|
+
*
|
|
310
|
+
* WhisperX-style binarize+merge, minus the binarize half because OmniVAD
|
|
311
|
+
* already returns binarized timestamps.
|
|
312
|
+
*
|
|
313
|
+
* Usage:
|
|
314
|
+
*
|
|
315
|
+
* import { mergeChunks } from "omnivad";
|
|
316
|
+
*
|
|
317
|
+
* const chunks = await mergeChunks(
|
|
318
|
+
* [[0.0, 5.0], [6.0, 10.0]],
|
|
319
|
+
* { maxChunkSecs: 30.0, maxGapSecs: 2.0 }
|
|
320
|
+
* );
|
|
321
|
+
* // [{ start: 0, end: 10, segStartIdx: 0, segCount: 2 }]
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Merge a sorted array of [start, end] speech segments into duration-bounded
|
|
326
|
+
* chunks.
|
|
327
|
+
*
|
|
328
|
+
* Lazily initializes the WASM module on first call (so the caller doesn't have
|
|
329
|
+
* to await `initWasm()` separately). Subsequent calls reuse the cached module.
|
|
330
|
+
*
|
|
331
|
+
* @param segments array of [start, end] pairs in seconds, sorted by start
|
|
332
|
+
* @param options chunking configuration; missing fields fall back to
|
|
333
|
+
* {@link DEFAULT_CHUNK_CONFIG}
|
|
334
|
+
*/
|
|
335
|
+
declare function mergeChunks(segments: Array<[number, number]>, options?: ChunkOptions): Promise<ChunkResult[]>;
|
|
203
336
|
|
|
204
|
-
export { type AEDConfig, type AEDResult, DEFAULT_CDN_BASE, OmniAED as FireRedAED, OmniStreamVAD as FireRedStreamVAD, OmniVAD as FireRedVAD, MODEL_FILES, type ModelSource, OmniAED, OmniStreamVAD, OmniVAD, type StreamVADConfig, type StreamVADFrameResult, type StreamVADFullResult, type VADConfig, type VADResult, VERSION, initWasm, loadModel };
|
|
337
|
+
export { type AEDConfig, type AEDResult, type ChunkOptions, type ChunkResult, DEFAULT_CDN_BASE, DEFAULT_CHUNK_CONFIG, OmniAED as FireRedAED, OmniStreamVAD as FireRedStreamVAD, OmniVAD as FireRedVAD, MODEL_FILES, type ModelSource, OmniAED, OmniStreamVAD, OmniVAD, type StreamVADConfig, type StreamVADFrameResult, type StreamVADFullResult, type VADConfig, type VADResult, VERSION, initWasm, loadModel, mergeChunks };
|