@livekit/agents-plugin-krisp 1.4.9

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.
Files changed (48) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +144 -0
  3. package/dist/_krisp.cjs +267 -0
  4. package/dist/_krisp.cjs.map +1 -0
  5. package/dist/_krisp.d.cts +43 -0
  6. package/dist/_krisp.d.ts +43 -0
  7. package/dist/_krisp.d.ts.map +1 -0
  8. package/dist/_krisp.js +241 -0
  9. package/dist/_krisp.js.map +1 -0
  10. package/dist/_krisp_sdk.d.cjs +2 -0
  11. package/dist/_krisp_sdk.d.cjs.map +1 -0
  12. package/dist/_krisp_sdk.d.js +1 -0
  13. package/dist/_krisp_sdk.d.js.map +1 -0
  14. package/dist/auth.cjs +69 -0
  15. package/dist/auth.cjs.map +1 -0
  16. package/dist/auth.d.cts +57 -0
  17. package/dist/auth.d.ts +57 -0
  18. package/dist/auth.d.ts.map +1 -0
  19. package/dist/auth.js +41 -0
  20. package/dist/auth.js.map +1 -0
  21. package/dist/index.cjs +55 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +24 -0
  24. package/dist/index.d.ts +24 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +31 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/log.cjs +30 -0
  29. package/dist/log.cjs.map +1 -0
  30. package/dist/log.d.cts +3 -0
  31. package/dist/log.d.ts +3 -0
  32. package/dist/log.d.ts.map +1 -0
  33. package/dist/log.js +6 -0
  34. package/dist/log.js.map +1 -0
  35. package/dist/viva_filter.cjs +103 -0
  36. package/dist/viva_filter.cjs.map +1 -0
  37. package/dist/viva_filter.d.cts +75 -0
  38. package/dist/viva_filter.d.ts +75 -0
  39. package/dist/viva_filter.d.ts.map +1 -0
  40. package/dist/viva_filter.js +81 -0
  41. package/dist/viva_filter.js.map +1 -0
  42. package/package.json +54 -0
  43. package/src/_krisp.ts +366 -0
  44. package/src/_krisp_sdk.d.ts +57 -0
  45. package/src/auth.ts +109 -0
  46. package/src/index.ts +78 -0
  47. package/src/log.ts +7 -0
  48. package/src/viva_filter.ts +191 -0
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@livekit/agents-plugin-krisp",
3
+ "version": "1.4.9",
4
+ "description": "Krisp Audio plugin for LiveKit Node Agents",
5
+ "main": "dist/index.js",
6
+ "require": "dist/index.cjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.cts",
15
+ "default": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "author": "LiveKit",
19
+ "type": "module",
20
+ "repository": "git@github.com:livekit/agents-js.git",
21
+ "license": "Apache-2.0",
22
+ "files": [
23
+ "dist",
24
+ "src",
25
+ "README.md"
26
+ ],
27
+ "devDependencies": {
28
+ "@livekit/rtc-node": "^0.13.31",
29
+ "@microsoft/api-extractor": "^7.35.0",
30
+ "@types/ws": "^8.5.10",
31
+ "pino": "^8.19.0",
32
+ "tsup": "^8.3.5",
33
+ "typescript": "^5.0.0",
34
+ "@livekit/agents-plugins-test": "1.5.5",
35
+ "@livekit/agents-plugin-openai": "1.5.5",
36
+ "@livekit/agents": "1.5.5"
37
+ },
38
+ "dependencies": {
39
+ "@livekit/plugins-krisp-viva-internal": "0.2.0"
40
+ },
41
+ "peerDependencies": {
42
+ "@livekit/rtc-node": "^0.13.31",
43
+ "@livekit/agents": "1.5.5"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup --onSuccess \"pnpm build:types\"",
47
+ "build:types": "tsc --declaration --emitDeclarationOnly && node ../../scripts/copyDeclarationOutput.js",
48
+ "clean": "rm -rf dist",
49
+ "clean:build": "pnpm clean && pnpm build",
50
+ "lint": "eslint -f unix \"src/**/*.{ts,js}\"",
51
+ "api:check": "api-extractor run --typescript-compiler-folder ../../node_modules/typescript",
52
+ "api:update": "api-extractor run --local --typescript-compiler-folder ../../node_modules/typescript --verbose"
53
+ }
54
+ }
package/src/_krisp.ts ADDED
@@ -0,0 +1,366 @@
1
+ // SPDX-FileCopyrightText: 2026 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * License-mode Krisp internals.
7
+ *
8
+ * This module is private to the plugin. It wraps the public
9
+ * `@krisp/viva-node-sdk` and exposes a {@link KrispLicenseFrameProcessor} that
10
+ * {@link krispVivaFilter} instantiates when the user picks
11
+ * {@link KrispLicenseAuthProvider}.
12
+ *
13
+ * Wires the documented `@krisp/viva-node-sdk` surface (https://sdk-docs.krisp.ai):
14
+ * `globalInit(workingDir, licenseKey)`, the `enums.SamplingRate` and
15
+ * `enums.FrameDuration` tables, `NcInt16.create(config)`, per-frame `process`
16
+ * (byte `Buffer` in and out), and the session/global destroy calls. The license
17
+ * key is read from `KRISP_VIVA_SDK_LICENSE_KEY` and passed to `globalInit`.
18
+ *
19
+ * The frame buffering / reframing logic is ported from the Python plugin.
20
+ */
21
+ import type { KrispEnumMember, KrispModule, KrispNcSession } from '@krisp/viva-node-sdk';
22
+ import { AudioFrame, FrameProcessor } from '@livekit/rtc-node';
23
+ import { createRequire } from 'node:module';
24
+ import { log } from './log.js';
25
+
26
+ const require = createRequire(import.meta.url);
27
+
28
+ const SUPPORTED_SAMPLE_RATES: Array<number> = [8000, 16000, 24000, 32000, 44100, 48000] as const;
29
+ const SUPPORTED_FRAME_DURATIONS_MS: Array<number> = [10, 15, 20, 30, 32] as const;
30
+
31
+ /** Map a sample rate (Hz) to the SDK's `enums.SamplingRate.Sr<rate>Hz` member. */
32
+ function samplingRateEnum(mod: KrispModule, sampleRate: number): KrispEnumMember {
33
+ const value = mod.enums?.SamplingRate?.[`Sr${sampleRate}Hz`];
34
+ if (value === undefined) {
35
+ throw new Error(
36
+ `Unsupported sample rate: ${sampleRate} Hz. ` +
37
+ `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,
38
+ );
39
+ }
40
+ return value;
41
+ }
42
+
43
+ /** Map a frame duration (ms) to the SDK's `enums.FrameDuration.Fd<ms>ms` member. */
44
+ function frameDurationEnum(mod: KrispModule, frameDurationMs: number): KrispEnumMember {
45
+ const value = mod.enums?.FrameDuration?.[`Fd${frameDurationMs}ms`];
46
+ if (value === undefined) {
47
+ throw new Error(
48
+ `Unsupported frame duration: ${frameDurationMs} ms. ` +
49
+ `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,
50
+ );
51
+ }
52
+ return value;
53
+ }
54
+
55
+ /**
56
+ * Process-singleton ref counter for the proprietary `@krisp/viva-node-sdk`.
57
+ *
58
+ * Krisp's `globalInit` / `globalDestroy` are process-global, so this manager
59
+ * keeps a single SDK alive across multiple license-mode frame processors. The
60
+ * module is lazy-required on first acquire — never loaded in cloud-only
61
+ * deployments.
62
+ */
63
+ class KrispLicenseSdkManager {
64
+ private static module: KrispModule | null = null;
65
+ private static referenceCount = 0;
66
+
67
+ /** Acquire a reference, returning the loaded `@krisp/viva-node-sdk` module. */
68
+ static acquire(): KrispModule {
69
+ if (this.referenceCount === 0) {
70
+ let mod: KrispModule;
71
+ try {
72
+ mod = require('@krisp/viva-node-sdk');
73
+ } catch {
74
+ throw new Error(
75
+ '@krisp/viva-node-sdk is not installed. Install the proprietary Krisp Node SDK ' +
76
+ '(`pnpm add @krisp/viva-node-sdk`) and provide a .kef model, or use the ' +
77
+ 'default LiveKit Cloud auth provider (auth.livekitCloud()).',
78
+ );
79
+ }
80
+
81
+ // Working dir '' uses the SDK default; the license key comes from the
82
+ // environment (KRISP_VIVA_SDK_LICENSE_KEY) and is passed to globalInit.
83
+ const licenseKey = process.env.KRISP_VIVA_SDK_LICENSE_KEY;
84
+ if (licenseKey) {
85
+ mod.globalInit('', licenseKey);
86
+ } else {
87
+ mod.globalInit('');
88
+ }
89
+
90
+ this.module = mod;
91
+ log().debug('Krisp Audio SDK (license) initialized');
92
+ }
93
+ this.referenceCount += 1;
94
+ log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);
95
+ // Non-null once refCount > 0: release() only nulls the module at refCount 0.
96
+ return this.module!;
97
+ }
98
+
99
+ /** Release a reference, destroying the SDK on the last release. */
100
+ static release(): void {
101
+ if (this.referenceCount === 0) {
102
+ return;
103
+ }
104
+ this.referenceCount -= 1;
105
+ log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);
106
+ if (this.referenceCount === 0 && this.module !== null) {
107
+ try {
108
+ this.module.globalDestroy();
109
+ log().debug('Krisp Audio SDK (license) destroyed');
110
+ } catch (e) {
111
+ log().error(`Error during Krisp SDK cleanup: ${e}`);
112
+ } finally {
113
+ this.module = null;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ function concatInt16(a: Int16Array, b: Int16Array): Int16Array {
120
+ const out = new Int16Array(a.length + b.length);
121
+ out.set(a, 0);
122
+ out.set(b, a.length);
123
+ return out;
124
+ }
125
+
126
+ /**
127
+ * Reinterpret a byte buffer of interleaved int16 PCM as an `Int16Array`. Copies
128
+ * into a fresh, 2-byte-aligned buffer — a native-returned `Buffer` may sit at an
129
+ * odd `byteOffset` in a pooled `ArrayBuffer`, which a zero-copy `Int16Array`
130
+ * view cannot represent.
131
+ */
132
+ function bufferToInt16(buf: Buffer): Int16Array {
133
+ const usableBytes = buf.byteLength - (buf.byteLength % 2);
134
+ const copy = buf.buffer.slice(buf.byteOffset, buf.byteOffset + usableBytes);
135
+ return new Int16Array(copy);
136
+ }
137
+
138
+ function clampLevel(value: number): number {
139
+ return Math.max(0, Math.min(100, Math.round(value)));
140
+ }
141
+
142
+ export interface KrispLicenseFrameProcessorOptions {
143
+ modelPath: string;
144
+ noiseSuppressionLevel: number;
145
+ frameDurationMs: number;
146
+ }
147
+
148
+ /**
149
+ * License-mode FrameProcessor wrapping `@krisp/viva-node-sdk`.
150
+ *
151
+ * Internal implementation detail — users call `voiceIsolation()` and the facade
152
+ * selects this when the auth provider is {@link KrispLicenseAuthProvider}.
153
+ *
154
+ * The buffering strategy mirrors the Python plugin: Krisp processes fixed-size
155
+ * chunks (`frameDurationMs` worth of samples) but input frames may arrive at any
156
+ * size, so incoming samples accumulate in {@link inBuf}, are processed one whole
157
+ * chunk at a time, and results queue in {@link outBuf}. Each call emits whatever
158
+ * processed audio is ready (never zero-padded — see {@link process}), so the
159
+ * output frame size floats and real audio is never interrupted by silence.
160
+ */
161
+ export class KrispLicenseFrameProcessor extends FrameProcessor<AudioFrame> {
162
+ private enabled = true;
163
+
164
+ private sdkAcquired = false;
165
+ private module: KrispModule;
166
+ private session: KrispNcSession | null = null;
167
+ private level: number;
168
+ private readonly frameDurationMs: number;
169
+ private readonly modelPath: string;
170
+ private sampleRate: number | null = null;
171
+ private chunkSamples: number | null = null;
172
+ private warnedChannels = false;
173
+ private inBuf: Int16Array = new Int16Array(0);
174
+ private outBuf: Int16Array = new Int16Array(0);
175
+
176
+ constructor(opts: KrispLicenseFrameProcessorOptions) {
177
+ super();
178
+ this.level = clampLevel(opts.noiseSuppressionLevel);
179
+ this.frameDurationMs = opts.frameDurationMs;
180
+ this.modelPath = opts.modelPath;
181
+
182
+ if (!SUPPORTED_FRAME_DURATIONS_MS.includes(this.frameDurationMs)) {
183
+ throw new Error(
184
+ `Unsupported frame duration: ${this.frameDurationMs} ms. ` +
185
+ `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,
186
+ );
187
+ }
188
+
189
+ this.module = KrispLicenseSdkManager.acquire();
190
+ this.sdkAcquired = true;
191
+
192
+ try {
193
+ // Pre-load the model now to fail fast on a bad license/model path. The
194
+ // session is recreated automatically if the first frame arrives at a
195
+ // different sample rate.
196
+ this.createSession(16000);
197
+ log().info('Krisp license frame processor initialized (adapts to input sample rate)');
198
+ } catch (e) {
199
+ this.teardown();
200
+ throw e;
201
+ }
202
+ }
203
+
204
+ private createSession(sampleRate: number): void {
205
+ if (this.session !== null && this.sampleRate === sampleRate) {
206
+ return;
207
+ }
208
+ if (!SUPPORTED_SAMPLE_RATES.includes(sampleRate as never)) {
209
+ throw new Error(
210
+ `Unsupported sample rate: ${sampleRate} Hz. ` +
211
+ `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,
212
+ );
213
+ }
214
+
215
+ log().info(`Creating Krisp session for sample rate: ${sampleRate}Hz`);
216
+
217
+ // Free the previous session (if any) before replacing it on a rate change.
218
+ if (this.session !== null) {
219
+ try {
220
+ this.session.destroy();
221
+ } catch (e) {
222
+ log().error(`Error destroying Krisp session: ${e}`);
223
+ }
224
+ this.session = null;
225
+ }
226
+
227
+ // Int16 noise-cancellation session. Our AudioFrame samples are int16 PCM, so
228
+ // NcInt16 avoids a float round-trip (the docs' Node example shows the NcFloat
229
+ // sibling). Output sample rate is pinned to the input rate — we only filter.
230
+ const inputSampleRate = samplingRateEnum(this.module, sampleRate);
231
+ const config = {
232
+ inputSampleRate,
233
+ inputFrameDuration: frameDurationEnum(this.module, this.frameDurationMs),
234
+ outputSampleRate: inputSampleRate,
235
+ modelInfo: { path: this.modelPath },
236
+ };
237
+ this.session = this.module.NcInt16.create(config);
238
+ this.sampleRate = sampleRate;
239
+ this.chunkSamples = Math.floor((sampleRate * this.frameDurationMs) / 1000);
240
+ // The pending/processed buffers belong to the old rate; start fresh.
241
+ this.inBuf = new Int16Array(0);
242
+ this.outBuf = new Int16Array(0);
243
+ }
244
+
245
+ isEnabled(): boolean {
246
+ return this.enabled;
247
+ }
248
+
249
+ setEnabled(enabled: boolean): void {
250
+ if (this.enabled === enabled) {
251
+ return;
252
+ }
253
+ this.enabled = enabled;
254
+ // Drop buffered audio across the transition: while disabled, process()
255
+ // returns raw frames without draining, so a partial input chunk (inBuf) and
256
+ // processed-but-unemitted output (outBuf) captured before the mute would
257
+ // otherwise replay on re-enable and produce a discontinuity.
258
+ this.inBuf = new Int16Array(0);
259
+ this.outBuf = new Int16Array(0);
260
+ }
261
+
262
+ get noiseSuppressionLevel(): number {
263
+ return this.level;
264
+ }
265
+
266
+ setNoiseSuppressionLevel(value: number): void {
267
+ // Applied on the next processed frame — the level is passed per-call to the
268
+ // Krisp session, so no session recreation is needed.
269
+ this.level = clampLevel(value);
270
+ }
271
+
272
+ process(frame: AudioFrame): AudioFrame {
273
+ if (!this.enabled) {
274
+ return frame;
275
+ }
276
+
277
+ if (frame.channels !== 1) {
278
+ if (!this.warnedChannels) {
279
+ log().warn(
280
+ `Krisp filter not applied: expected mono audio but got ${frame.channels} ` +
281
+ 'channels; frames are passed through unprocessed.',
282
+ );
283
+ this.warnedChannels = true;
284
+ }
285
+ return frame;
286
+ }
287
+
288
+ // Adapt to the input sample rate, recreating the session on a change.
289
+ if (this.session === null || this.sampleRate !== frame.sampleRate) {
290
+ this.createSession(frame.sampleRate);
291
+ }
292
+
293
+ const chunk = this.chunkSamples!;
294
+
295
+ // Accumulate the incoming samples and process every whole chunk available.
296
+ this.inBuf = concatInt16(this.inBuf, frame.data);
297
+
298
+ const nChunks = Math.floor(this.inBuf.length / chunk);
299
+ if (nChunks > 0) {
300
+ const consumed = nChunks * chunk;
301
+ const pending = this.inBuf.subarray(0, consumed);
302
+ this.inBuf = this.inBuf.slice(consumed);
303
+
304
+ for (let i = 0; i < nChunks; i++) {
305
+ const chunkIn = pending.subarray(i * chunk, (i + 1) * chunk);
306
+ let chunkOut: Int16Array;
307
+ try {
308
+ // The SDK takes/returns byte buffers of interleaved int16 PCM, so wrap
309
+ // the input samples as a Buffer view and reinterpret the returned
310
+ // Buffer's bytes as int16 samples (its `.length` is bytes = samples×2).
311
+ const inputBuf = Buffer.from(chunkIn.buffer, chunkIn.byteOffset, chunkIn.byteLength);
312
+ // Non-null: the guard above (re)creates the session or throws.
313
+ const outputBuf = this.session!.process(inputBuf, this.level);
314
+ chunkOut = bufferToInt16(outputBuf);
315
+ } catch (e) {
316
+ log().error(`Error processing frame: ${e}`);
317
+ chunkOut = chunkIn;
318
+ }
319
+ if (chunkOut.length !== chunk) {
320
+ log().warn(
321
+ `Krisp returned ${chunkOut.length} samples, expected ${chunk}; using original audio`,
322
+ );
323
+ chunkOut = chunkIn;
324
+ }
325
+ this.outBuf = concatInt16(this.outBuf, chunkOut);
326
+ }
327
+ }
328
+
329
+ // Emit the processed audio that is ready, keeping any surplus buffered for
330
+ // the next call. We never zero-pad a deficit: doing so injects silence
331
+ // *between* real audio (which recurs whenever the input frame size isn't a
332
+ // multiple of the chunk size) and surfaces as audible gaps once frames are
333
+ // concatenated downstream. Instead the output frame size floats — up to a
334
+ // full chunk of latency at the start (and an empty frame if the buffer is
335
+ // momentarily starved), both of which downstream reframing handles fine —
336
+ // so real audio is never interrupted.
337
+ const n = frame.samplesPerChannel;
338
+ const k = Math.min(n, this.outBuf.length);
339
+ const out = this.outBuf.slice(0, k);
340
+ this.outBuf = this.outBuf.slice(k);
341
+
342
+ return new AudioFrame(out, frame.sampleRate, frame.channels, out.length);
343
+ }
344
+
345
+ private teardown(): void {
346
+ if (this.session !== null) {
347
+ try {
348
+ this.session.destroy();
349
+ } catch (e) {
350
+ log().error(`Error destroying Krisp session: ${e}`);
351
+ }
352
+ this.session = null;
353
+ }
354
+ this.inBuf = new Int16Array(0);
355
+ this.outBuf = new Int16Array(0);
356
+ if (this.sdkAcquired) {
357
+ KrispLicenseSdkManager.release();
358
+ this.sdkAcquired = false;
359
+ }
360
+ }
361
+
362
+ close(): void {
363
+ this.teardown();
364
+ log().debug('Krisp license frame processor closed');
365
+ }
366
+ }
@@ -0,0 +1,57 @@
1
+ // SPDX-FileCopyrightText: 2026 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * Ambient typings for the untyped, user-installed `@krisp/viva-node-sdk` native
7
+ * module, covering the subset of the documented server SDK surface this plugin
8
+ * uses (https://sdk-docs.krisp.ai/docs/getting-started-server).
9
+ *
10
+ * The package is not a dependency — it is lazily `require`d at runtime in
11
+ * license mode — so these declarations let the plugin type-check without it
12
+ * installed.
13
+ */
14
+ declare module '@krisp/viva-node-sdk' {
15
+ /**
16
+ * Opaque `enums.SamplingRate.Sr<rate>Hz` / `enums.FrameDuration.Fd<ms>ms`
17
+ * member. The SDK treats these as tokens — we only read them from `enums` and
18
+ * pass them straight back into `create`, never inspecting their runtime shape.
19
+ */
20
+ export type KrispEnumMember = unknown;
21
+
22
+ /** Config passed to `NcInt16.create` for a noise-cancellation session. */
23
+ export interface KrispSessionConfig {
24
+ inputSampleRate: KrispEnumMember;
25
+ inputFrameDuration: KrispEnumMember;
26
+ outputSampleRate: KrispEnumMember;
27
+ modelInfo: { path: string };
28
+ }
29
+
30
+ /** Noise-cancellation session returned by `NcInt16.create`. */
31
+ export interface KrispNcSession {
32
+ /**
33
+ * Filter one fixed-size int16 chunk at the given suppression level (0–100).
34
+ * Input is a byte buffer of interleaved int16 PCM; the return is a byte
35
+ * buffer of the same length (samples × 2 bytes).
36
+ */
37
+ process(frame: Buffer | ArrayBuffer, noiseSuppressionLevel?: number): Buffer;
38
+ destroy(): void;
39
+ }
40
+
41
+ /** The subset of the module surface this plugin uses. */
42
+ export interface KrispModule {
43
+ enums: {
44
+ SamplingRate: Record<string, KrispEnumMember>;
45
+ FrameDuration: Record<string, KrispEnumMember>;
46
+ };
47
+ /**
48
+ * Process-global init. Takes a working-directory path; the second argument
49
+ * is the license key (the SDK also honors overloads with log callbacks, not
50
+ * used here). Pass `''` for the working dir to use the SDK default.
51
+ */
52
+ globalInit(workingDir: string, licenseKey?: string): void;
53
+ /** Process-global teardown. */
54
+ globalDestroy(): void;
55
+ NcInt16: { create(config: KrispSessionConfig): KrispNcSession };
56
+ }
57
+ }
package/src/auth.ts ADDED
@@ -0,0 +1,109 @@
1
+ // SPDX-FileCopyrightText: 2026 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * Authentication providers for the Krisp plugin.
7
+ *
8
+ * These types are plain configuration holders — {@link krispVivaFilter}
9
+ * dispatches on the provider instance to pick the matching backend FrameProcessor
10
+ * implementation.
11
+ *
12
+ * - {@link LiveKitCloudAuthProvider} (default): selects the closed-source
13
+ * `@livekit/plugins-krisp-viva-internal` backend. It bundles the model and
14
+ * authenticates against LiveKit Cloud using the room JWT, which the agent
15
+ * framework hands to the FrameProcessor via the standard `onCredentialsUpdated`
16
+ * callback.
17
+ * - {@link KrispLicenseAuthProvider}: selects the proprietary `@krisp/viva-node-sdk`
18
+ * with a `.kef` model file (license key supplied via `KRISP_VIVA_SDK_LICENSE_KEY`).
19
+ *
20
+ * Preferred call sites use the {@link auth} namespace:
21
+ *
22
+ * ```ts
23
+ * import { auth } from '@livekit/agents-plugin-krisp';
24
+ *
25
+ * auth.livekitCloud();
26
+ * auth.krispLicense();
27
+ * ```
28
+ */
29
+ import { existsSync, statSync } from 'node:fs';
30
+
31
+ /**
32
+ * Discriminator symbols identifying each auth provider, registered in the global
33
+ * symbol registry via `Symbol.for` so the {@link krispVivaFilter}
34
+ * facade can dispatch reliably even when this module is loaded more than once
35
+ * (e.g. duplicate copies through bundling or linked workspaces) — a case where
36
+ * `instanceof` would silently fail. Not part of the public API surface.
37
+ */
38
+ export const LIVEKIT_CLOUD_KIND: unique symbol = Symbol.for(
39
+ 'livekit.agents.krisp.auth.livekitCloud',
40
+ );
41
+ export const KRISP_LICENSE_KIND: unique symbol = Symbol.for(
42
+ 'livekit.agents.krisp.auth.krispLicense',
43
+ );
44
+
45
+ /**
46
+ * Marker for the LiveKit Cloud-bundled Krisp backend.
47
+ *
48
+ * Auth + metering happen inside `@livekit/plugins-krisp-viva-internal`, which
49
+ * receives the room JWT via the standard FrameProcessor `onCredentialsUpdated`
50
+ * callback (forwarded by the facade). There is nothing to configure on this side.
51
+ *
52
+ * @public
53
+ */
54
+ export class LiveKitCloudAuthProvider {
55
+ /** @internal */
56
+ readonly kind: typeof LIVEKIT_CLOUD_KIND = LIVEKIT_CLOUD_KIND;
57
+ }
58
+
59
+ /**
60
+ * Krisp-direct auth using the proprietary `@krisp/viva-node-sdk`.
61
+ *
62
+ * Both inputs are read from the environment, which the native SDK also relies on:
63
+ *
64
+ * - `KRISP_VIVA_FILTER_MODEL_PATH` — path to the `.kef` model file.
65
+ * - `KRISP_VIVA_SDK_LICENSE_KEY` — Krisp license key (read by the SDK directly).
66
+ *
67
+ * @public
68
+ */
69
+ export class KrispLicenseAuthProvider {
70
+ /** @internal */
71
+ readonly kind: typeof KRISP_LICENSE_KIND = KRISP_LICENSE_KIND;
72
+ readonly modelPath: string;
73
+
74
+ constructor() {
75
+ const resolvedModelPath = process.env.KRISP_VIVA_FILTER_MODEL_PATH;
76
+
77
+ if (!resolvedModelPath) {
78
+ throw new Error('Krisp model path is required. Set KRISP_VIVA_FILTER_MODEL_PATH.');
79
+ }
80
+ if (!resolvedModelPath.endsWith('.kef')) {
81
+ throw new Error('Krisp model must have a .kef extension');
82
+ }
83
+ if (!existsSync(resolvedModelPath) || !statSync(resolvedModelPath).isFile()) {
84
+ throw new Error(`Krisp model file not found: ${resolvedModelPath}`);
85
+ }
86
+
87
+ this.modelPath = resolvedModelPath;
88
+ }
89
+ }
90
+
91
+ /** @public */
92
+ export type AuthProvider = LiveKitCloudAuthProvider | KrispLicenseAuthProvider;
93
+
94
+ /**
95
+ * Preferred factory namespace for auth providers.
96
+ *
97
+ * ```ts
98
+ * import { auth } from '@livekit/agents-plugin-krisp';
99
+ *
100
+ * auth.livekitCloud();
101
+ * auth.krispLicense(); // reads KRISP_VIVA_FILTER_MODEL_PATH + KRISP_VIVA_SDK_LICENSE_KEY
102
+ * ```
103
+ *
104
+ * @public
105
+ */
106
+ export const auth = {
107
+ livekitCloud: (): LiveKitCloudAuthProvider => new LiveKitCloudAuthProvider(),
108
+ krispLicense: (): KrispLicenseAuthProvider => new KrispLicenseAuthProvider(),
109
+ };
package/src/index.ts ADDED
@@ -0,0 +1,78 @@
1
+ // SPDX-FileCopyrightText: 2026 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * Krisp VIVA plugin for LiveKit Agents.
7
+ *
8
+ * Real-time noise reduction as a `FrameProcessor`. Two authentication backends
9
+ * are supported, exposed under the {@link auth} namespace:
10
+ *
11
+ * - `auth.livekitCloud()` (default): LiveKit Cloud-managed auth + bundled model.
12
+ * No Krisp keys or model files required.
13
+ * - `auth.krispLicense(...)`: Krisp-direct auth using a license key and a `.kef`
14
+ * model file (requires the proprietary `@krisp/viva-node-sdk`).
15
+ *
16
+ * Two voice isolation modes are available: {@link voiceIsolation} for general
17
+ * use and {@link voiceIsolationTelephony} tuned for telephony audio.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import * as krisp from '@livekit/agents-plugin-krisp';
22
+ *
23
+ * const processor = krisp.voiceIsolation();
24
+ * ```
25
+ *
26
+ * @packageDocumentation
27
+ */
28
+ import { Plugin } from '@livekit/agents';
29
+ import { KrispVivaFilter, type KrispVivaFilterOptions } from './viva_filter.js';
30
+
31
+ export { type KrispVivaFilter, type KrispVivaFilterOptions };
32
+
33
+ export {
34
+ type AuthProvider,
35
+ auth,
36
+ KrispLicenseAuthProvider,
37
+ LiveKitCloudAuthProvider,
38
+ } from './auth.js';
39
+
40
+ /**
41
+ * Create a Krisp VIVA voice isolation `FrameProcessor`.
42
+ *
43
+ * Pass the result as `noiseCancellation` in the session's input options. Uses
44
+ * LiveKit Cloud auth by default; pass `authProvider: auth.krispLicense(...)` to
45
+ * run the proprietary Krisp SDK with your own license + `.kef` model.
46
+ *
47
+ * @public
48
+ */
49
+ export function voiceIsolation(options?: Partial<KrispVivaFilterOptions>): KrispVivaFilter {
50
+ return new KrispVivaFilter(options, 'voiceIsolation');
51
+ }
52
+
53
+ /**
54
+ * Create a Krisp VIVA voice isolation `FrameProcessor` for telephony use cases.
55
+ *
56
+ * Pass the result as `noiseCancellation` in the session's input options. Uses
57
+ * LiveKit Cloud auth by default; pass `authProvider: auth.krispLicense(...)` to
58
+ * run the proprietary Krisp SDK with your own license + `.kef` model.
59
+ *
60
+ * @public
61
+ */
62
+ export function voiceIsolationTelephony(
63
+ options?: Partial<KrispVivaFilterOptions>,
64
+ ): KrispVivaFilter {
65
+ return new KrispVivaFilter(options, 'voiceIsolationTelephony');
66
+ }
67
+
68
+ class KrispPlugin extends Plugin {
69
+ constructor() {
70
+ super({
71
+ title: 'krisp',
72
+ version: __PACKAGE_VERSION__,
73
+ package: __PACKAGE_NAME__,
74
+ });
75
+ }
76
+ }
77
+
78
+ Plugin.registerPlugin(new KrispPlugin());
package/src/log.ts ADDED
@@ -0,0 +1,7 @@
1
+ // SPDX-FileCopyrightText: 2026 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { log as agentsLog } from '@livekit/agents';
5
+ import type { Logger } from 'pino';
6
+
7
+ export const log = (): Logger => agentsLog().child({ plugin: 'krisp' });