@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
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 LiveKit, Inc.
|
|
3
|
+
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
-->
|
|
6
|
+
|
|
7
|
+
# Krisp VIVA plugin for LiveKit Agents
|
|
8
|
+
|
|
9
|
+
Real-time noise reduction for LiveKit voice agents using [Krisp's VIVA SDK](https://krisp.ai), exposed as a LiveKit `FrameProcessor`.
|
|
10
|
+
|
|
11
|
+
See [https://docs.livekit.io/agents/integrations/](https://docs.livekit.io/agents/integrations/) for more information.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @livekit/agents-plugin-krisp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The default backend is bundled with the plugin and authenticates through LiveKit Cloud using the room's credentials — no separate SDK download, license key, or model file is required.
|
|
20
|
+
|
|
21
|
+
> Using your own [Krisp license](#alternative-krisp-license-auth) instead? That path has additional prerequisites — see below.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
`krisp.voiceIsolation()` resolves its backend from the environment: if both `KRISP_VIVA_SDK_LICENSE_KEY` and `KRISP_VIVA_FILTER_MODEL_PATH` are set, it uses the [Krisp license path](#alternative-krisp-license-auth) (you are responsible for installing `@krisp/viva-node-sdk`); otherwise it uses **LiveKit Cloud** authentication — the bundled backend ships the voice isolation model and authenticates against LiveKit Cloud using the room JWT the agent framework hands to the `FrameProcessor` automatically. Pass `authProvider` to pin a backend explicitly.
|
|
26
|
+
|
|
27
|
+
For telephony audio, use `krisp.voiceIsolationTelephony()` instead — it takes the same options and behaves identically, but selects a noise-reduction model tuned for telephony.
|
|
28
|
+
|
|
29
|
+
Pass the processor as `noiseCancellation` in the session's input options:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { type JobContext, voice } from '@livekit/agents';
|
|
33
|
+
import * as krisp from '@livekit/agents-plugin-krisp';
|
|
34
|
+
import * as openai from '@livekit/agents-plugin-openai';
|
|
35
|
+
import * as silero from '@livekit/agents-plugin-silero';
|
|
36
|
+
|
|
37
|
+
export default async function entry(ctx: JobContext) {
|
|
38
|
+
// Default: LiveKit Cloud auth + bundled model. No keys or model files.
|
|
39
|
+
const noiseCancellation = krisp.voiceIsolation({
|
|
40
|
+
noiseSuppressionLevel: 100, // 0-100
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const session = new voice.AgentSession({
|
|
44
|
+
vad: await silero.VAD.load(),
|
|
45
|
+
stt: new openai.STT(),
|
|
46
|
+
llm: new openai.LLM({ model: 'gpt-4o-mini' }),
|
|
47
|
+
tts: new openai.TTS(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await session.start({
|
|
51
|
+
agent: new voice.Agent({ instructions: 'You are a helpful assistant.' }),
|
|
52
|
+
room: ctx.room,
|
|
53
|
+
inputOptions: {
|
|
54
|
+
// Pass the FrameProcessor directly.
|
|
55
|
+
noiseCancellation,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Audio pipeline:** `Room → RoomIO (with voiceIsolation) → VAD → STT → LLM`
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
### `KrispVivaFilterOptions`
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
| ----------------------- | -------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| `authProvider` | `AuthProvider` | `LiveKitCloudAuthProvider` | Authentication backend. Defaults to LiveKit Cloud. See [the alternative](#alternative-krisp-license-auth). |
|
|
70
|
+
| `noiseSuppressionLevel` | `number` | `100` | Noise reduction intensity (0-100). |
|
|
71
|
+
|
|
72
|
+
Input frames of any size and sample rate are buffered and adapted automatically.
|
|
73
|
+
|
|
74
|
+
### Runtime control
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
noiseCancellation.setEnabled(false); // pass audio through unmodified
|
|
78
|
+
noiseCancellation.setNoiseSuppressionLevel(50); // adjust 0-100 on the fly
|
|
79
|
+
noiseCancellation.close(); // free resources when done
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Alternative: Krisp license auth
|
|
83
|
+
|
|
84
|
+
> **Most users should use the default LiveKit Cloud path above.** This alternative is for running the proprietary Krisp SDK directly with your own Krisp license — for example, when using the LiveKit OSS server.
|
|
85
|
+
|
|
86
|
+
This path uses the proprietary `@krisp/viva-node-sdk` together with a Krisp license key and a `.kef` model file that you obtain from Krisp.
|
|
87
|
+
|
|
88
|
+
### Prerequisites
|
|
89
|
+
|
|
90
|
+
1. **Krisp Node SDK** — proprietary, not bundled with this plugin. Obtain and install it separately from [Krisp](https://krisp.ai/developers/):
|
|
91
|
+
```bash
|
|
92
|
+
pnpm add @krisp/viva-node-sdk
|
|
93
|
+
```
|
|
94
|
+
2. **License key**:
|
|
95
|
+
```bash
|
|
96
|
+
export KRISP_VIVA_SDK_LICENSE_KEY=your-license-key-here
|
|
97
|
+
```
|
|
98
|
+
3. **Noise-reduction model** — a `.kef` model file from Krisp:
|
|
99
|
+
```bash
|
|
100
|
+
export KRISP_VIVA_FILTER_MODEL_PATH=/path/to/noise_model.kef
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Usage
|
|
104
|
+
|
|
105
|
+
Select the license backend by passing `authProvider`. Both the model path and
|
|
106
|
+
the license key come from the environment variables above (read by the native
|
|
107
|
+
SDK), so `krispLicense()` takes no arguments:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import * as krisp from '@livekit/agents-plugin-krisp';
|
|
111
|
+
|
|
112
|
+
const noiseCancellation = krisp.voiceIsolation({
|
|
113
|
+
authProvider: krisp.auth.krispLicense(),
|
|
114
|
+
noiseSuppressionLevel: 100,
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Troubleshooting
|
|
119
|
+
|
|
120
|
+
### `@livekit/plugins-krisp-viva-internal` is missing
|
|
121
|
+
|
|
122
|
+
The default (LiveKit Cloud) backend is bundled as a dependency. If it reports as missing, the install is likely broken — reinstall the plugin, or fall back to the [Krisp license auth](#alternative-krisp-license-auth) path.
|
|
123
|
+
|
|
124
|
+
### "@krisp/viva-node-sdk is not installed" _(license auth only)_
|
|
125
|
+
|
|
126
|
+
Install the proprietary Krisp Node SDK (`pnpm add @krisp/viva-node-sdk`), or use the default `auth.livekitCloud()` provider.
|
|
127
|
+
|
|
128
|
+
### "Krisp model path is required" / "Krisp model file not found" _(license auth only)_
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
export KRISP_VIVA_FILTER_MODEL_PATH=/path/to/model.kef
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### "Unsupported sample rate"
|
|
135
|
+
|
|
136
|
+
Supported: 8000, 16000, 24000, 32000, 44100, 48000 Hz.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
The source code in this package (`@livekit/agents-plugin-krisp`) is licensed under the **Apache-2.0** license.
|
|
141
|
+
|
|
142
|
+
The **default backend** is a separate, closed-source package (`@livekit/plugins-krisp-viva-internal`) installed automatically as a dependency. It is **proprietary** and distributed under the [LiveKit Terms of Service](https://livekit.io/legal/terms-of-service). That package bundles the Krisp VIVA SDK along with its third-party open-source components.
|
|
143
|
+
|
|
144
|
+
The **Krisp license alternative** (`KrispLicenseAuthProvider`) instead needs a manual install of the proprietary `@krisp/viva-node-sdk` together with your own Krisp license key and model file, governed by your agreement with [Krisp](https://krisp.ai).
|
package/dist/_krisp.cjs
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
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 krisp_exports = {};
|
|
20
|
+
__export(krisp_exports, {
|
|
21
|
+
KrispLicenseFrameProcessor: () => KrispLicenseFrameProcessor
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(krisp_exports);
|
|
24
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
25
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
26
|
+
var import_rtc_node = require("@livekit/rtc-node");
|
|
27
|
+
var import_node_module = require("node:module");
|
|
28
|
+
var import_log = require("./log.cjs");
|
|
29
|
+
const require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
30
|
+
const SUPPORTED_SAMPLE_RATES = [8e3, 16e3, 24e3, 32e3, 44100, 48e3];
|
|
31
|
+
const SUPPORTED_FRAME_DURATIONS_MS = [10, 15, 20, 30, 32];
|
|
32
|
+
function samplingRateEnum(mod, sampleRate) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const value = (_b = (_a = mod.enums) == null ? void 0 : _a.SamplingRate) == null ? void 0 : _b[`Sr${sampleRate}Hz`];
|
|
35
|
+
if (value === void 0) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Unsupported sample rate: ${sampleRate} Hz. Supported rates: ${SUPPORTED_SAMPLE_RATES.join(", ")} Hz`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function frameDurationEnum(mod, frameDurationMs) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const value = (_b = (_a = mod.enums) == null ? void 0 : _a.FrameDuration) == null ? void 0 : _b[`Fd${frameDurationMs}ms`];
|
|
45
|
+
if (value === void 0) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Unsupported frame duration: ${frameDurationMs} ms. Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(", ")} ms`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
class KrispLicenseSdkManager {
|
|
53
|
+
static module = null;
|
|
54
|
+
static referenceCount = 0;
|
|
55
|
+
/** Acquire a reference, returning the loaded `@krisp/viva-node-sdk` module. */
|
|
56
|
+
static acquire() {
|
|
57
|
+
if (this.referenceCount === 0) {
|
|
58
|
+
let mod;
|
|
59
|
+
try {
|
|
60
|
+
mod = require2("@krisp/viva-node-sdk");
|
|
61
|
+
} catch {
|
|
62
|
+
throw new Error(
|
|
63
|
+
"@krisp/viva-node-sdk is not installed. Install the proprietary Krisp Node SDK (`pnpm add @krisp/viva-node-sdk`) and provide a .kef model, or use the default LiveKit Cloud auth provider (auth.livekitCloud())."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const licenseKey = process.env.KRISP_VIVA_SDK_LICENSE_KEY;
|
|
67
|
+
if (licenseKey) {
|
|
68
|
+
mod.globalInit("", licenseKey);
|
|
69
|
+
} else {
|
|
70
|
+
mod.globalInit("");
|
|
71
|
+
}
|
|
72
|
+
this.module = mod;
|
|
73
|
+
(0, import_log.log)().debug("Krisp Audio SDK (license) initialized");
|
|
74
|
+
}
|
|
75
|
+
this.referenceCount += 1;
|
|
76
|
+
(0, import_log.log)().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);
|
|
77
|
+
return this.module;
|
|
78
|
+
}
|
|
79
|
+
/** Release a reference, destroying the SDK on the last release. */
|
|
80
|
+
static release() {
|
|
81
|
+
if (this.referenceCount === 0) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.referenceCount -= 1;
|
|
85
|
+
(0, import_log.log)().debug(`Krisp SDK (license) reference count: ${this.referenceCount}`);
|
|
86
|
+
if (this.referenceCount === 0 && this.module !== null) {
|
|
87
|
+
try {
|
|
88
|
+
this.module.globalDestroy();
|
|
89
|
+
(0, import_log.log)().debug("Krisp Audio SDK (license) destroyed");
|
|
90
|
+
} catch (e) {
|
|
91
|
+
(0, import_log.log)().error(`Error during Krisp SDK cleanup: ${e}`);
|
|
92
|
+
} finally {
|
|
93
|
+
this.module = null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function concatInt16(a, b) {
|
|
99
|
+
const out = new Int16Array(a.length + b.length);
|
|
100
|
+
out.set(a, 0);
|
|
101
|
+
out.set(b, a.length);
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
function bufferToInt16(buf) {
|
|
105
|
+
const usableBytes = buf.byteLength - buf.byteLength % 2;
|
|
106
|
+
const copy = buf.buffer.slice(buf.byteOffset, buf.byteOffset + usableBytes);
|
|
107
|
+
return new Int16Array(copy);
|
|
108
|
+
}
|
|
109
|
+
function clampLevel(value) {
|
|
110
|
+
return Math.max(0, Math.min(100, Math.round(value)));
|
|
111
|
+
}
|
|
112
|
+
class KrispLicenseFrameProcessor extends import_rtc_node.FrameProcessor {
|
|
113
|
+
enabled = true;
|
|
114
|
+
sdkAcquired = false;
|
|
115
|
+
module;
|
|
116
|
+
session = null;
|
|
117
|
+
level;
|
|
118
|
+
frameDurationMs;
|
|
119
|
+
modelPath;
|
|
120
|
+
sampleRate = null;
|
|
121
|
+
chunkSamples = null;
|
|
122
|
+
warnedChannels = false;
|
|
123
|
+
inBuf = new Int16Array(0);
|
|
124
|
+
outBuf = new Int16Array(0);
|
|
125
|
+
constructor(opts) {
|
|
126
|
+
super();
|
|
127
|
+
this.level = clampLevel(opts.noiseSuppressionLevel);
|
|
128
|
+
this.frameDurationMs = opts.frameDurationMs;
|
|
129
|
+
this.modelPath = opts.modelPath;
|
|
130
|
+
if (!SUPPORTED_FRAME_DURATIONS_MS.includes(this.frameDurationMs)) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Unsupported frame duration: ${this.frameDurationMs} ms. Supported durations: ${SUPPORTED_FRAME_DURATIONS_MS.join(", ")} ms`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
this.module = KrispLicenseSdkManager.acquire();
|
|
136
|
+
this.sdkAcquired = true;
|
|
137
|
+
try {
|
|
138
|
+
this.createSession(16e3);
|
|
139
|
+
(0, import_log.log)().info("Krisp license frame processor initialized (adapts to input sample rate)");
|
|
140
|
+
} catch (e) {
|
|
141
|
+
this.teardown();
|
|
142
|
+
throw e;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
createSession(sampleRate) {
|
|
146
|
+
if (this.session !== null && this.sampleRate === sampleRate) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (!SUPPORTED_SAMPLE_RATES.includes(sampleRate)) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Unsupported sample rate: ${sampleRate} Hz. Supported rates: ${SUPPORTED_SAMPLE_RATES.join(", ")} Hz`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
(0, import_log.log)().info(`Creating Krisp session for sample rate: ${sampleRate}Hz`);
|
|
155
|
+
if (this.session !== null) {
|
|
156
|
+
try {
|
|
157
|
+
this.session.destroy();
|
|
158
|
+
} catch (e) {
|
|
159
|
+
(0, import_log.log)().error(`Error destroying Krisp session: ${e}`);
|
|
160
|
+
}
|
|
161
|
+
this.session = null;
|
|
162
|
+
}
|
|
163
|
+
const inputSampleRate = samplingRateEnum(this.module, sampleRate);
|
|
164
|
+
const config = {
|
|
165
|
+
inputSampleRate,
|
|
166
|
+
inputFrameDuration: frameDurationEnum(this.module, this.frameDurationMs),
|
|
167
|
+
outputSampleRate: inputSampleRate,
|
|
168
|
+
modelInfo: { path: this.modelPath }
|
|
169
|
+
};
|
|
170
|
+
this.session = this.module.NcInt16.create(config);
|
|
171
|
+
this.sampleRate = sampleRate;
|
|
172
|
+
this.chunkSamples = Math.floor(sampleRate * this.frameDurationMs / 1e3);
|
|
173
|
+
this.inBuf = new Int16Array(0);
|
|
174
|
+
this.outBuf = new Int16Array(0);
|
|
175
|
+
}
|
|
176
|
+
isEnabled() {
|
|
177
|
+
return this.enabled;
|
|
178
|
+
}
|
|
179
|
+
setEnabled(enabled) {
|
|
180
|
+
if (this.enabled === enabled) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.enabled = enabled;
|
|
184
|
+
this.inBuf = new Int16Array(0);
|
|
185
|
+
this.outBuf = new Int16Array(0);
|
|
186
|
+
}
|
|
187
|
+
get noiseSuppressionLevel() {
|
|
188
|
+
return this.level;
|
|
189
|
+
}
|
|
190
|
+
setNoiseSuppressionLevel(value) {
|
|
191
|
+
this.level = clampLevel(value);
|
|
192
|
+
}
|
|
193
|
+
process(frame) {
|
|
194
|
+
if (!this.enabled) {
|
|
195
|
+
return frame;
|
|
196
|
+
}
|
|
197
|
+
if (frame.channels !== 1) {
|
|
198
|
+
if (!this.warnedChannels) {
|
|
199
|
+
(0, import_log.log)().warn(
|
|
200
|
+
`Krisp filter not applied: expected mono audio but got ${frame.channels} channels; frames are passed through unprocessed.`
|
|
201
|
+
);
|
|
202
|
+
this.warnedChannels = true;
|
|
203
|
+
}
|
|
204
|
+
return frame;
|
|
205
|
+
}
|
|
206
|
+
if (this.session === null || this.sampleRate !== frame.sampleRate) {
|
|
207
|
+
this.createSession(frame.sampleRate);
|
|
208
|
+
}
|
|
209
|
+
const chunk = this.chunkSamples;
|
|
210
|
+
this.inBuf = concatInt16(this.inBuf, frame.data);
|
|
211
|
+
const nChunks = Math.floor(this.inBuf.length / chunk);
|
|
212
|
+
if (nChunks > 0) {
|
|
213
|
+
const consumed = nChunks * chunk;
|
|
214
|
+
const pending = this.inBuf.subarray(0, consumed);
|
|
215
|
+
this.inBuf = this.inBuf.slice(consumed);
|
|
216
|
+
for (let i = 0; i < nChunks; i++) {
|
|
217
|
+
const chunkIn = pending.subarray(i * chunk, (i + 1) * chunk);
|
|
218
|
+
let chunkOut;
|
|
219
|
+
try {
|
|
220
|
+
const inputBuf = Buffer.from(chunkIn.buffer, chunkIn.byteOffset, chunkIn.byteLength);
|
|
221
|
+
const outputBuf = this.session.process(inputBuf, this.level);
|
|
222
|
+
chunkOut = bufferToInt16(outputBuf);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
(0, import_log.log)().error(`Error processing frame: ${e}`);
|
|
225
|
+
chunkOut = chunkIn;
|
|
226
|
+
}
|
|
227
|
+
if (chunkOut.length !== chunk) {
|
|
228
|
+
(0, import_log.log)().warn(
|
|
229
|
+
`Krisp returned ${chunkOut.length} samples, expected ${chunk}; using original audio`
|
|
230
|
+
);
|
|
231
|
+
chunkOut = chunkIn;
|
|
232
|
+
}
|
|
233
|
+
this.outBuf = concatInt16(this.outBuf, chunkOut);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const n = frame.samplesPerChannel;
|
|
237
|
+
const k = Math.min(n, this.outBuf.length);
|
|
238
|
+
const out = this.outBuf.slice(0, k);
|
|
239
|
+
this.outBuf = this.outBuf.slice(k);
|
|
240
|
+
return new import_rtc_node.AudioFrame(out, frame.sampleRate, frame.channels, out.length);
|
|
241
|
+
}
|
|
242
|
+
teardown() {
|
|
243
|
+
if (this.session !== null) {
|
|
244
|
+
try {
|
|
245
|
+
this.session.destroy();
|
|
246
|
+
} catch (e) {
|
|
247
|
+
(0, import_log.log)().error(`Error destroying Krisp session: ${e}`);
|
|
248
|
+
}
|
|
249
|
+
this.session = null;
|
|
250
|
+
}
|
|
251
|
+
this.inBuf = new Int16Array(0);
|
|
252
|
+
this.outBuf = new Int16Array(0);
|
|
253
|
+
if (this.sdkAcquired) {
|
|
254
|
+
KrispLicenseSdkManager.release();
|
|
255
|
+
this.sdkAcquired = false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
close() {
|
|
259
|
+
this.teardown();
|
|
260
|
+
(0, import_log.log)().debug("Krisp license frame processor closed");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
264
|
+
0 && (module.exports = {
|
|
265
|
+
KrispLicenseFrameProcessor
|
|
266
|
+
});
|
|
267
|
+
//# sourceMappingURL=_krisp.cjs.map
|
|
@@ -0,0 +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.21.0_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,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