@livekit/agents-plugin-krisp 1.6.0 → 1.6.2
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/README.md +1 -1
- package/dist/_frame_identity.cjs +42 -0
- package/dist/_frame_identity.cjs.map +1 -0
- package/dist/_frame_identity.d.cts +14 -0
- package/dist/_frame_identity.d.ts +14 -0
- package/dist/_frame_identity.d.ts.map +1 -0
- package/dist/_frame_identity.js +18 -0
- package/dist/_frame_identity.js.map +1 -0
- package/dist/_frame_identity.test.cjs +35 -0
- package/dist/_frame_identity.test.cjs.map +1 -0
- package/dist/_frame_identity.test.d.cts +2 -0
- package/dist/_frame_identity.test.d.ts +2 -0
- package/dist/_frame_identity.test.d.ts.map +1 -0
- package/dist/_frame_identity.test.js +34 -0
- package/dist/_frame_identity.test.js.map +1 -0
- package/dist/_krisp.cjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/viva_filter.cjs +3 -2
- package/dist/viva_filter.cjs.map +1 -1
- package/dist/viva_filter.d.cts +1 -1
- package/dist/viva_filter.d.ts +1 -1
- package/dist/viva_filter.d.ts.map +1 -1
- package/dist/viva_filter.js +3 -2
- package/dist/viva_filter.js.map +1 -1
- package/package.json +7 -7
- package/src/_frame_identity.test.ts +51 -0
- package/src/_frame_identity.ts +39 -0
- package/src/viva_filter.ts +4 -3
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ export default async function entry(ctx: JobContext) {
|
|
|
67
67
|
| Option | Type | Default | Description |
|
|
68
68
|
| ----------------------- | -------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
69
69
|
| `authProvider` | `AuthProvider` | `LiveKitCloudAuthProvider` | Authentication backend. Defaults to LiveKit Cloud. See [the alternative](#alternative-krisp-license-auth). |
|
|
70
|
-
| `noiseSuppressionLevel` | `number` | `
|
|
70
|
+
| `noiseSuppressionLevel` | `number` | `75` | Noise reduction intensity (0-100). |
|
|
71
71
|
|
|
72
72
|
Input frames of any size and sample rate are buffered and adapted automatically.
|
|
73
73
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var frame_identity_exports = {};
|
|
20
|
+
__export(frame_identity_exports, {
|
|
21
|
+
adoptLocalAudioFrame: () => adoptLocalAudioFrame
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(frame_identity_exports);
|
|
24
|
+
var import_rtc_node = require("@livekit/rtc-node");
|
|
25
|
+
function adoptLocalAudioFrame(frame) {
|
|
26
|
+
if (frame instanceof import_rtc_node.AudioFrame) {
|
|
27
|
+
return frame;
|
|
28
|
+
}
|
|
29
|
+
const foreign = frame;
|
|
30
|
+
return new import_rtc_node.AudioFrame(
|
|
31
|
+
foreign.data,
|
|
32
|
+
foreign.sampleRate,
|
|
33
|
+
foreign.channels,
|
|
34
|
+
foreign.samplesPerChannel,
|
|
35
|
+
foreign.userdata
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
adoptLocalAudioFrame
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=_frame_identity.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/_frame_identity.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioFrame } from '@livekit/rtc-node';\n\n/**\n * Return a frame that belongs to *this* copy of `@livekit/rtc-node`.\n *\n * The Cloud backend is reached through `createRequire`, which resolves the internal package's\n * `require` condition and so loads the CJS build of `@livekit/rtc-node` next to our ESM one.\n * Frames it hands back are instances of that copy's `AudioFrame`, so `instanceof AudioFrame`\n * fails everywhere downstream: audio recognition treats them as unrecognised sentinels and\n * drops them, and adaptive interruption — never fed any audio — rules every barge-in a\n * backchannel. `AudioFrame` is a plain data holder, so adopting one shares its samples rather\n * than copying them.\n */\nexport function adoptLocalAudioFrame(frame: AudioFrame): AudioFrame {\n if (frame instanceof AudioFrame) {\n return frame;\n }\n\n // Statically unreachable — the declared type *is* `AudioFrame`. It is reachable at runtime\n // precisely because that type came from a different copy of the module.\n const foreign = frame as unknown as {\n data: Int16Array;\n sampleRate: number;\n channels: number;\n samplesPerChannel: number;\n userdata?: Record<string, unknown>;\n };\n\n return new AudioFrame(\n foreign.data,\n foreign.sampleRate,\n foreign.channels,\n foreign.samplesPerChannel,\n foreign.userdata,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA2B;AAapB,SAAS,qBAAqB,OAA+B;AAClE,MAAI,iBAAiB,4BAAY;AAC/B,WAAO;AAAA,EACT;AAIA,QAAM,UAAU;AAQhB,SAAO,IAAI;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AudioFrame } from '@livekit/rtc-node';
|
|
2
|
+
/**
|
|
3
|
+
* Return a frame that belongs to *this* copy of `@livekit/rtc-node`.
|
|
4
|
+
*
|
|
5
|
+
* The Cloud backend is reached through `createRequire`, which resolves the internal package's
|
|
6
|
+
* `require` condition and so loads the CJS build of `@livekit/rtc-node` next to our ESM one.
|
|
7
|
+
* Frames it hands back are instances of that copy's `AudioFrame`, so `instanceof AudioFrame`
|
|
8
|
+
* fails everywhere downstream: audio recognition treats them as unrecognised sentinels and
|
|
9
|
+
* drops them, and adaptive interruption — never fed any audio — rules every barge-in a
|
|
10
|
+
* backchannel. `AudioFrame` is a plain data holder, so adopting one shares its samples rather
|
|
11
|
+
* than copying them.
|
|
12
|
+
*/
|
|
13
|
+
export declare function adoptLocalAudioFrame(frame: AudioFrame): AudioFrame;
|
|
14
|
+
//# sourceMappingURL=_frame_identity.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AudioFrame } from '@livekit/rtc-node';
|
|
2
|
+
/**
|
|
3
|
+
* Return a frame that belongs to *this* copy of `@livekit/rtc-node`.
|
|
4
|
+
*
|
|
5
|
+
* The Cloud backend is reached through `createRequire`, which resolves the internal package's
|
|
6
|
+
* `require` condition and so loads the CJS build of `@livekit/rtc-node` next to our ESM one.
|
|
7
|
+
* Frames it hands back are instances of that copy's `AudioFrame`, so `instanceof AudioFrame`
|
|
8
|
+
* fails everywhere downstream: audio recognition treats them as unrecognised sentinels and
|
|
9
|
+
* drops them, and adaptive interruption — never fed any audio — rules every barge-in a
|
|
10
|
+
* backchannel. `AudioFrame` is a plain data holder, so adopting one shares its samples rather
|
|
11
|
+
* than copying them.
|
|
12
|
+
*/
|
|
13
|
+
export declare function adoptLocalAudioFrame(frame: AudioFrame): AudioFrame;
|
|
14
|
+
//# sourceMappingURL=_frame_identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_frame_identity.d.ts","sourceRoot":"","sources":["../src/_frame_identity.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAsBlE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AudioFrame } from "@livekit/rtc-node";
|
|
2
|
+
function adoptLocalAudioFrame(frame) {
|
|
3
|
+
if (frame instanceof AudioFrame) {
|
|
4
|
+
return frame;
|
|
5
|
+
}
|
|
6
|
+
const foreign = frame;
|
|
7
|
+
return new AudioFrame(
|
|
8
|
+
foreign.data,
|
|
9
|
+
foreign.sampleRate,
|
|
10
|
+
foreign.channels,
|
|
11
|
+
foreign.samplesPerChannel,
|
|
12
|
+
foreign.userdata
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
adoptLocalAudioFrame
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=_frame_identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/_frame_identity.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioFrame } from '@livekit/rtc-node';\n\n/**\n * Return a frame that belongs to *this* copy of `@livekit/rtc-node`.\n *\n * The Cloud backend is reached through `createRequire`, which resolves the internal package's\n * `require` condition and so loads the CJS build of `@livekit/rtc-node` next to our ESM one.\n * Frames it hands back are instances of that copy's `AudioFrame`, so `instanceof AudioFrame`\n * fails everywhere downstream: audio recognition treats them as unrecognised sentinels and\n * drops them, and adaptive interruption — never fed any audio — rules every barge-in a\n * backchannel. `AudioFrame` is a plain data holder, so adopting one shares its samples rather\n * than copying them.\n */\nexport function adoptLocalAudioFrame(frame: AudioFrame): AudioFrame {\n if (frame instanceof AudioFrame) {\n return frame;\n }\n\n // Statically unreachable — the declared type *is* `AudioFrame`. It is reachable at runtime\n // precisely because that type came from a different copy of the module.\n const foreign = frame as unknown as {\n data: Int16Array;\n sampleRate: number;\n channels: number;\n samplesPerChannel: number;\n userdata?: Record<string, unknown>;\n };\n\n return new AudioFrame(\n foreign.data,\n foreign.sampleRate,\n foreign.channels,\n foreign.samplesPerChannel,\n foreign.userdata,\n );\n}\n"],"mappings":"AAGA,SAAS,kBAAkB;AAapB,SAAS,qBAAqB,OAA+B;AAClE,MAAI,iBAAiB,YAAY;AAC/B,WAAO;AAAA,EACT;AAIA,QAAM,UAAU;AAQhB,SAAO,IAAI;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AACF;","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_rtc_node = require("@livekit/rtc-node");
|
|
3
|
+
var import_vitest = require("vitest");
|
|
4
|
+
var import_frame_identity = require("./_frame_identity.cjs");
|
|
5
|
+
class ForeignAudioFrame {
|
|
6
|
+
constructor(data, sampleRate, channels, samplesPerChannel, _userdata = {}) {
|
|
7
|
+
this.data = data;
|
|
8
|
+
this.sampleRate = sampleRate;
|
|
9
|
+
this.channels = channels;
|
|
10
|
+
this.samplesPerChannel = samplesPerChannel;
|
|
11
|
+
this._userdata = _userdata;
|
|
12
|
+
}
|
|
13
|
+
get userdata() {
|
|
14
|
+
return this._userdata;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
(0, import_vitest.describe)("adoptLocalAudioFrame", () => {
|
|
18
|
+
(0, import_vitest.it)("adopts a frame built by another copy of rtc-node", () => {
|
|
19
|
+
const samples = new Int16Array([1, -2, 3, -4]);
|
|
20
|
+
const foreign = new ForeignAudioFrame(samples, 16e3, 1, 4, { source: "krisp" });
|
|
21
|
+
(0, import_vitest.expect)(foreign instanceof import_rtc_node.AudioFrame).toBe(false);
|
|
22
|
+
const adopted = (0, import_frame_identity.adoptLocalAudioFrame)(foreign);
|
|
23
|
+
(0, import_vitest.expect)(adopted instanceof import_rtc_node.AudioFrame).toBe(true);
|
|
24
|
+
(0, import_vitest.expect)(adopted.sampleRate).toBe(16e3);
|
|
25
|
+
(0, import_vitest.expect)(adopted.channels).toBe(1);
|
|
26
|
+
(0, import_vitest.expect)(adopted.samplesPerChannel).toBe(4);
|
|
27
|
+
(0, import_vitest.expect)(adopted.userdata).toEqual({ source: "krisp" });
|
|
28
|
+
(0, import_vitest.expect)(adopted.data).toBe(samples);
|
|
29
|
+
});
|
|
30
|
+
(0, import_vitest.it)("returns a local frame untouched", () => {
|
|
31
|
+
const local = new import_rtc_node.AudioFrame(new Int16Array([5, 6]), 48e3, 1, 2);
|
|
32
|
+
(0, import_vitest.expect)((0, import_frame_identity.adoptLocalAudioFrame)(local)).toBe(local);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=_frame_identity.test.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/_frame_identity.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioFrame } from '@livekit/rtc-node';\nimport { describe, expect, it } from 'vitest';\nimport { adoptLocalAudioFrame } from './_frame_identity.js';\n\n/**\n * Stands in for the `AudioFrame` of a second copy of `@livekit/rtc-node`: identical shape, same\n * constructor name, unrelated identity. That is exactly what the CJS build produces when the\n * Cloud backend pulls it in through `createRequire`.\n */\nclass ForeignAudioFrame {\n constructor(\n readonly data: Int16Array,\n readonly sampleRate: number,\n readonly channels: number,\n readonly samplesPerChannel: number,\n private readonly _userdata: Record<string, unknown> = {},\n ) {}\n\n get userdata(): Record<string, unknown> {\n return this._userdata;\n }\n}\n\ndescribe('adoptLocalAudioFrame', () => {\n it('adopts a frame built by another copy of rtc-node', () => {\n const samples = new Int16Array([1, -2, 3, -4]);\n const foreign = new ForeignAudioFrame(samples, 16000, 1, 4, { source: 'krisp' });\n\n // The premise of the bug: this lookalike fails the identity check every consumer relies on.\n expect(foreign instanceof AudioFrame).toBe(false);\n\n const adopted = adoptLocalAudioFrame(foreign as unknown as AudioFrame);\n\n expect(adopted instanceof AudioFrame).toBe(true);\n expect(adopted.sampleRate).toBe(16000);\n expect(adopted.channels).toBe(1);\n expect(adopted.samplesPerChannel).toBe(4);\n expect(adopted.userdata).toEqual({ source: 'krisp' });\n // Adopting must not copy the audio: this runs on every frame of every session.\n expect(adopted.data).toBe(samples);\n });\n\n it('returns a local frame untouched', () => {\n const local = new AudioFrame(new Int16Array([5, 6]), 48000, 1, 2);\n\n expect(adoptLocalAudioFrame(local)).toBe(local);\n });\n});\n"],"mappings":";AAGA,sBAA2B;AAC3B,oBAAqC;AACrC,4BAAqC;AAOrC,MAAM,kBAAkB;AAAA,EACtB,YACW,MACA,YACA,UACA,mBACQ,YAAqC,CAAC,GACvD;AALS;AACA;AACA;AACA;AACQ;AAAA,EAChB;AAAA,EAEH,IAAI,WAAoC;AACtC,WAAO,KAAK;AAAA,EACd;AACF;AAAA,IAEA,wBAAS,wBAAwB,MAAM;AACrC,wBAAG,oDAAoD,MAAM;AAC3D,UAAM,UAAU,IAAI,WAAW,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AAC7C,UAAM,UAAU,IAAI,kBAAkB,SAAS,MAAO,GAAG,GAAG,EAAE,QAAQ,QAAQ,CAAC;AAG/E,8BAAO,mBAAmB,0BAAU,EAAE,KAAK,KAAK;AAEhD,UAAM,cAAU,4CAAqB,OAAgC;AAErE,8BAAO,mBAAmB,0BAAU,EAAE,KAAK,IAAI;AAC/C,8BAAO,QAAQ,UAAU,EAAE,KAAK,IAAK;AACrC,8BAAO,QAAQ,QAAQ,EAAE,KAAK,CAAC;AAC/B,8BAAO,QAAQ,iBAAiB,EAAE,KAAK,CAAC;AACxC,8BAAO,QAAQ,QAAQ,EAAE,QAAQ,EAAE,QAAQ,QAAQ,CAAC;AAEpD,8BAAO,QAAQ,IAAI,EAAE,KAAK,OAAO;AAAA,EACnC,CAAC;AAED,wBAAG,mCAAmC,MAAM;AAC1C,UAAM,QAAQ,IAAI,2BAAW,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,MAAO,GAAG,CAAC;AAEhE,kCAAO,4CAAqB,KAAK,CAAC,EAAE,KAAK,KAAK;AAAA,EAChD,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_frame_identity.test.d.ts","sourceRoot":"","sources":["../src/_frame_identity.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AudioFrame } from "@livekit/rtc-node";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { adoptLocalAudioFrame } from "./_frame_identity.js";
|
|
4
|
+
class ForeignAudioFrame {
|
|
5
|
+
constructor(data, sampleRate, channels, samplesPerChannel, _userdata = {}) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
this.sampleRate = sampleRate;
|
|
8
|
+
this.channels = channels;
|
|
9
|
+
this.samplesPerChannel = samplesPerChannel;
|
|
10
|
+
this._userdata = _userdata;
|
|
11
|
+
}
|
|
12
|
+
get userdata() {
|
|
13
|
+
return this._userdata;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
describe("adoptLocalAudioFrame", () => {
|
|
17
|
+
it("adopts a frame built by another copy of rtc-node", () => {
|
|
18
|
+
const samples = new Int16Array([1, -2, 3, -4]);
|
|
19
|
+
const foreign = new ForeignAudioFrame(samples, 16e3, 1, 4, { source: "krisp" });
|
|
20
|
+
expect(foreign instanceof AudioFrame).toBe(false);
|
|
21
|
+
const adopted = adoptLocalAudioFrame(foreign);
|
|
22
|
+
expect(adopted instanceof AudioFrame).toBe(true);
|
|
23
|
+
expect(adopted.sampleRate).toBe(16e3);
|
|
24
|
+
expect(adopted.channels).toBe(1);
|
|
25
|
+
expect(adopted.samplesPerChannel).toBe(4);
|
|
26
|
+
expect(adopted.userdata).toEqual({ source: "krisp" });
|
|
27
|
+
expect(adopted.data).toBe(samples);
|
|
28
|
+
});
|
|
29
|
+
it("returns a local frame untouched", () => {
|
|
30
|
+
const local = new AudioFrame(new Int16Array([5, 6]), 48e3, 1, 2);
|
|
31
|
+
expect(adoptLocalAudioFrame(local)).toBe(local);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=_frame_identity.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/_frame_identity.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AudioFrame } from '@livekit/rtc-node';\nimport { describe, expect, it } from 'vitest';\nimport { adoptLocalAudioFrame } from './_frame_identity.js';\n\n/**\n * Stands in for the `AudioFrame` of a second copy of `@livekit/rtc-node`: identical shape, same\n * constructor name, unrelated identity. That is exactly what the CJS build produces when the\n * Cloud backend pulls it in through `createRequire`.\n */\nclass ForeignAudioFrame {\n constructor(\n readonly data: Int16Array,\n readonly sampleRate: number,\n readonly channels: number,\n readonly samplesPerChannel: number,\n private readonly _userdata: Record<string, unknown> = {},\n ) {}\n\n get userdata(): Record<string, unknown> {\n return this._userdata;\n }\n}\n\ndescribe('adoptLocalAudioFrame', () => {\n it('adopts a frame built by another copy of rtc-node', () => {\n const samples = new Int16Array([1, -2, 3, -4]);\n const foreign = new ForeignAudioFrame(samples, 16000, 1, 4, { source: 'krisp' });\n\n // The premise of the bug: this lookalike fails the identity check every consumer relies on.\n expect(foreign instanceof AudioFrame).toBe(false);\n\n const adopted = adoptLocalAudioFrame(foreign as unknown as AudioFrame);\n\n expect(adopted instanceof AudioFrame).toBe(true);\n expect(adopted.sampleRate).toBe(16000);\n expect(adopted.channels).toBe(1);\n expect(adopted.samplesPerChannel).toBe(4);\n expect(adopted.userdata).toEqual({ source: 'krisp' });\n // Adopting must not copy the audio: this runs on every frame of every session.\n expect(adopted.data).toBe(samples);\n });\n\n it('returns a local frame untouched', () => {\n const local = new AudioFrame(new Int16Array([5, 6]), 48000, 1, 2);\n\n expect(adoptLocalAudioFrame(local)).toBe(local);\n });\n});\n"],"mappings":"AAGA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,4BAA4B;AAOrC,MAAM,kBAAkB;AAAA,EACtB,YACW,MACA,YACA,UACA,mBACQ,YAAqC,CAAC,GACvD;AALS;AACA;AACA;AACA;AACQ;AAAA,EAChB;AAAA,EAEH,IAAI,WAAoC;AACtC,WAAO,KAAK;AAAA,EACd;AACF;AAEA,SAAS,wBAAwB,MAAM;AACrC,KAAG,oDAAoD,MAAM;AAC3D,UAAM,UAAU,IAAI,WAAW,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AAC7C,UAAM,UAAU,IAAI,kBAAkB,SAAS,MAAO,GAAG,GAAG,EAAE,QAAQ,QAAQ,CAAC;AAG/E,WAAO,mBAAmB,UAAU,EAAE,KAAK,KAAK;AAEhD,UAAM,UAAU,qBAAqB,OAAgC;AAErE,WAAO,mBAAmB,UAAU,EAAE,KAAK,IAAI;AAC/C,WAAO,QAAQ,UAAU,EAAE,KAAK,IAAK;AACrC,WAAO,QAAQ,QAAQ,EAAE,KAAK,CAAC;AAC/B,WAAO,QAAQ,iBAAiB,EAAE,KAAK,CAAC;AACxC,WAAO,QAAQ,QAAQ,EAAE,QAAQ,EAAE,QAAQ,QAAQ,CAAC;AAEpD,WAAO,QAAQ,IAAI,EAAE,KAAK,OAAO;AAAA,EACnC,CAAC;AAED,KAAG,mCAAmC,MAAM;AAC1C,UAAM,QAAQ,IAAI,WAAW,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,MAAO,GAAG,CAAC;AAEhE,WAAO,qBAAqB,KAAK,CAAC,EAAE,KAAK,KAAK;AAAA,EAChD,CAAC;AACH,CAAC;","names":[]}
|
package/dist/_krisp.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/_krisp.ts","../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.43.7_@types+node@25.6.0__postcss@8.5.17_tsx@4.23.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * License-mode Krisp internals.\n *\n * This module is private to the plugin. It wraps the public\n * `@krisp/viva-node-sdk` and exposes a {@link KrispLicenseFrameProcessor} that\n * {@link krispVivaFilter} instantiates when the user picks\n * {@link KrispLicenseAuthProvider}.\n *\n * Wires the documented `@krisp/viva-node-sdk` surface (https://sdk-docs.krisp.ai):\n * `globalInit(workingDir, licenseKey)`, the `enums.SamplingRate` and\n * `enums.FrameDuration` tables, `NcInt16.create(config)`, per-frame `process`\n * (byte `Buffer` in and out), and the session/global destroy calls. The license\n * key is read from `KRISP_VIVA_SDK_LICENSE_KEY` and passed to `globalInit`.\n *\n * The frame buffering / reframing logic is ported from the Python plugin.\n */\nimport type { KrispEnumMember, KrispModule, KrispNcSession } from '@krisp/viva-node-sdk';\nimport { AudioFrame, FrameProcessor } from '@livekit/rtc-node';\nimport { createRequire } from 'node:module';\nimport { log } from './log.js';\n\nconst require = createRequire(import.meta.url);\n\nconst SUPPORTED_SAMPLE_RATES: Array<number> = [8000, 16000, 24000, 32000, 44100, 48000] as const;\nconst SUPPORTED_FRAME_DURATIONS_MS: Array<number> = [10, 15, 20, 30, 32] as const;\n\n/** Map a sample rate (Hz) to the SDK's `enums.SamplingRate.Sr<rate>Hz` member. */\nfunction samplingRateEnum(mod: KrispModule, sampleRate: number): KrispEnumMember {\n const value = mod.enums?.SamplingRate?.[`Sr${sampleRate}Hz`];\n if (value === undefined) {\n throw new Error(\n `Unsupported sample rate: ${sampleRate} Hz. ` +\n `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,\n );\n }\n return value;\n}\n\n/** Map a frame duration (ms) to the SDK's `enums.FrameDuration.Fd<ms>ms` member. */\nfunction frameDurationEnum(mod: KrispModule, frameDurationMs: number): KrispEnumMember {\n const value = mod.enums?.FrameDuration?.[`Fd${frameDurationMs}ms`];\n if (value === undefined) {\n throw new Error(\n `Unsupported frame duration: ${frameDurationMs} ms. ` +\n `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,\n );\n }\n return value;\n}\n\n/**\n * Process-singleton ref counter for the proprietary `@krisp/viva-node-sdk`.\n *\n * Krisp's `globalInit` / `globalDestroy` are process-global, so this manager\n * keeps a single SDK alive across multiple license-mode frame processors. The\n * module is lazy-required on first acquire — never loaded in cloud-only\n * deployments.\n */\nclass KrispLicenseSdkManager {\n private static module: KrispModule | null = null;\n private static referenceCount = 0;\n\n /** Acquire a reference, returning the loaded `@krisp/viva-node-sdk` module. */\n static acquire(): KrispModule {\n if (this.referenceCount === 0) {\n let mod: KrispModule;\n try {\n mod = require('@krisp/viva-node-sdk');\n } catch {\n throw new Error(\n '@krisp/viva-node-sdk is not installed. Install the proprietary Krisp Node SDK ' +\n '(`pnpm add @krisp/viva-node-sdk`) and provide a .kef model, or use the ' +\n 'default LiveKit Cloud auth provider (auth.livekitCloud()).',\n );\n }\n\n // Working dir '' uses the SDK default; the license key comes from the\n // environment (KRISP_VIVA_SDK_LICENSE_KEY) and is passed to globalInit.\n const licenseKey = process.env.KRISP_VIVA_SDK_LICENSE_KEY;\n if (licenseKey) {\n mod.globalInit('', licenseKey);\n } else {\n mod.globalInit('');\n }\n\n this.module = mod;\n log().debug('Krisp Audio SDK (license) initialized');\n }\n this.referenceCount += 1;\n log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);\n // Non-null once refCount > 0: release() only nulls the module at refCount 0.\n return this.module!;\n }\n\n /** Release a reference, destroying the SDK on the last release. */\n static release(): void {\n if (this.referenceCount === 0) {\n return;\n }\n this.referenceCount -= 1;\n log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);\n if (this.referenceCount === 0 && this.module !== null) {\n try {\n this.module.globalDestroy();\n log().debug('Krisp Audio SDK (license) destroyed');\n } catch (e) {\n log().error(`Error during Krisp SDK cleanup: ${e}`);\n } finally {\n this.module = null;\n }\n }\n }\n}\n\nfunction concatInt16(a: Int16Array, b: Int16Array): Int16Array {\n const out = new Int16Array(a.length + b.length);\n out.set(a, 0);\n out.set(b, a.length);\n return out;\n}\n\n/**\n * Reinterpret a byte buffer of interleaved int16 PCM as an `Int16Array`. Copies\n * into a fresh, 2-byte-aligned buffer — a native-returned `Buffer` may sit at an\n * odd `byteOffset` in a pooled `ArrayBuffer`, which a zero-copy `Int16Array`\n * view cannot represent.\n */\nfunction bufferToInt16(buf: Buffer): Int16Array {\n const usableBytes = buf.byteLength - (buf.byteLength % 2);\n const copy = buf.buffer.slice(buf.byteOffset, buf.byteOffset + usableBytes);\n return new Int16Array(copy);\n}\n\nfunction clampLevel(value: number): number {\n return Math.max(0, Math.min(100, Math.round(value)));\n}\n\nexport interface KrispLicenseFrameProcessorOptions {\n modelPath: string;\n noiseSuppressionLevel: number;\n frameDurationMs: number;\n}\n\n/**\n * License-mode FrameProcessor wrapping `@krisp/viva-node-sdk`.\n *\n * Internal implementation detail — users call `voiceIsolation()` and the facade\n * selects this when the auth provider is {@link KrispLicenseAuthProvider}.\n *\n * The buffering strategy mirrors the Python plugin: Krisp processes fixed-size\n * chunks (`frameDurationMs` worth of samples) but input frames may arrive at any\n * size, so incoming samples accumulate in {@link inBuf}, are processed one whole\n * chunk at a time, and results queue in {@link outBuf}. Each call emits whatever\n * processed audio is ready (never zero-padded — see {@link process}), so the\n * output frame size floats and real audio is never interrupted by silence.\n */\nexport class KrispLicenseFrameProcessor extends FrameProcessor<AudioFrame> {\n private enabled = true;\n\n private sdkAcquired = false;\n private module: KrispModule;\n private session: KrispNcSession | null = null;\n private level: number;\n private readonly frameDurationMs: number;\n private readonly modelPath: string;\n private sampleRate: number | null = null;\n private chunkSamples: number | null = null;\n private warnedChannels = false;\n private inBuf: Int16Array = new Int16Array(0);\n private outBuf: Int16Array = new Int16Array(0);\n\n constructor(opts: KrispLicenseFrameProcessorOptions) {\n super();\n this.level = clampLevel(opts.noiseSuppressionLevel);\n this.frameDurationMs = opts.frameDurationMs;\n this.modelPath = opts.modelPath;\n\n if (!SUPPORTED_FRAME_DURATIONS_MS.includes(this.frameDurationMs)) {\n throw new Error(\n `Unsupported frame duration: ${this.frameDurationMs} ms. ` +\n `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,\n );\n }\n\n this.module = KrispLicenseSdkManager.acquire();\n this.sdkAcquired = true;\n\n try {\n // Pre-load the model now to fail fast on a bad license/model path. The\n // session is recreated automatically if the first frame arrives at a\n // different sample rate.\n this.createSession(16000);\n log().info('Krisp license frame processor initialized (adapts to input sample rate)');\n } catch (e) {\n this.teardown();\n throw e;\n }\n }\n\n private createSession(sampleRate: number): void {\n if (this.session !== null && this.sampleRate === sampleRate) {\n return;\n }\n if (!SUPPORTED_SAMPLE_RATES.includes(sampleRate as never)) {\n throw new Error(\n `Unsupported sample rate: ${sampleRate} Hz. ` +\n `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,\n );\n }\n\n log().info(`Creating Krisp session for sample rate: ${sampleRate}Hz`);\n\n // Free the previous session (if any) before replacing it on a rate change.\n if (this.session !== null) {\n try {\n this.session.destroy();\n } catch (e) {\n log().error(`Error destroying Krisp session: ${e}`);\n }\n this.session = null;\n }\n\n // Int16 noise-cancellation session. Our AudioFrame samples are int16 PCM, so\n // NcInt16 avoids a float round-trip (the docs' Node example shows the NcFloat\n // sibling). Output sample rate is pinned to the input rate — we only filter.\n const inputSampleRate = samplingRateEnum(this.module, sampleRate);\n const config = {\n inputSampleRate,\n inputFrameDuration: frameDurationEnum(this.module, this.frameDurationMs),\n outputSampleRate: inputSampleRate,\n modelInfo: { path: this.modelPath },\n };\n this.session = this.module.NcInt16.create(config);\n this.sampleRate = sampleRate;\n this.chunkSamples = Math.floor((sampleRate * this.frameDurationMs) / 1000);\n // The pending/processed buffers belong to the old rate; start fresh.\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n }\n\n isEnabled(): boolean {\n return this.enabled;\n }\n\n setEnabled(enabled: boolean): void {\n if (this.enabled === enabled) {\n return;\n }\n this.enabled = enabled;\n // Drop buffered audio across the transition: while disabled, process()\n // returns raw frames without draining, so a partial input chunk (inBuf) and\n // processed-but-unemitted output (outBuf) captured before the mute would\n // otherwise replay on re-enable and produce a discontinuity.\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n }\n\n get noiseSuppressionLevel(): number {\n return this.level;\n }\n\n setNoiseSuppressionLevel(value: number): void {\n // Applied on the next processed frame — the level is passed per-call to the\n // Krisp session, so no session recreation is needed.\n this.level = clampLevel(value);\n }\n\n process(frame: AudioFrame): AudioFrame {\n if (!this.enabled) {\n return frame;\n }\n\n if (frame.channels !== 1) {\n if (!this.warnedChannels) {\n log().warn(\n `Krisp filter not applied: expected mono audio but got ${frame.channels} ` +\n 'channels; frames are passed through unprocessed.',\n );\n this.warnedChannels = true;\n }\n return frame;\n }\n\n // Adapt to the input sample rate, recreating the session on a change.\n if (this.session === null || this.sampleRate !== frame.sampleRate) {\n this.createSession(frame.sampleRate);\n }\n\n const chunk = this.chunkSamples!;\n\n // Accumulate the incoming samples and process every whole chunk available.\n this.inBuf = concatInt16(this.inBuf, frame.data);\n\n const nChunks = Math.floor(this.inBuf.length / chunk);\n if (nChunks > 0) {\n const consumed = nChunks * chunk;\n const pending = this.inBuf.subarray(0, consumed);\n this.inBuf = this.inBuf.slice(consumed);\n\n for (let i = 0; i < nChunks; i++) {\n const chunkIn = pending.subarray(i * chunk, (i + 1) * chunk);\n let chunkOut: Int16Array;\n try {\n // The SDK takes/returns byte buffers of interleaved int16 PCM, so wrap\n // the input samples as a Buffer view and reinterpret the returned\n // Buffer's bytes as int16 samples (its `.length` is bytes = samples×2).\n const inputBuf = Buffer.from(chunkIn.buffer, chunkIn.byteOffset, chunkIn.byteLength);\n // Non-null: the guard above (re)creates the session or throws.\n const outputBuf = this.session!.process(inputBuf, this.level);\n chunkOut = bufferToInt16(outputBuf);\n } catch (e) {\n log().error(`Error processing frame: ${e}`);\n chunkOut = chunkIn;\n }\n if (chunkOut.length !== chunk) {\n log().warn(\n `Krisp returned ${chunkOut.length} samples, expected ${chunk}; using original audio`,\n );\n chunkOut = chunkIn;\n }\n this.outBuf = concatInt16(this.outBuf, chunkOut);\n }\n }\n\n // Emit the processed audio that is ready, keeping any surplus buffered for\n // the next call. We never zero-pad a deficit: doing so injects silence\n // *between* real audio (which recurs whenever the input frame size isn't a\n // multiple of the chunk size) and surfaces as audible gaps once frames are\n // concatenated downstream. Instead the output frame size floats — up to a\n // full chunk of latency at the start (and an empty frame if the buffer is\n // momentarily starved), both of which downstream reframing handles fine —\n // so real audio is never interrupted.\n const n = frame.samplesPerChannel;\n const k = Math.min(n, this.outBuf.length);\n const out = this.outBuf.slice(0, k);\n this.outBuf = this.outBuf.slice(k);\n\n return new AudioFrame(out, frame.sampleRate, frame.channels, out.length);\n }\n\n private teardown(): void {\n if (this.session !== null) {\n try {\n this.session.destroy();\n } catch (e) {\n log().error(`Error destroying Krisp session: ${e}`);\n }\n this.session = null;\n }\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n if (this.sdkAcquired) {\n KrispLicenseSdkManager.release();\n this.sdkAcquired = false;\n }\n }\n\n close(): void {\n this.teardown();\n log().debug('Krisp license frame processor closed');\n }\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.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I,KAAK,aAAa;AACpB,6BAAuB,QAAQ;AAC/B,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,QAAc;AACZ,SAAK,SAAS;AACd,wBAAI,EAAE,MAAM,sCAAsC;AAAA,EACpD;AACF;","names":["require"]}
|
|
1
|
+
{"version":3,"sources":["../src/_krisp.ts","../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.43.7_@types+node@25.6.0__postcss@8.5.23_tsx@4.23.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * License-mode Krisp internals.\n *\n * This module is private to the plugin. It wraps the public\n * `@krisp/viva-node-sdk` and exposes a {@link KrispLicenseFrameProcessor} that\n * {@link krispVivaFilter} instantiates when the user picks\n * {@link KrispLicenseAuthProvider}.\n *\n * Wires the documented `@krisp/viva-node-sdk` surface (https://sdk-docs.krisp.ai):\n * `globalInit(workingDir, licenseKey)`, the `enums.SamplingRate` and\n * `enums.FrameDuration` tables, `NcInt16.create(config)`, per-frame `process`\n * (byte `Buffer` in and out), and the session/global destroy calls. The license\n * key is read from `KRISP_VIVA_SDK_LICENSE_KEY` and passed to `globalInit`.\n *\n * The frame buffering / reframing logic is ported from the Python plugin.\n */\nimport type { KrispEnumMember, KrispModule, KrispNcSession } from '@krisp/viva-node-sdk';\nimport { AudioFrame, FrameProcessor } from '@livekit/rtc-node';\nimport { createRequire } from 'node:module';\nimport { log } from './log.js';\n\nconst require = createRequire(import.meta.url);\n\nconst SUPPORTED_SAMPLE_RATES: Array<number> = [8000, 16000, 24000, 32000, 44100, 48000] as const;\nconst SUPPORTED_FRAME_DURATIONS_MS: Array<number> = [10, 15, 20, 30, 32] as const;\n\n/** Map a sample rate (Hz) to the SDK's `enums.SamplingRate.Sr<rate>Hz` member. */\nfunction samplingRateEnum(mod: KrispModule, sampleRate: number): KrispEnumMember {\n const value = mod.enums?.SamplingRate?.[`Sr${sampleRate}Hz`];\n if (value === undefined) {\n throw new Error(\n `Unsupported sample rate: ${sampleRate} Hz. ` +\n `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,\n );\n }\n return value;\n}\n\n/** Map a frame duration (ms) to the SDK's `enums.FrameDuration.Fd<ms>ms` member. */\nfunction frameDurationEnum(mod: KrispModule, frameDurationMs: number): KrispEnumMember {\n const value = mod.enums?.FrameDuration?.[`Fd${frameDurationMs}ms`];\n if (value === undefined) {\n throw new Error(\n `Unsupported frame duration: ${frameDurationMs} ms. ` +\n `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,\n );\n }\n return value;\n}\n\n/**\n * Process-singleton ref counter for the proprietary `@krisp/viva-node-sdk`.\n *\n * Krisp's `globalInit` / `globalDestroy` are process-global, so this manager\n * keeps a single SDK alive across multiple license-mode frame processors. The\n * module is lazy-required on first acquire — never loaded in cloud-only\n * deployments.\n */\nclass KrispLicenseSdkManager {\n private static module: KrispModule | null = null;\n private static referenceCount = 0;\n\n /** Acquire a reference, returning the loaded `@krisp/viva-node-sdk` module. */\n static acquire(): KrispModule {\n if (this.referenceCount === 0) {\n let mod: KrispModule;\n try {\n mod = require('@krisp/viva-node-sdk');\n } catch {\n throw new Error(\n '@krisp/viva-node-sdk is not installed. Install the proprietary Krisp Node SDK ' +\n '(`pnpm add @krisp/viva-node-sdk`) and provide a .kef model, or use the ' +\n 'default LiveKit Cloud auth provider (auth.livekitCloud()).',\n );\n }\n\n // Working dir '' uses the SDK default; the license key comes from the\n // environment (KRISP_VIVA_SDK_LICENSE_KEY) and is passed to globalInit.\n const licenseKey = process.env.KRISP_VIVA_SDK_LICENSE_KEY;\n if (licenseKey) {\n mod.globalInit('', licenseKey);\n } else {\n mod.globalInit('');\n }\n\n this.module = mod;\n log().debug('Krisp Audio SDK (license) initialized');\n }\n this.referenceCount += 1;\n log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);\n // Non-null once refCount > 0: release() only nulls the module at refCount 0.\n return this.module!;\n }\n\n /** Release a reference, destroying the SDK on the last release. */\n static release(): void {\n if (this.referenceCount === 0) {\n return;\n }\n this.referenceCount -= 1;\n log().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);\n if (this.referenceCount === 0 && this.module !== null) {\n try {\n this.module.globalDestroy();\n log().debug('Krisp Audio SDK (license) destroyed');\n } catch (e) {\n log().error(`Error during Krisp SDK cleanup: ${e}`);\n } finally {\n this.module = null;\n }\n }\n }\n}\n\nfunction concatInt16(a: Int16Array, b: Int16Array): Int16Array {\n const out = new Int16Array(a.length + b.length);\n out.set(a, 0);\n out.set(b, a.length);\n return out;\n}\n\n/**\n * Reinterpret a byte buffer of interleaved int16 PCM as an `Int16Array`. Copies\n * into a fresh, 2-byte-aligned buffer — a native-returned `Buffer` may sit at an\n * odd `byteOffset` in a pooled `ArrayBuffer`, which a zero-copy `Int16Array`\n * view cannot represent.\n */\nfunction bufferToInt16(buf: Buffer): Int16Array {\n const usableBytes = buf.byteLength - (buf.byteLength % 2);\n const copy = buf.buffer.slice(buf.byteOffset, buf.byteOffset + usableBytes);\n return new Int16Array(copy);\n}\n\nfunction clampLevel(value: number): number {\n return Math.max(0, Math.min(100, Math.round(value)));\n}\n\nexport interface KrispLicenseFrameProcessorOptions {\n modelPath: string;\n noiseSuppressionLevel: number;\n frameDurationMs: number;\n}\n\n/**\n * License-mode FrameProcessor wrapping `@krisp/viva-node-sdk`.\n *\n * Internal implementation detail — users call `voiceIsolation()` and the facade\n * selects this when the auth provider is {@link KrispLicenseAuthProvider}.\n *\n * The buffering strategy mirrors the Python plugin: Krisp processes fixed-size\n * chunks (`frameDurationMs` worth of samples) but input frames may arrive at any\n * size, so incoming samples accumulate in {@link inBuf}, are processed one whole\n * chunk at a time, and results queue in {@link outBuf}. Each call emits whatever\n * processed audio is ready (never zero-padded — see {@link process}), so the\n * output frame size floats and real audio is never interrupted by silence.\n */\nexport class KrispLicenseFrameProcessor extends FrameProcessor<AudioFrame> {\n private enabled = true;\n\n private sdkAcquired = false;\n private module: KrispModule;\n private session: KrispNcSession | null = null;\n private level: number;\n private readonly frameDurationMs: number;\n private readonly modelPath: string;\n private sampleRate: number | null = null;\n private chunkSamples: number | null = null;\n private warnedChannels = false;\n private inBuf: Int16Array = new Int16Array(0);\n private outBuf: Int16Array = new Int16Array(0);\n\n constructor(opts: KrispLicenseFrameProcessorOptions) {\n super();\n this.level = clampLevel(opts.noiseSuppressionLevel);\n this.frameDurationMs = opts.frameDurationMs;\n this.modelPath = opts.modelPath;\n\n if (!SUPPORTED_FRAME_DURATIONS_MS.includes(this.frameDurationMs)) {\n throw new Error(\n `Unsupported frame duration: ${this.frameDurationMs} ms. ` +\n `Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(', ')} ms`,\n );\n }\n\n this.module = KrispLicenseSdkManager.acquire();\n this.sdkAcquired = true;\n\n try {\n // Pre-load the model now to fail fast on a bad license/model path. The\n // session is recreated automatically if the first frame arrives at a\n // different sample rate.\n this.createSession(16000);\n log().info('Krisp license frame processor initialized (adapts to input sample rate)');\n } catch (e) {\n this.teardown();\n throw e;\n }\n }\n\n private createSession(sampleRate: number): void {\n if (this.session !== null && this.sampleRate === sampleRate) {\n return;\n }\n if (!SUPPORTED_SAMPLE_RATES.includes(sampleRate as never)) {\n throw new Error(\n `Unsupported sample rate: ${sampleRate} Hz. ` +\n `Supported rates: ${SUPPORTED_SAMPLE_RATES.join(', ')} Hz`,\n );\n }\n\n log().info(`Creating Krisp session for sample rate: ${sampleRate}Hz`);\n\n // Free the previous session (if any) before replacing it on a rate change.\n if (this.session !== null) {\n try {\n this.session.destroy();\n } catch (e) {\n log().error(`Error destroying Krisp session: ${e}`);\n }\n this.session = null;\n }\n\n // Int16 noise-cancellation session. Our AudioFrame samples are int16 PCM, so\n // NcInt16 avoids a float round-trip (the docs' Node example shows the NcFloat\n // sibling). Output sample rate is pinned to the input rate — we only filter.\n const inputSampleRate = samplingRateEnum(this.module, sampleRate);\n const config = {\n inputSampleRate,\n inputFrameDuration: frameDurationEnum(this.module, this.frameDurationMs),\n outputSampleRate: inputSampleRate,\n modelInfo: { path: this.modelPath },\n };\n this.session = this.module.NcInt16.create(config);\n this.sampleRate = sampleRate;\n this.chunkSamples = Math.floor((sampleRate * this.frameDurationMs) / 1000);\n // The pending/processed buffers belong to the old rate; start fresh.\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n }\n\n isEnabled(): boolean {\n return this.enabled;\n }\n\n setEnabled(enabled: boolean): void {\n if (this.enabled === enabled) {\n return;\n }\n this.enabled = enabled;\n // Drop buffered audio across the transition: while disabled, process()\n // returns raw frames without draining, so a partial input chunk (inBuf) and\n // processed-but-unemitted output (outBuf) captured before the mute would\n // otherwise replay on re-enable and produce a discontinuity.\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n }\n\n get noiseSuppressionLevel(): number {\n return this.level;\n }\n\n setNoiseSuppressionLevel(value: number): void {\n // Applied on the next processed frame — the level is passed per-call to the\n // Krisp session, so no session recreation is needed.\n this.level = clampLevel(value);\n }\n\n process(frame: AudioFrame): AudioFrame {\n if (!this.enabled) {\n return frame;\n }\n\n if (frame.channels !== 1) {\n if (!this.warnedChannels) {\n log().warn(\n `Krisp filter not applied: expected mono audio but got ${frame.channels} ` +\n 'channels; frames are passed through unprocessed.',\n );\n this.warnedChannels = true;\n }\n return frame;\n }\n\n // Adapt to the input sample rate, recreating the session on a change.\n if (this.session === null || this.sampleRate !== frame.sampleRate) {\n this.createSession(frame.sampleRate);\n }\n\n const chunk = this.chunkSamples!;\n\n // Accumulate the incoming samples and process every whole chunk available.\n this.inBuf = concatInt16(this.inBuf, frame.data);\n\n const nChunks = Math.floor(this.inBuf.length / chunk);\n if (nChunks > 0) {\n const consumed = nChunks * chunk;\n const pending = this.inBuf.subarray(0, consumed);\n this.inBuf = this.inBuf.slice(consumed);\n\n for (let i = 0; i < nChunks; i++) {\n const chunkIn = pending.subarray(i * chunk, (i + 1) * chunk);\n let chunkOut: Int16Array;\n try {\n // The SDK takes/returns byte buffers of interleaved int16 PCM, so wrap\n // the input samples as a Buffer view and reinterpret the returned\n // Buffer's bytes as int16 samples (its `.length` is bytes = samples×2).\n const inputBuf = Buffer.from(chunkIn.buffer, chunkIn.byteOffset, chunkIn.byteLength);\n // Non-null: the guard above (re)creates the session or throws.\n const outputBuf = this.session!.process(inputBuf, this.level);\n chunkOut = bufferToInt16(outputBuf);\n } catch (e) {\n log().error(`Error processing frame: ${e}`);\n chunkOut = chunkIn;\n }\n if (chunkOut.length !== chunk) {\n log().warn(\n `Krisp returned ${chunkOut.length} samples, expected ${chunk}; using original audio`,\n );\n chunkOut = chunkIn;\n }\n this.outBuf = concatInt16(this.outBuf, chunkOut);\n }\n }\n\n // Emit the processed audio that is ready, keeping any surplus buffered for\n // the next call. We never zero-pad a deficit: doing so injects silence\n // *between* real audio (which recurs whenever the input frame size isn't a\n // multiple of the chunk size) and surfaces as audible gaps once frames are\n // concatenated downstream. Instead the output frame size floats — up to a\n // full chunk of latency at the start (and an empty frame if the buffer is\n // momentarily starved), both of which downstream reframing handles fine —\n // so real audio is never interrupted.\n const n = frame.samplesPerChannel;\n const k = Math.min(n, this.outBuf.length);\n const out = this.outBuf.slice(0, k);\n this.outBuf = this.outBuf.slice(k);\n\n return new AudioFrame(out, frame.sampleRate, frame.channels, out.length);\n }\n\n private teardown(): void {\n if (this.session !== null) {\n try {\n this.session.destroy();\n } catch (e) {\n log().error(`Error destroying Krisp session: ${e}`);\n }\n this.session = null;\n }\n this.inBuf = new Int16Array(0);\n this.outBuf = new Int16Array(0);\n if (this.sdkAcquired) {\n KrispLicenseSdkManager.release();\n this.sdkAcquired = false;\n }\n }\n\n close(): void {\n this.teardown();\n log().debug('Krisp license frame processor closed');\n }\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,OAClD,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEpC,IAAM,gBAAgC,iCAAiB;ADU9D,sBAA2C;AAC3C,yBAA8B;AAC9B,iBAAoB;AAEpB,MAAMA,eAAU,kCAAc,aAAe;AAE7C,MAAM,yBAAwC,CAAC,KAAM,MAAO,MAAO,MAAO,OAAO,IAAK;AACtF,MAAM,+BAA8C,CAAC,IAAI,IAAI,IAAI,IAAI,EAAE;AAGvE,SAAS,iBAAiB,KAAkB,YAAqC;AA/BjF;AAgCE,QAAM,SAAQ,eAAI,UAAJ,mBAAW,iBAAX,mBAA0B,KAAK,UAAU;AACvD,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI;AAAA,MACR,4BAA4B,UAAU,yBAChB,uBAAuB,KAAK,IAAI,CAAC;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;AAGA,SAAS,kBAAkB,KAAkB,iBAA0C;AA3CvF;AA4CE,QAAM,SAAQ,eAAI,UAAJ,mBAAW,kBAAX,mBAA2B,KAAK,eAAe;AAC7D,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI;AAAA,MACR,+BAA+B,eAAe,6BACpB,6BAA6B,KAAK,IAAI,CAAC;AAAA,IACnE;AAAA,EACF;AACA,SAAO;AACT;AAUA,MAAM,uBAAuB;AAAA,EAC3B,OAAe,SAA6B;AAAA,EAC5C,OAAe,iBAAiB;AAAA;AAAA,EAGhC,OAAO,UAAuB;AAC5B,QAAI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K,UAAU;AAAA,IACjB;AACA,SAAK,QAAQ,IAAI,WAAW,CAAC;AAC7B,SAAK,SAAS,IAAI,WAAW,CAAC;AAC9B,QAAI,KAAK,aAAa;AACpB,6BAAuB,QAAQ;AAC/B,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,QAAc;AACZ,SAAK,SAAS;AACd,wBAAI,EAAE,MAAM,sCAAsC;AAAA,EACpD;AACF;","names":["require"]}
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/dist/viva_filter.cjs
CHANGED
|
@@ -25,6 +25,7 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
|
|
|
25
25
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
26
26
|
var import_rtc_node = require("@livekit/rtc-node");
|
|
27
27
|
var import_node_module = require("node:module");
|
|
28
|
+
var import_frame_identity = require("./_frame_identity.cjs");
|
|
28
29
|
var import_krisp = require("./_krisp.cjs");
|
|
29
30
|
var import_auth = require("./auth.cjs");
|
|
30
31
|
var import_log = require("./log.cjs");
|
|
@@ -68,7 +69,7 @@ class KrispVivaFilter extends import_rtc_node.FrameProcessor {
|
|
|
68
69
|
constructor(opts = {}, mode = "voiceIsolation") {
|
|
69
70
|
super();
|
|
70
71
|
const provider = resolveAuthProvider(opts.authProvider);
|
|
71
|
-
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ??
|
|
72
|
+
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ?? 75);
|
|
72
73
|
}
|
|
73
74
|
isEnabled() {
|
|
74
75
|
return this.inner.isEnabled();
|
|
@@ -90,7 +91,7 @@ class KrispVivaFilter extends import_rtc_node.FrameProcessor {
|
|
|
90
91
|
this.inner.onCredentialsUpdated(credentials);
|
|
91
92
|
}
|
|
92
93
|
process(frame) {
|
|
93
|
-
return this.inner.process(frame);
|
|
94
|
+
return (0, import_frame_identity.adoptLocalAudioFrame)(this.inner.process(frame));
|
|
94
95
|
}
|
|
95
96
|
close() {
|
|
96
97
|
this.inner.close();
|
package/dist/viva_filter.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viva_filter.ts","../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.43.7_@types+node@25.6.0__postcss@8.5.
|
|
1
|
+
{"version":3,"sources":["../src/viva_filter.ts","../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.43.7_@types+node@25.6.0__postcss@8.5.23_tsx@4.23.1_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Krisp VIVA noise reduction audio filter for LiveKit Agents.\n *\n * Exposes {@link KrispVivaFilter}, a thin facade that forwards to\n * one of two underlying FrameProcessor implementations:\n *\n * - The closed-source `@livekit/plugins-krisp-viva-internal` backend (default;\n * authenticates via the LiveKit Cloud-managed JWT the agent framework hands to\n * FrameProcessors through `onCredentialsUpdated`).\n * - A local license-mode wrapper around `@krisp/viva-node-sdk` (selected when the\n * user passes a {@link KrispLicenseAuthProvider}).\n */\nimport type * as KrispInternal from '@livekit/plugins-krisp-viva-internal';\nimport type {\n AudioFrame,\n FrameProcessorCredentials,\n FrameProcessorStreamInfo,\n} from '@livekit/rtc-node';\nimport { FrameProcessor } from '@livekit/rtc-node';\nimport { createRequire } from 'node:module';\nimport { adoptLocalAudioFrame } from './_frame_identity.js';\nimport { KrispLicenseFrameProcessor } from './_krisp.js';\nimport {\n type AuthProvider,\n KrispLicenseAuthProvider,\n LIVEKIT_CLOUD_KIND,\n LiveKitCloudAuthProvider,\n} from './auth.js';\nimport { log } from './log.js';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Structural type for the backend FrameProcessors the facade forwards to.\n *\n * Both backends are `FrameProcessor<AudioFrame>` implementations that additionally\n * expose a runtime-settable noise suppression level (not part of the base\n * FrameProcessor interface).\n */\ninterface KrispBackend extends FrameProcessor<AudioFrame> {\n readonly noiseSuppressionLevel: number;\n setNoiseSuppressionLevel(value: number): void;\n}\n\n/**\n * Options for {@link KrispVivaFilter}.\n * @public\n */\nexport interface KrispVivaFilterOptions {\n /**\n * Authentication backend. When omitted, it is resolved from the environment:\n * the Krisp license path ({@link KrispLicenseAuthProvider}) is used when both\n * `KRISP_VIVA_SDK_LICENSE_KEY` and `KRISP_VIVA_FILTER_MODEL_PATH` are set;\n * otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).\n */\n authProvider: AuthProvider;\n /** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default 75. */\n noiseSuppressionLevel: number;\n}\n\nconst DEFAULT_FRAME_DURATION_MS = 10;\n\n/**\n * Pick the auth backend when the caller did not pass one explicitly. Uses the\n * Krisp license path when both `KRISP_VIVA_SDK_LICENSE_KEY` and\n * `KRISP_VIVA_FILTER_MODEL_PATH` are set (the user is responsible for having the\n * proprietary `@krisp/viva-node-sdk` installed); otherwise falls back to LiveKit\n * Cloud auth.\n */\nfunction resolveAuthProvider(explicit?: AuthProvider): AuthProvider {\n if (explicit) {\n return explicit;\n }\n if (process.env.KRISP_VIVA_SDK_LICENSE_KEY && process.env.KRISP_VIVA_FILTER_MODEL_PATH) {\n log().debug('Krisp: using license auth (env vars set)');\n return new KrispLicenseAuthProvider();\n }\n log().debug('Krisp: using LiveKit Cloud auth');\n return new LiveKitCloudAuthProvider();\n}\n\nfunction buildBackend(\n mode: KrispInternal.VivaMode,\n provider: AuthProvider,\n noiseSuppressionLevel: number,\n): KrispBackend {\n if (provider.kind === LIVEKIT_CLOUD_KIND) {\n let mod: typeof KrispInternal;\n try {\n mod = require('@livekit/plugins-krisp-viva-internal');\n } catch {\n throw new Error(\n '@livekit/plugins-krisp-viva-internal is missing — this package is bundled ' +\n 'with @livekit/agents-plugin-krisp, so this likely means a broken install. ' +\n 'Reinstall the plugin, or pass a KrispLicenseAuthProvider if you have a Krisp ' +\n 'license key + .kef model.',\n );\n }\n return new mod.KrispVivaFilterFrameProcessor({\n mode,\n noiseSuppressionLevel,\n frameDurationMs: DEFAULT_FRAME_DURATION_MS,\n });\n }\n\n // KrispLicenseAuthProvider\n return new KrispLicenseFrameProcessor({\n modelPath: provider.modelPath,\n noiseSuppressionLevel,\n frameDurationMs: DEFAULT_FRAME_DURATION_MS,\n });\n}\n\n/**\n * FrameProcessor for Krisp noise reduction.\n *\n * Thin facade over two backend FrameProcessor implementations: the LiveKit\n * Cloud-bundled package and a local wrapper around the public\n * `@krisp/viva-node-sdk`. When no `authProvider` is given, the backend is\n * resolved from the environment (see {@link KrispVivaFilterOptions.authProvider}).\n *\n * @example\n * ```ts\n * import * as krisp from '@livekit/agents-plugin-krisp';\n *\n * // Auto-resolves: Krisp license path if both KRISP_VIVA_SDK_LICENSE_KEY and\n * // KRISP_VIVA_FILTER_MODEL_PATH are set, else LiveKit Cloud auth.\n * const processor = krisp.voiceIsolation();\n *\n * // Or pin a backend explicitly.\n * const processor = krisp.voiceIsolation({\n * authProvider: krisp.auth.krispLicense(),\n * });\n *\n * await session.start({\n * agent,\n * room: ctx.room,\n * inputOptions: { noiseCancellation: processor },\n * });\n * ```\n *\n * @public\n */\nexport class KrispVivaFilter extends FrameProcessor<AudioFrame> {\n private readonly inner: KrispBackend;\n\n constructor(\n opts: Partial<KrispVivaFilterOptions> = {},\n mode: KrispInternal.VivaMode = 'voiceIsolation',\n ) {\n super();\n const provider = resolveAuthProvider(opts.authProvider);\n this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ?? 75);\n }\n\n isEnabled(): boolean {\n return this.inner.isEnabled();\n }\n\n setEnabled(enabled: boolean): void {\n this.inner.setEnabled(enabled);\n }\n\n get noiseSuppressionLevel(): number {\n return this.inner.noiseSuppressionLevel;\n }\n\n /** Adjust the noise suppression level (0-100) at runtime. */\n setNoiseSuppressionLevel(value: number): void {\n this.inner.setNoiseSuppressionLevel(value);\n }\n\n override onStreamInfoUpdated(info: FrameProcessorStreamInfo): void {\n this.inner.onStreamInfoUpdated(info);\n }\n\n override onCredentialsUpdated(credentials: FrameProcessorCredentials): void {\n this.inner.onCredentialsUpdated(credentials);\n }\n\n process(frame: AudioFrame): AudioFrame {\n return adoptLocalAudioFrame(this.inner.process(frame));\n }\n\n close(): void {\n this.inner.close();\n }\n}\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,OAClD,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEpC,IAAM,gBAAgC,iCAAiB;ADW9D,sBAA+B;AAC/B,yBAA8B;AAC9B,4BAAqC;AACrC,mBAA2C;AAC3C,kBAKO;AACP,iBAAoB;AAEpB,MAAMA,eAAU,kCAAc,aAAe;AA8B7C,MAAM,4BAA4B;AASlC,SAAS,oBAAoB,UAAuC;AAClE,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AACA,MAAI,QAAQ,IAAI,8BAA8B,QAAQ,IAAI,8BAA8B;AACtF,wBAAI,EAAE,MAAM,0CAA0C;AACtD,WAAO,IAAI,qCAAyB;AAAA,EACtC;AACA,sBAAI,EAAE,MAAM,iCAAiC;AAC7C,SAAO,IAAI,qCAAyB;AACtC;AAEA,SAAS,aACP,MACA,UACA,uBACc;AACd,MAAI,SAAS,SAAS,gCAAoB;AACxC,QAAI;AACJ,QAAI;AACF,YAAMA,SAAQ,sCAAsC;AAAA,IACtD,QAAQ;AACN,YAAM,IAAI;AAAA,QACR;AAAA,MAIF;AAAA,IACF;AACA,WAAO,IAAI,IAAI,8BAA8B;AAAA,MAC3C;AAAA,MACA;AAAA,MACA,iBAAiB;AAAA,IACnB,CAAC;AAAA,EACH;AAGA,SAAO,IAAI,wCAA2B;AAAA,IACpC,WAAW,SAAS;AAAA,IACpB;AAAA,IACA,iBAAiB;AAAA,EACnB,CAAC;AACH;AAgCO,MAAM,wBAAwB,+BAA2B;AAAA,EAC7C;AAAA,EAEjB,YACE,OAAwC,CAAC,GACzC,OAA+B,kBAC/B;AACA,UAAM;AACN,UAAM,WAAW,oBAAoB,KAAK,YAAY;AACtD,SAAK,QAAQ,aAAa,MAAM,UAAU,KAAK,yBAAyB,EAAE;AAAA,EAC5E;AAAA,EAEA,YAAqB;AACnB,WAAO,KAAK,MAAM,UAAU;AAAA,EAC9B;AAAA,EAEA,WAAW,SAAwB;AACjC,SAAK,MAAM,WAAW,OAAO;AAAA,EAC/B;AAAA,EAEA,IAAI,wBAAgC;AAClC,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA,EAGA,yBAAyB,OAAqB;AAC5C,SAAK,MAAM,yBAAyB,KAAK;AAAA,EAC3C;AAAA,EAES,oBAAoB,MAAsC;AACjE,SAAK,MAAM,oBAAoB,IAAI;AAAA,EACrC;AAAA,EAES,qBAAqB,aAA8C;AAC1E,SAAK,MAAM,qBAAqB,WAAW;AAAA,EAC7C;AAAA,EAEA,QAAQ,OAA+B;AACrC,eAAO,4CAAqB,KAAK,MAAM,QAAQ,KAAK,CAAC;AAAA,EACvD;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AACF;","names":["require"]}
|
package/dist/viva_filter.d.cts
CHANGED
|
@@ -26,7 +26,7 @@ export interface KrispVivaFilterOptions {
|
|
|
26
26
|
* otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).
|
|
27
27
|
*/
|
|
28
28
|
authProvider: AuthProvider;
|
|
29
|
-
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default
|
|
29
|
+
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default 75. */
|
|
30
30
|
noiseSuppressionLevel: number;
|
|
31
31
|
}
|
|
32
32
|
/**
|
package/dist/viva_filter.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface KrispVivaFilterOptions {
|
|
|
26
26
|
* otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).
|
|
27
27
|
*/
|
|
28
28
|
authProvider: AuthProvider;
|
|
29
|
-
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default
|
|
29
|
+
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default 75. */
|
|
30
30
|
noiseSuppressionLevel: number;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viva_filter.d.ts","sourceRoot":"","sources":["../src/viva_filter.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,KAAK,aAAa,MAAM,sCAAsC,CAAC;AAC3E,OAAO,KAAK,EACV,UAAU,EACV,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"viva_filter.d.ts","sourceRoot":"","sources":["../src/viva_filter.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,KAAK,aAAa,MAAM,sCAAsC,CAAC;AAC3E,OAAO,KAAK,EACV,UAAU,EACV,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,WAAW,CAAC;AAiBnB;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B,wFAAwF;IACxF,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAuDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,eAAgB,SAAQ,cAAc,CAAC,UAAU,CAAC;IAC7D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAGnC,IAAI,GAAE,OAAO,CAAC,sBAAsB,CAAM,EAC1C,IAAI,GAAE,aAAa,CAAC,QAA2B;IAOjD,SAAS,IAAI,OAAO;IAIpB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC,IAAI,qBAAqB,IAAI,MAAM,CAElC;IAED,6DAA6D;IAC7D,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC,mBAAmB,CAAC,IAAI,EAAE,wBAAwB,GAAG,IAAI;IAIzD,oBAAoB,CAAC,WAAW,EAAE,yBAAyB,GAAG,IAAI;IAI3E,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAItC,KAAK,IAAI,IAAI;CAGd"}
|
package/dist/viva_filter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FrameProcessor } from "@livekit/rtc-node";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
import { adoptLocalAudioFrame } from "./_frame_identity.js";
|
|
3
4
|
import { KrispLicenseFrameProcessor } from "./_krisp.js";
|
|
4
5
|
import {
|
|
5
6
|
KrispLicenseAuthProvider,
|
|
@@ -47,7 +48,7 @@ class KrispVivaFilter extends FrameProcessor {
|
|
|
47
48
|
constructor(opts = {}, mode = "voiceIsolation") {
|
|
48
49
|
super();
|
|
49
50
|
const provider = resolveAuthProvider(opts.authProvider);
|
|
50
|
-
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ??
|
|
51
|
+
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ?? 75);
|
|
51
52
|
}
|
|
52
53
|
isEnabled() {
|
|
53
54
|
return this.inner.isEnabled();
|
|
@@ -69,7 +70,7 @@ class KrispVivaFilter extends FrameProcessor {
|
|
|
69
70
|
this.inner.onCredentialsUpdated(credentials);
|
|
70
71
|
}
|
|
71
72
|
process(frame) {
|
|
72
|
-
return this.inner.process(frame);
|
|
73
|
+
return adoptLocalAudioFrame(this.inner.process(frame));
|
|
73
74
|
}
|
|
74
75
|
close() {
|
|
75
76
|
this.inner.close();
|
package/dist/viva_filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viva_filter.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Krisp VIVA noise reduction audio filter for LiveKit Agents.\n *\n * Exposes {@link KrispVivaFilter}, a thin facade that forwards to\n * one of two underlying FrameProcessor implementations:\n *\n * - The closed-source `@livekit/plugins-krisp-viva-internal` backend (default;\n * authenticates via the LiveKit Cloud-managed JWT the agent framework hands to\n * FrameProcessors through `onCredentialsUpdated`).\n * - A local license-mode wrapper around `@krisp/viva-node-sdk` (selected when the\n * user passes a {@link KrispLicenseAuthProvider}).\n */\nimport type * as KrispInternal from '@livekit/plugins-krisp-viva-internal';\nimport type {\n AudioFrame,\n FrameProcessorCredentials,\n FrameProcessorStreamInfo,\n} from '@livekit/rtc-node';\nimport { FrameProcessor } from '@livekit/rtc-node';\nimport { createRequire } from 'node:module';\nimport { KrispLicenseFrameProcessor } from './_krisp.js';\nimport {\n type AuthProvider,\n KrispLicenseAuthProvider,\n LIVEKIT_CLOUD_KIND,\n LiveKitCloudAuthProvider,\n} from './auth.js';\nimport { log } from './log.js';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Structural type for the backend FrameProcessors the facade forwards to.\n *\n * Both backends are `FrameProcessor<AudioFrame>` implementations that additionally\n * expose a runtime-settable noise suppression level (not part of the base\n * FrameProcessor interface).\n */\ninterface KrispBackend extends FrameProcessor<AudioFrame> {\n readonly noiseSuppressionLevel: number;\n setNoiseSuppressionLevel(value: number): void;\n}\n\n/**\n * Options for {@link KrispVivaFilter}.\n * @public\n */\nexport interface KrispVivaFilterOptions {\n /**\n * Authentication backend. When omitted, it is resolved from the environment:\n * the Krisp license path ({@link KrispLicenseAuthProvider}) is used when both\n * `KRISP_VIVA_SDK_LICENSE_KEY` and `KRISP_VIVA_FILTER_MODEL_PATH` are set;\n * otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).\n */\n authProvider: AuthProvider;\n /** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default
|
|
1
|
+
{"version":3,"sources":["../src/viva_filter.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Krisp VIVA noise reduction audio filter for LiveKit Agents.\n *\n * Exposes {@link KrispVivaFilter}, a thin facade that forwards to\n * one of two underlying FrameProcessor implementations:\n *\n * - The closed-source `@livekit/plugins-krisp-viva-internal` backend (default;\n * authenticates via the LiveKit Cloud-managed JWT the agent framework hands to\n * FrameProcessors through `onCredentialsUpdated`).\n * - A local license-mode wrapper around `@krisp/viva-node-sdk` (selected when the\n * user passes a {@link KrispLicenseAuthProvider}).\n */\nimport type * as KrispInternal from '@livekit/plugins-krisp-viva-internal';\nimport type {\n AudioFrame,\n FrameProcessorCredentials,\n FrameProcessorStreamInfo,\n} from '@livekit/rtc-node';\nimport { FrameProcessor } from '@livekit/rtc-node';\nimport { createRequire } from 'node:module';\nimport { adoptLocalAudioFrame } from './_frame_identity.js';\nimport { KrispLicenseFrameProcessor } from './_krisp.js';\nimport {\n type AuthProvider,\n KrispLicenseAuthProvider,\n LIVEKIT_CLOUD_KIND,\n LiveKitCloudAuthProvider,\n} from './auth.js';\nimport { log } from './log.js';\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Structural type for the backend FrameProcessors the facade forwards to.\n *\n * Both backends are `FrameProcessor<AudioFrame>` implementations that additionally\n * expose a runtime-settable noise suppression level (not part of the base\n * FrameProcessor interface).\n */\ninterface KrispBackend extends FrameProcessor<AudioFrame> {\n readonly noiseSuppressionLevel: number;\n setNoiseSuppressionLevel(value: number): void;\n}\n\n/**\n * Options for {@link KrispVivaFilter}.\n * @public\n */\nexport interface KrispVivaFilterOptions {\n /**\n * Authentication backend. When omitted, it is resolved from the environment:\n * the Krisp license path ({@link KrispLicenseAuthProvider}) is used when both\n * `KRISP_VIVA_SDK_LICENSE_KEY` and `KRISP_VIVA_FILTER_MODEL_PATH` are set;\n * otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).\n */\n authProvider: AuthProvider;\n /** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default 75. */\n noiseSuppressionLevel: number;\n}\n\nconst DEFAULT_FRAME_DURATION_MS = 10;\n\n/**\n * Pick the auth backend when the caller did not pass one explicitly. Uses the\n * Krisp license path when both `KRISP_VIVA_SDK_LICENSE_KEY` and\n * `KRISP_VIVA_FILTER_MODEL_PATH` are set (the user is responsible for having the\n * proprietary `@krisp/viva-node-sdk` installed); otherwise falls back to LiveKit\n * Cloud auth.\n */\nfunction resolveAuthProvider(explicit?: AuthProvider): AuthProvider {\n if (explicit) {\n return explicit;\n }\n if (process.env.KRISP_VIVA_SDK_LICENSE_KEY && process.env.KRISP_VIVA_FILTER_MODEL_PATH) {\n log().debug('Krisp: using license auth (env vars set)');\n return new KrispLicenseAuthProvider();\n }\n log().debug('Krisp: using LiveKit Cloud auth');\n return new LiveKitCloudAuthProvider();\n}\n\nfunction buildBackend(\n mode: KrispInternal.VivaMode,\n provider: AuthProvider,\n noiseSuppressionLevel: number,\n): KrispBackend {\n if (provider.kind === LIVEKIT_CLOUD_KIND) {\n let mod: typeof KrispInternal;\n try {\n mod = require('@livekit/plugins-krisp-viva-internal');\n } catch {\n throw new Error(\n '@livekit/plugins-krisp-viva-internal is missing — this package is bundled ' +\n 'with @livekit/agents-plugin-krisp, so this likely means a broken install. ' +\n 'Reinstall the plugin, or pass a KrispLicenseAuthProvider if you have a Krisp ' +\n 'license key + .kef model.',\n );\n }\n return new mod.KrispVivaFilterFrameProcessor({\n mode,\n noiseSuppressionLevel,\n frameDurationMs: DEFAULT_FRAME_DURATION_MS,\n });\n }\n\n // KrispLicenseAuthProvider\n return new KrispLicenseFrameProcessor({\n modelPath: provider.modelPath,\n noiseSuppressionLevel,\n frameDurationMs: DEFAULT_FRAME_DURATION_MS,\n });\n}\n\n/**\n * FrameProcessor for Krisp noise reduction.\n *\n * Thin facade over two backend FrameProcessor implementations: the LiveKit\n * Cloud-bundled package and a local wrapper around the public\n * `@krisp/viva-node-sdk`. When no `authProvider` is given, the backend is\n * resolved from the environment (see {@link KrispVivaFilterOptions.authProvider}).\n *\n * @example\n * ```ts\n * import * as krisp from '@livekit/agents-plugin-krisp';\n *\n * // Auto-resolves: Krisp license path if both KRISP_VIVA_SDK_LICENSE_KEY and\n * // KRISP_VIVA_FILTER_MODEL_PATH are set, else LiveKit Cloud auth.\n * const processor = krisp.voiceIsolation();\n *\n * // Or pin a backend explicitly.\n * const processor = krisp.voiceIsolation({\n * authProvider: krisp.auth.krispLicense(),\n * });\n *\n * await session.start({\n * agent,\n * room: ctx.room,\n * inputOptions: { noiseCancellation: processor },\n * });\n * ```\n *\n * @public\n */\nexport class KrispVivaFilter extends FrameProcessor<AudioFrame> {\n private readonly inner: KrispBackend;\n\n constructor(\n opts: Partial<KrispVivaFilterOptions> = {},\n mode: KrispInternal.VivaMode = 'voiceIsolation',\n ) {\n super();\n const provider = resolveAuthProvider(opts.authProvider);\n this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ?? 75);\n }\n\n isEnabled(): boolean {\n return this.inner.isEnabled();\n }\n\n setEnabled(enabled: boolean): void {\n this.inner.setEnabled(enabled);\n }\n\n get noiseSuppressionLevel(): number {\n return this.inner.noiseSuppressionLevel;\n }\n\n /** Adjust the noise suppression level (0-100) at runtime. */\n setNoiseSuppressionLevel(value: number): void {\n this.inner.setNoiseSuppressionLevel(value);\n }\n\n override onStreamInfoUpdated(info: FrameProcessorStreamInfo): void {\n this.inner.onStreamInfoUpdated(info);\n }\n\n override onCredentialsUpdated(credentials: FrameProcessorCredentials): void {\n this.inner.onCredentialsUpdated(credentials);\n }\n\n process(frame: AudioFrame): AudioFrame {\n return adoptLocalAudioFrame(this.inner.process(frame));\n }\n\n close(): void {\n this.inner.close();\n }\n}\n"],"mappings":"AAsBA,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,SAAS,kCAAkC;AAC3C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW;AAEpB,MAAMA,WAAU,cAAc,YAAY,GAAG;AA8B7C,MAAM,4BAA4B;AASlC,SAAS,oBAAoB,UAAuC;AAClE,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AACA,MAAI,QAAQ,IAAI,8BAA8B,QAAQ,IAAI,8BAA8B;AACtF,QAAI,EAAE,MAAM,0CAA0C;AACtD,WAAO,IAAI,yBAAyB;AAAA,EACtC;AACA,MAAI,EAAE,MAAM,iCAAiC;AAC7C,SAAO,IAAI,yBAAyB;AACtC;AAEA,SAAS,aACP,MACA,UACA,uBACc;AACd,MAAI,SAAS,SAAS,oBAAoB;AACxC,QAAI;AACJ,QAAI;AACF,YAAMA,SAAQ,sCAAsC;AAAA,IACtD,QAAQ;AACN,YAAM,IAAI;AAAA,QACR;AAAA,MAIF;AAAA,IACF;AACA,WAAO,IAAI,IAAI,8BAA8B;AAAA,MAC3C;AAAA,MACA;AAAA,MACA,iBAAiB;AAAA,IACnB,CAAC;AAAA,EACH;AAGA,SAAO,IAAI,2BAA2B;AAAA,IACpC,WAAW,SAAS;AAAA,IACpB;AAAA,IACA,iBAAiB;AAAA,EACnB,CAAC;AACH;AAgCO,MAAM,wBAAwB,eAA2B;AAAA,EAC7C;AAAA,EAEjB,YACE,OAAwC,CAAC,GACzC,OAA+B,kBAC/B;AACA,UAAM;AACN,UAAM,WAAW,oBAAoB,KAAK,YAAY;AACtD,SAAK,QAAQ,aAAa,MAAM,UAAU,KAAK,yBAAyB,EAAE;AAAA,EAC5E;AAAA,EAEA,YAAqB;AACnB,WAAO,KAAK,MAAM,UAAU;AAAA,EAC9B;AAAA,EAEA,WAAW,SAAwB;AACjC,SAAK,MAAM,WAAW,OAAO;AAAA,EAC/B;AAAA,EAEA,IAAI,wBAAgC;AAClC,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA,EAGA,yBAAyB,OAAqB;AAC5C,SAAK,MAAM,yBAAyB,KAAK;AAAA,EAC3C;AAAA,EAES,oBAAoB,MAAsC;AACjE,SAAK,MAAM,oBAAoB,IAAI;AAAA,EACrC;AAAA,EAES,qBAAqB,aAA8C;AAC1E,SAAK,MAAM,qBAAqB,WAAW;AAAA,EAC7C;AAAA,EAEA,QAAQ,OAA+B;AACrC,WAAO,qBAAqB,KAAK,MAAM,QAAQ,KAAK,CAAC;AAAA,EACvD;AAAA,EAEA,QAAc;AACZ,SAAK,MAAM,MAAM;AAAA,EACnB;AACF;","names":["require"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/agents-plugin-krisp",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Krisp Audio plugin for LiveKit Node Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"require": "dist/index.cjs",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@livekit/rtc-node": "^0.13.
|
|
31
|
+
"@livekit/rtc-node": "^0.13.33",
|
|
32
32
|
"@microsoft/api-extractor": "^7.35.0",
|
|
33
33
|
"@types/ws": "^8.5.10",
|
|
34
34
|
"pino": "^8.19.0",
|
|
35
35
|
"tsup": "^8.3.5",
|
|
36
36
|
"typescript": "^5.0.0",
|
|
37
|
-
"@livekit/agents": "1.6.
|
|
38
|
-
"@livekit/agents-plugin-openai": "1.6.
|
|
39
|
-
"@livekit/agents-plugins-test": "1.6.
|
|
37
|
+
"@livekit/agents": "1.6.2",
|
|
38
|
+
"@livekit/agents-plugin-openai": "1.6.2",
|
|
39
|
+
"@livekit/agents-plugins-test": "1.6.2"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@livekit/plugins-krisp-viva-internal": "0.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@livekit/rtc-node": "^0.13.
|
|
46
|
-
"@livekit/agents": "1.6.
|
|
45
|
+
"@livekit/rtc-node": "^0.13.33",
|
|
46
|
+
"@livekit/agents": "1.6.2"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup --onSuccess \"pnpm build:types\"",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { AudioFrame } from '@livekit/rtc-node';
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { adoptLocalAudioFrame } from './_frame_identity.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Stands in for the `AudioFrame` of a second copy of `@livekit/rtc-node`: identical shape, same
|
|
10
|
+
* constructor name, unrelated identity. That is exactly what the CJS build produces when the
|
|
11
|
+
* Cloud backend pulls it in through `createRequire`.
|
|
12
|
+
*/
|
|
13
|
+
class ForeignAudioFrame {
|
|
14
|
+
constructor(
|
|
15
|
+
readonly data: Int16Array,
|
|
16
|
+
readonly sampleRate: number,
|
|
17
|
+
readonly channels: number,
|
|
18
|
+
readonly samplesPerChannel: number,
|
|
19
|
+
private readonly _userdata: Record<string, unknown> = {},
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
get userdata(): Record<string, unknown> {
|
|
23
|
+
return this._userdata;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('adoptLocalAudioFrame', () => {
|
|
28
|
+
it('adopts a frame built by another copy of rtc-node', () => {
|
|
29
|
+
const samples = new Int16Array([1, -2, 3, -4]);
|
|
30
|
+
const foreign = new ForeignAudioFrame(samples, 16000, 1, 4, { source: 'krisp' });
|
|
31
|
+
|
|
32
|
+
// The premise of the bug: this lookalike fails the identity check every consumer relies on.
|
|
33
|
+
expect(foreign instanceof AudioFrame).toBe(false);
|
|
34
|
+
|
|
35
|
+
const adopted = adoptLocalAudioFrame(foreign as unknown as AudioFrame);
|
|
36
|
+
|
|
37
|
+
expect(adopted instanceof AudioFrame).toBe(true);
|
|
38
|
+
expect(adopted.sampleRate).toBe(16000);
|
|
39
|
+
expect(adopted.channels).toBe(1);
|
|
40
|
+
expect(adopted.samplesPerChannel).toBe(4);
|
|
41
|
+
expect(adopted.userdata).toEqual({ source: 'krisp' });
|
|
42
|
+
// Adopting must not copy the audio: this runs on every frame of every session.
|
|
43
|
+
expect(adopted.data).toBe(samples);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns a local frame untouched', () => {
|
|
47
|
+
const local = new AudioFrame(new Int16Array([5, 6]), 48000, 1, 2);
|
|
48
|
+
|
|
49
|
+
expect(adoptLocalAudioFrame(local)).toBe(local);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { AudioFrame } from '@livekit/rtc-node';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Return a frame that belongs to *this* copy of `@livekit/rtc-node`.
|
|
8
|
+
*
|
|
9
|
+
* The Cloud backend is reached through `createRequire`, which resolves the internal package's
|
|
10
|
+
* `require` condition and so loads the CJS build of `@livekit/rtc-node` next to our ESM one.
|
|
11
|
+
* Frames it hands back are instances of that copy's `AudioFrame`, so `instanceof AudioFrame`
|
|
12
|
+
* fails everywhere downstream: audio recognition treats them as unrecognised sentinels and
|
|
13
|
+
* drops them, and adaptive interruption — never fed any audio — rules every barge-in a
|
|
14
|
+
* backchannel. `AudioFrame` is a plain data holder, so adopting one shares its samples rather
|
|
15
|
+
* than copying them.
|
|
16
|
+
*/
|
|
17
|
+
export function adoptLocalAudioFrame(frame: AudioFrame): AudioFrame {
|
|
18
|
+
if (frame instanceof AudioFrame) {
|
|
19
|
+
return frame;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Statically unreachable — the declared type *is* `AudioFrame`. It is reachable at runtime
|
|
23
|
+
// precisely because that type came from a different copy of the module.
|
|
24
|
+
const foreign = frame as unknown as {
|
|
25
|
+
data: Int16Array;
|
|
26
|
+
sampleRate: number;
|
|
27
|
+
channels: number;
|
|
28
|
+
samplesPerChannel: number;
|
|
29
|
+
userdata?: Record<string, unknown>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return new AudioFrame(
|
|
33
|
+
foreign.data,
|
|
34
|
+
foreign.sampleRate,
|
|
35
|
+
foreign.channels,
|
|
36
|
+
foreign.samplesPerChannel,
|
|
37
|
+
foreign.userdata,
|
|
38
|
+
);
|
|
39
|
+
}
|
package/src/viva_filter.ts
CHANGED
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
} from '@livekit/rtc-node';
|
|
23
23
|
import { FrameProcessor } from '@livekit/rtc-node';
|
|
24
24
|
import { createRequire } from 'node:module';
|
|
25
|
+
import { adoptLocalAudioFrame } from './_frame_identity.js';
|
|
25
26
|
import { KrispLicenseFrameProcessor } from './_krisp.js';
|
|
26
27
|
import {
|
|
27
28
|
type AuthProvider,
|
|
@@ -57,7 +58,7 @@ export interface KrispVivaFilterOptions {
|
|
|
57
58
|
* otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).
|
|
58
59
|
*/
|
|
59
60
|
authProvider: AuthProvider;
|
|
60
|
-
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default
|
|
61
|
+
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default 75. */
|
|
61
62
|
noiseSuppressionLevel: number;
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -153,7 +154,7 @@ export class KrispVivaFilter extends FrameProcessor<AudioFrame> {
|
|
|
153
154
|
) {
|
|
154
155
|
super();
|
|
155
156
|
const provider = resolveAuthProvider(opts.authProvider);
|
|
156
|
-
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ??
|
|
157
|
+
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ?? 75);
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
isEnabled(): boolean {
|
|
@@ -182,7 +183,7 @@ export class KrispVivaFilter extends FrameProcessor<AudioFrame> {
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
process(frame: AudioFrame): AudioFrame {
|
|
185
|
-
return this.inner.process(frame);
|
|
186
|
+
return adoptLocalAudioFrame(this.inner.process(frame));
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
close(): void {
|