@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.
- package/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/_krisp.cjs +267 -0
- package/dist/_krisp.cjs.map +1 -0
- package/dist/_krisp.d.cts +43 -0
- package/dist/_krisp.d.ts +43 -0
- package/dist/_krisp.d.ts.map +1 -0
- package/dist/_krisp.js +241 -0
- package/dist/_krisp.js.map +1 -0
- package/dist/_krisp_sdk.d.cjs +2 -0
- package/dist/_krisp_sdk.d.cjs.map +1 -0
- package/dist/_krisp_sdk.d.js +1 -0
- package/dist/_krisp_sdk.d.js.map +1 -0
- package/dist/auth.cjs +69 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +57 -0
- package/dist/auth.d.ts +57 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +41 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.cjs +55 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/log.cjs +30 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.d.cts +3 -0
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +6 -0
- package/dist/log.js.map +1 -0
- package/dist/viva_filter.cjs +103 -0
- package/dist/viva_filter.cjs.map +1 -0
- package/dist/viva_filter.d.cts +75 -0
- package/dist/viva_filter.d.ts +75 -0
- package/dist/viva_filter.d.ts.map +1 -0
- package/dist/viva_filter.js +81 -0
- package/dist/viva_filter.js.map +1 -0
- package/package.json +54 -0
- package/src/_krisp.ts +366 -0
- package/src/_krisp_sdk.d.ts +57 -0
- package/src/auth.ts +109 -0
- package/src/index.ts +78 -0
- package/src/log.ts +7 -0
- package/src/viva_filter.ts +191 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Krisp VIVA noise reduction audio filter for LiveKit Agents.
|
|
7
|
+
*
|
|
8
|
+
* Exposes {@link KrispVivaFilter}, a thin facade that forwards to
|
|
9
|
+
* one of two underlying FrameProcessor implementations:
|
|
10
|
+
*
|
|
11
|
+
* - The closed-source `@livekit/plugins-krisp-viva-internal` backend (default;
|
|
12
|
+
* authenticates via the LiveKit Cloud-managed JWT the agent framework hands to
|
|
13
|
+
* FrameProcessors through `onCredentialsUpdated`).
|
|
14
|
+
* - A local license-mode wrapper around `@krisp/viva-node-sdk` (selected when the
|
|
15
|
+
* user passes a {@link KrispLicenseAuthProvider}).
|
|
16
|
+
*/
|
|
17
|
+
import type * as KrispInternal from '@livekit/plugins-krisp-viva-internal';
|
|
18
|
+
import type {
|
|
19
|
+
AudioFrame,
|
|
20
|
+
FrameProcessorCredentials,
|
|
21
|
+
FrameProcessorStreamInfo,
|
|
22
|
+
} from '@livekit/rtc-node';
|
|
23
|
+
import { FrameProcessor } from '@livekit/rtc-node';
|
|
24
|
+
import { createRequire } from 'node:module';
|
|
25
|
+
import { KrispLicenseFrameProcessor } from './_krisp.js';
|
|
26
|
+
import {
|
|
27
|
+
type AuthProvider,
|
|
28
|
+
KrispLicenseAuthProvider,
|
|
29
|
+
LIVEKIT_CLOUD_KIND,
|
|
30
|
+
LiveKitCloudAuthProvider,
|
|
31
|
+
} from './auth.js';
|
|
32
|
+
import { log } from './log.js';
|
|
33
|
+
|
|
34
|
+
const require = createRequire(import.meta.url);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Structural type for the backend FrameProcessors the facade forwards to.
|
|
38
|
+
*
|
|
39
|
+
* Both backends are `FrameProcessor<AudioFrame>` implementations that additionally
|
|
40
|
+
* expose a runtime-settable noise suppression level (not part of the base
|
|
41
|
+
* FrameProcessor interface).
|
|
42
|
+
*/
|
|
43
|
+
interface KrispBackend extends FrameProcessor<AudioFrame> {
|
|
44
|
+
readonly noiseSuppressionLevel: number;
|
|
45
|
+
setNoiseSuppressionLevel(value: number): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Options for {@link KrispVivaFilter}.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface KrispVivaFilterOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Authentication backend. When omitted, it is resolved from the environment:
|
|
55
|
+
* the Krisp license path ({@link KrispLicenseAuthProvider}) is used when both
|
|
56
|
+
* `KRISP_VIVA_SDK_LICENSE_KEY` and `KRISP_VIVA_FILTER_MODEL_PATH` are set;
|
|
57
|
+
* otherwise it falls back to LiveKit Cloud auth ({@link LiveKitCloudAuthProvider}).
|
|
58
|
+
*/
|
|
59
|
+
authProvider: AuthProvider;
|
|
60
|
+
/** Noise suppression strength, 0..=100 where 100 is maximum suppression. Default 100. */
|
|
61
|
+
noiseSuppressionLevel: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const DEFAULT_FRAME_DURATION_MS = 10;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Pick the auth backend when the caller did not pass one explicitly. Uses the
|
|
68
|
+
* Krisp license path when both `KRISP_VIVA_SDK_LICENSE_KEY` and
|
|
69
|
+
* `KRISP_VIVA_FILTER_MODEL_PATH` are set (the user is responsible for having the
|
|
70
|
+
* proprietary `@krisp/viva-node-sdk` installed); otherwise falls back to LiveKit
|
|
71
|
+
* Cloud auth.
|
|
72
|
+
*/
|
|
73
|
+
function resolveAuthProvider(explicit?: AuthProvider): AuthProvider {
|
|
74
|
+
if (explicit) {
|
|
75
|
+
return explicit;
|
|
76
|
+
}
|
|
77
|
+
if (process.env.KRISP_VIVA_SDK_LICENSE_KEY && process.env.KRISP_VIVA_FILTER_MODEL_PATH) {
|
|
78
|
+
log().debug('Krisp: using license auth (env vars set)');
|
|
79
|
+
return new KrispLicenseAuthProvider();
|
|
80
|
+
}
|
|
81
|
+
log().debug('Krisp: using LiveKit Cloud auth');
|
|
82
|
+
return new LiveKitCloudAuthProvider();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function buildBackend(
|
|
86
|
+
mode: KrispInternal.VivaMode,
|
|
87
|
+
provider: AuthProvider,
|
|
88
|
+
noiseSuppressionLevel: number,
|
|
89
|
+
): KrispBackend {
|
|
90
|
+
if (provider.kind === LIVEKIT_CLOUD_KIND) {
|
|
91
|
+
let mod: typeof KrispInternal;
|
|
92
|
+
try {
|
|
93
|
+
mod = require('@livekit/plugins-krisp-viva-internal');
|
|
94
|
+
} catch {
|
|
95
|
+
throw new Error(
|
|
96
|
+
'@livekit/plugins-krisp-viva-internal is missing — this package is bundled ' +
|
|
97
|
+
'with @livekit/agents-plugin-krisp, so this likely means a broken install. ' +
|
|
98
|
+
'Reinstall the plugin, or pass a KrispLicenseAuthProvider if you have a Krisp ' +
|
|
99
|
+
'license key + .kef model.',
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return new mod.KrispVivaFilterFrameProcessor({
|
|
103
|
+
mode,
|
|
104
|
+
noiseSuppressionLevel,
|
|
105
|
+
frameDurationMs: DEFAULT_FRAME_DURATION_MS,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// KrispLicenseAuthProvider
|
|
110
|
+
return new KrispLicenseFrameProcessor({
|
|
111
|
+
modelPath: provider.modelPath,
|
|
112
|
+
noiseSuppressionLevel,
|
|
113
|
+
frameDurationMs: DEFAULT_FRAME_DURATION_MS,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* FrameProcessor for Krisp noise reduction.
|
|
119
|
+
*
|
|
120
|
+
* Thin facade over two backend FrameProcessor implementations: the LiveKit
|
|
121
|
+
* Cloud-bundled package and a local wrapper around the public
|
|
122
|
+
* `@krisp/viva-node-sdk`. When no `authProvider` is given, the backend is
|
|
123
|
+
* resolved from the environment (see {@link KrispVivaFilterOptions.authProvider}).
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import * as krisp from '@livekit/agents-plugin-krisp';
|
|
128
|
+
*
|
|
129
|
+
* // Auto-resolves: Krisp license path if both KRISP_VIVA_SDK_LICENSE_KEY and
|
|
130
|
+
* // KRISP_VIVA_FILTER_MODEL_PATH are set, else LiveKit Cloud auth.
|
|
131
|
+
* const processor = krisp.voiceIsolation();
|
|
132
|
+
*
|
|
133
|
+
* // Or pin a backend explicitly.
|
|
134
|
+
* const processor = krisp.voiceIsolation({
|
|
135
|
+
* authProvider: krisp.auth.krispLicense(),
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* await session.start({
|
|
139
|
+
* agent,
|
|
140
|
+
* room: ctx.room,
|
|
141
|
+
* inputOptions: { noiseCancellation: processor },
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
export class KrispVivaFilter extends FrameProcessor<AudioFrame> {
|
|
148
|
+
private readonly inner: KrispBackend;
|
|
149
|
+
|
|
150
|
+
constructor(
|
|
151
|
+
opts: Partial<KrispVivaFilterOptions> = {},
|
|
152
|
+
mode: KrispInternal.VivaMode = 'voiceIsolation',
|
|
153
|
+
) {
|
|
154
|
+
super();
|
|
155
|
+
const provider = resolveAuthProvider(opts.authProvider);
|
|
156
|
+
this.inner = buildBackend(mode, provider, opts.noiseSuppressionLevel ?? 100);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
isEnabled(): boolean {
|
|
160
|
+
return this.inner.isEnabled();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
setEnabled(enabled: boolean): void {
|
|
164
|
+
this.inner.setEnabled(enabled);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get noiseSuppressionLevel(): number {
|
|
168
|
+
return this.inner.noiseSuppressionLevel;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Adjust the noise suppression level (0-100) at runtime. */
|
|
172
|
+
setNoiseSuppressionLevel(value: number): void {
|
|
173
|
+
this.inner.setNoiseSuppressionLevel(value);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
override onStreamInfoUpdated(info: FrameProcessorStreamInfo): void {
|
|
177
|
+
this.inner.onStreamInfoUpdated(info);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override onCredentialsUpdated(credentials: FrameProcessorCredentials): void {
|
|
181
|
+
this.inner.onCredentialsUpdated(credentials);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
process(frame: AudioFrame): AudioFrame {
|
|
185
|
+
return this.inner.process(frame);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
close(): void {
|
|
189
|
+
this.inner.close();
|
|
190
|
+
}
|
|
191
|
+
}
|