@voltkit-rtc/client 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +102 -0
  3. package/dist/cjs/diagnostics.d.ts +1 -1
  4. package/dist/cjs/diagnostics.js +1 -1
  5. package/dist/cjs/effects-core.d.ts +95 -0
  6. package/dist/cjs/effects-core.d.ts.map +1 -0
  7. package/dist/cjs/effects-core.js +154 -0
  8. package/dist/cjs/effects-core.js.map +1 -0
  9. package/dist/cjs/effects-gl.d.ts +79 -0
  10. package/dist/cjs/effects-gl.d.ts.map +1 -0
  11. package/dist/cjs/effects-gl.js +351 -0
  12. package/dist/cjs/effects-gl.js.map +1 -0
  13. package/dist/cjs/index.d.ts +57 -0
  14. package/dist/cjs/index.d.ts.map +1 -1
  15. package/dist/cjs/index.js +278 -64
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/noise-suppression.d.ts +44 -0
  18. package/dist/cjs/noise-suppression.d.ts.map +1 -0
  19. package/dist/cjs/noise-suppression.js +103 -0
  20. package/dist/cjs/noise-suppression.js.map +1 -0
  21. package/dist/cjs/processors.d.ts +34 -0
  22. package/dist/cjs/processors.d.ts.map +1 -0
  23. package/dist/cjs/processors.js +10 -0
  24. package/dist/cjs/processors.js.map +1 -0
  25. package/dist/cjs/video-effects.d.ts +93 -0
  26. package/dist/cjs/video-effects.d.ts.map +1 -0
  27. package/dist/cjs/video-effects.js +493 -0
  28. package/dist/cjs/video-effects.js.map +1 -0
  29. package/dist/esm/diagnostics.d.ts +1 -1
  30. package/dist/esm/diagnostics.js +1 -1
  31. package/dist/esm/effects-core.d.ts +95 -0
  32. package/dist/esm/effects-core.d.ts.map +1 -0
  33. package/dist/esm/effects-core.js +142 -0
  34. package/dist/esm/effects-core.js.map +1 -0
  35. package/dist/esm/effects-gl.d.ts +79 -0
  36. package/dist/esm/effects-gl.d.ts.map +1 -0
  37. package/dist/esm/effects-gl.js +347 -0
  38. package/dist/esm/effects-gl.js.map +1 -0
  39. package/dist/esm/index.d.ts +57 -0
  40. package/dist/esm/index.d.ts.map +1 -1
  41. package/dist/esm/index.js +278 -64
  42. package/dist/esm/index.js.map +1 -1
  43. package/dist/esm/noise-suppression.d.ts +44 -0
  44. package/dist/esm/noise-suppression.d.ts.map +1 -0
  45. package/dist/esm/noise-suppression.js +99 -0
  46. package/dist/esm/noise-suppression.js.map +1 -0
  47. package/dist/esm/processors.d.ts +34 -0
  48. package/dist/esm/processors.d.ts.map +1 -0
  49. package/dist/esm/processors.js +9 -0
  50. package/dist/esm/processors.js.map +1 -0
  51. package/dist/esm/video-effects.d.ts +93 -0
  52. package/dist/esm/video-effects.d.ts.map +1 -0
  53. package/dist/esm/video-effects.js +488 -0
  54. package/dist/esm/video-effects.js.map +1 -0
  55. package/package.json +31 -1
  56. package/src/diagnostics.ts +1 -1
  57. package/src/effects-core.ts +177 -0
  58. package/src/effects-gl.ts +384 -0
  59. package/src/index.ts +276 -63
  60. package/src/noise-suppression.ts +135 -0
  61. package/src/processors.ts +35 -0
  62. package/src/video-effects.ts +552 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * AI noise suppression for the microphone (docs/implementation-progress/RTC_PERF_PROGRESS.md P3-4): what Agora's AI
3
+ * Denoiser, LiveKit's Krisp filter and ZEGOCLOUD's AI noise suppression do, with RNNoise -- the open neural-network
4
+ * denoiser Jitsi uses -- through `@sapphi-red/web-noise-suppressor` (MIT): a Web Audio worklet in the browser's
5
+ * audio thread. Fans, traffic and room rumble fall away (measured in Chromium: rumble-like noise down by more than
6
+ * 60 dB, steady white hiss by 7-12 dB); voices stay.
7
+ *
8
+ * Imported on its own (`@voltkit-rtc/client/noise-suppression`), so an app that does not use it never ships it:
9
+ *
10
+ * import { createNoiseSuppressor } from '@voltkit-rtc/client/noise-suppression';
11
+ * await client.setAudioProcessor(createNoiseSuppressor());
12
+ *
13
+ * The worklet (64 kB) and the model (150 kB) are fetched when it starts: from jsDelivr, at the exact version this
14
+ * SDK was tested with, unless you serve them yourself (`workletUrl`, `wasmUrl`, `simdWasmUrl`) -- copy them from
15
+ * `node_modules/@sapphi-red/web-noise-suppressor/dist` to your own site for a strict Content-Security-Policy.
16
+ */
17
+ import type { AudioTrackProcessor } from './processors.js';
18
+ /** The package version the default URLs point at; equal to this SDK's pinned dependency (a test checks it). */
19
+ export declare const NOISE_SUPPRESSOR_VERSION = "0.4.1";
20
+ export interface NoiseSuppressorOptions {
21
+ /** Where `rnnoise/workletProcessor.js` is served. Default: jsDelivr, pinned. */
22
+ workletUrl?: string;
23
+ /** Where `rnnoise.wasm` is served. Default: jsDelivr, pinned. */
24
+ wasmUrl?: string;
25
+ /** Where `rnnoise_simd.wasm` is served (used where the browser supports SIMD). Default: jsDelivr, pinned. */
26
+ simdWasmUrl?: string;
27
+ }
28
+ /** What the processor needs from the browser; stood in for by tests. */
29
+ export interface NoiseSuppressorDeps {
30
+ createContext(): AudioContext;
31
+ loadModel(urls: {
32
+ url: string;
33
+ simdUrl: string;
34
+ }): Promise<ArrayBuffer>;
35
+ createNode(context: AudioContext, wasmBinary: ArrayBuffer): Promise<DenoiseNode> | DenoiseNode;
36
+ createStream(tracks: MediaStreamTrack[]): MediaStream;
37
+ }
38
+ type DenoiseNode = AudioNode & {
39
+ destroy?(): void;
40
+ };
41
+ /** An `AudioTrackProcessor` for `client.setAudioProcessor()` that removes background noise with RNNoise. */
42
+ export declare function createNoiseSuppressor(options?: NoiseSuppressorOptions, deps?: NoiseSuppressorDeps): AudioTrackProcessor;
43
+ export {};
44
+ //# sourceMappingURL=noise-suppression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noise-suppression.d.ts","sourceRoot":"","sources":["../../src/noise-suppression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAGhD,MAAM,WAAW,sBAAsB;IACrC,gFAAgF;IAChF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6GAA6G;IAC7G,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wEAAwE;AACxE,MAAM,WAAW,mBAAmB;IAClC,aAAa,IAAI,YAAY,CAAC;IAC9B,SAAS,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxE,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;IAC/F,YAAY,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,WAAW,CAAC;CACvD;AAED,KAAK,WAAW,GAAG,SAAS,GAAG;IAAE,OAAO,CAAC,IAAI,IAAI,CAAA;CAAE,CAAC;AAsBpD,4GAA4G;AAC5G,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,EAAE,IAAI,GAAE,mBAAiC,GAAG,mBAAmB,CAwExI"}
@@ -0,0 +1,99 @@
1
+ /** The package version the default URLs point at; equal to this SDK's pinned dependency (a test checks it). */
2
+ export const NOISE_SUPPRESSOR_VERSION = '0.4.1';
3
+ const CDN = `https://cdn.jsdelivr.net/npm/@sapphi-red/web-noise-suppressor@${NOISE_SUPPRESSOR_VERSION}/dist`;
4
+ let library = null;
5
+ /**
6
+ * The library is loaded on first use, not with this module: it extends `AudioWorkletNode` as it loads, which exists
7
+ * only in browsers, so a static import would break a server render (Next.js) or Node.
8
+ */
9
+ const load = () => (library ??= import('@sapphi-red/web-noise-suppressor').catch((err) => {
10
+ library = null;
11
+ throw err;
12
+ }));
13
+ const browserDeps = {
14
+ // RNNoise works on 48 kHz audio.
15
+ createContext: () => new AudioContext({ sampleRate: 48000 }),
16
+ loadModel: async (urls) => (await load()).loadRnnoise(urls),
17
+ createNode: async (context, wasmBinary) => new (await load()).RnnoiseWorkletNode(context, { wasmBinary, maxChannels: 1 }),
18
+ createStream: (tracks) => new MediaStream(tracks),
19
+ };
20
+ /** An `AudioTrackProcessor` for `client.setAudioProcessor()` that removes background noise with RNNoise. */
21
+ export function createNoiseSuppressor(options = {}, deps = browserDeps) {
22
+ let context = null;
23
+ let ready = null;
24
+ let graph = null;
25
+ let resumeOnGesture = null;
26
+ const release = () => {
27
+ if (!graph)
28
+ return;
29
+ try {
30
+ graph.source.disconnect();
31
+ graph.node.disconnect();
32
+ graph.node.destroy?.();
33
+ }
34
+ catch {
35
+ // Already gone.
36
+ }
37
+ graph.output.stop();
38
+ graph = null;
39
+ };
40
+ /** A context made without a tap starts suspended: no sound would go out until the page is touched. */
41
+ const keepRunning = (ctx) => {
42
+ void ctx.resume?.().catch(() => undefined);
43
+ if (ctx.state === 'running' || typeof document === 'undefined' || resumeOnGesture)
44
+ return;
45
+ resumeOnGesture = () => {
46
+ void ctx.resume().catch(() => undefined);
47
+ if (ctx.state === 'running' && resumeOnGesture) {
48
+ for (const type of ['pointerdown', 'keydown'])
49
+ document.removeEventListener(type, resumeOnGesture, { capture: true });
50
+ resumeOnGesture = null;
51
+ }
52
+ };
53
+ for (const type of ['pointerdown', 'keydown'])
54
+ document.addEventListener(type, resumeOnGesture, { capture: true });
55
+ };
56
+ return {
57
+ name: 'noise-suppression',
58
+ async process(track) {
59
+ const ctx = (context ??= deps.createContext());
60
+ ready ??= Promise.all([
61
+ deps.loadModel({ url: options.wasmUrl ?? `${CDN}/rnnoise.wasm`, simdUrl: options.simdWasmUrl ?? `${CDN}/rnnoise_simd.wasm` }),
62
+ ctx.audioWorklet.addModule(options.workletUrl ?? `${CDN}/rnnoise/workletProcessor.js`),
63
+ ]).then(([model]) => model);
64
+ let model;
65
+ try {
66
+ model = await ready;
67
+ }
68
+ catch (err) {
69
+ ready = null; // try again next time (a network blip)
70
+ throw err;
71
+ }
72
+ const node = await deps.createNode(ctx, model);
73
+ release();
74
+ const source = ctx.createMediaStreamSource(deps.createStream([track]));
75
+ const destination = ctx.createMediaStreamDestination();
76
+ source.connect(node);
77
+ node.connect(destination);
78
+ const output = destination.stream.getAudioTracks()[0];
79
+ if (!output)
80
+ throw new Error('the audio graph gave no track');
81
+ graph = { source, node, output };
82
+ keepRunning(ctx);
83
+ return output;
84
+ },
85
+ async destroy() {
86
+ release();
87
+ if (resumeOnGesture && typeof document !== 'undefined') {
88
+ for (const type of ['pointerdown', 'keydown'])
89
+ document.removeEventListener(type, resumeOnGesture, { capture: true });
90
+ }
91
+ resumeOnGesture = null;
92
+ const ctx = context;
93
+ context = null;
94
+ ready = null;
95
+ await ctx?.close().catch(() => undefined);
96
+ },
97
+ };
98
+ }
99
+ //# sourceMappingURL=noise-suppression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noise-suppression.js","sourceRoot":"","sources":["../../src/noise-suppression.ts"],"names":[],"mappings":"AAkBA,+GAA+G;AAC/G,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAChD,MAAM,GAAG,GAAG,iEAAiE,wBAAwB,OAAO,CAAC;AAqB7G,IAAI,OAAO,GAA4B,IAAI,CAAC;AAE5C;;;GAGG;AACH,MAAM,IAAI,GAAG,GAAqB,EAAE,CAClC,CAAC,OAAO,KAAK,MAAM,CAAC,kCAAkC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;IAC7E,OAAO,GAAG,IAAI,CAAC;IACf,MAAM,GAAG,CAAC;AACZ,CAAC,CAAC,CAAC,CAAC;AAEN,MAAM,WAAW,GAAwB;IACvC,iCAAiC;IACjC,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC5D,SAAS,EAAE,KAAK,EAAE,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AC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Track processors (docs/implementation-progress/RTC_PERF_PROGRESS.md P3-4, P3-5): the published microphone or
3
+ * camera sent through something that changes it first -- noise suppression, a blurred or replaced background, beauty.
4
+ * LiveKit (`setProcessor`: Krisp, background blur), Agora and TRTC (extensions and plugins) do it the same way: the
5
+ * device's track goes in, a processed track goes out and is published in its place; the device's own track stays the
6
+ * one watched for unplugging, given new constraints and released at the end.
7
+ */
8
+ /** Something the microphone passes through before it is sent. */
9
+ export interface AudioTrackProcessor {
10
+ /** A short name, for diagnostics. */
11
+ readonly name: string;
12
+ /**
13
+ * Process `track` and return the track to send. Called again whenever the microphone's track changes (another
14
+ * device, a reconnect): the processor then lets go of what it made for the previous one.
15
+ */
16
+ process(track: MediaStreamTrack): Promise<MediaStreamTrack>;
17
+ /** Let go of everything (the processor was removed, or the session ended). */
18
+ destroy(): Promise<void> | void;
19
+ }
20
+ /** Something the camera passes through before it is sent (and shown in `client.local`). */
21
+ export interface VideoTrackProcessor {
22
+ /** A short name, for diagnostics. */
23
+ readonly name: string;
24
+ /**
25
+ * Process `track` and return the track to send, at the same size and frame rate. Called again when the camera's
26
+ * track changes (another camera, `replaceVideoTrack`): the processor then lets go of what it made for the previous
27
+ * one. A picture the SDK no longer sends is stopped by the SDK; stop drawing it once its `readyState` is 'ended',
28
+ * and skip the work while it is switched off (`enabled` false: the camera is paused).
29
+ */
30
+ process(track: MediaStreamTrack): Promise<MediaStreamTrack>;
31
+ /** Let go of everything (the processor was removed, or the session ended). */
32
+ destroy(): Promise<void> | void;
33
+ }
34
+ //# sourceMappingURL=processors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processors.d.ts","sourceRoot":"","sources":["../../src/processors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AACjE,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,8EAA8E;IAC9E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACjC;AAED,2FAA2F;AAC3F,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,8EAA8E;IAC9E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACjC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Track processors (docs/implementation-progress/RTC_PERF_PROGRESS.md P3-4, P3-5): the published microphone or
3
+ * camera sent through something that changes it first -- noise suppression, a blurred or replaced background, beauty.
4
+ * LiveKit (`setProcessor`: Krisp, background blur), Agora and TRTC (extensions and plugins) do it the same way: the
5
+ * device's track goes in, a processed track goes out and is published in its place; the device's own track stays the
6
+ * one watched for unplugging, given new constraints and released at the end.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=processors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processors.js","sourceRoot":"","sources":["../../src/processors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Virtual background and beauty for the camera (docs/implementation-progress/RTC_PERF_PROGRESS.md P3-5): a blurred or
3
+ * replaced background and skin smoothing, as LiveKit's track processors, Agora's and ZEGOCLOUD's virtual background and
4
+ * beauty extensions, and Tencent TRTC's video effect plugin do -- in the browser, on the GPU.
5
+ *
6
+ * Imported on its own (`@voltkit-rtc/client/video-effects`), so an app that does not use it never ships it:
7
+ *
8
+ * import { createVideoEffects } from '@voltkit-rtc/client/video-effects';
9
+ * const effects = createVideoEffects({ background: 'blur', beauty: true });
10
+ * await client.setVideoProcessor(effects);
11
+ * await effects.update({ background: { image: '/office.jpg' } }); // live, no pause for viewers
12
+ *
13
+ * Finding the person takes Google's MediaPipe selfie segmenter: install `@mediapipe/tasks-vision@0.10.35` next to the
14
+ * SDK (an optional peer dependency, 0.10.35 exactly -- later versions report usage to Google). Its wasm (3 MB
15
+ * compressed) and the model (250 kB) load the first time a background effect is used: the wasm from jsDelivr at that
16
+ * version and the model from Google, unless you serve them yourself (`wasmPath`, `modelUrl`). Beauty alone needs none
17
+ * of it.
18
+ *
19
+ * Chrome and Edge process each camera frame as it arrives (insertable streams: smooth, and it keeps going in a
20
+ * background tab). Firefox and Safari draw from a hidden video on a worker's timer into a captured canvas -- what
21
+ * LiveKit, Twilio and Amazon Chime fall back to -- which a background tab can slow down.
22
+ */
23
+ import { type BackgroundSetting, type BeautyOptions, type BeautySettings } from './effects-core.js';
24
+ import type { VideoTrackProcessor } from './processors.js';
25
+ export type { BackgroundImageSource, BackgroundSetting, BeautyOptions, BeautySettings } from './effects-core.js';
26
+ /** The `@mediapipe/tasks-vision` version this SDK was tested with; the default wasm URL points at it. */
27
+ export declare const MEDIAPIPE_VERSION = "0.10.35";
28
+ /** Google's selfie segmenter for portrait and square pictures (phones), at a fixed version. */
29
+ export declare const DEFAULT_SEGMENTER_MODEL = "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/1/selfie_segmenter.tflite";
30
+ /**
31
+ * Its landscape version, for wide pictures (webcams): fed a 16:9 frame, the square model leaves patches of the room
32
+ * beside the head, the landscape one traces it cleanly (as LiveKit, Twilio, Chime and TRTC use for webcams).
33
+ */
34
+ export declare const DEFAULT_LANDSCAPE_MODEL = "https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter_landscape/float16/1/selfie_segmenter_landscape.tflite";
35
+ export interface VideoEffectsOptions {
36
+ /** `'none'` (default), `'blur'`, or `{ image }`: a URL, Blob, image, canvas or ImageBitmap, fitted to cover. */
37
+ background?: BackgroundSetting;
38
+ /** Blur strength, 1 (light) to 10 (strong). Default 5. */
39
+ blur?: number;
40
+ /** Beauty: `true` for the defaults, or each of `smooth`, `brighten`, `redness`, `sharpen` (0-1). Off by default. */
41
+ beauty?: BeautyOptions | boolean | null;
42
+ /** A folder serving `vision_wasm_internal.{js,wasm}` and `vision_wasm_nosimd_internal.{js,wasm}` (from
43
+ * `node_modules/@mediapipe/tasks-vision/wasm`). Default: jsDelivr at MEDIAPIPE_VERSION. */
44
+ wasmPath?: string;
45
+ /** Where the segmentation model is served, for every picture. Default: DEFAULT_LANDSCAPE_MODEL for wide pictures,
46
+ * DEFAULT_SEGMENTER_MODEL for portrait and square ones. */
47
+ modelUrl?: string;
48
+ /** The most frames a second to process; the camera's rate by default. */
49
+ maxFrameRate?: number;
50
+ /**
51
+ * Told when this device cannot keep up even finding the person only every few frames (Agora's `onoverload`): turn
52
+ * the background off, or lower the camera's frame rate or size. Told again with `false` when it can.
53
+ */
54
+ onOverload?: (overloaded: boolean) => void;
55
+ }
56
+ /** What `update` can change while the effects run. */
57
+ export type VideoEffectsUpdate = Pick<VideoEffectsOptions, 'background' | 'blur' | 'beauty'>;
58
+ export interface VideoEffects extends VideoTrackProcessor {
59
+ /**
60
+ * Change the effects while they run: no new camera, no pause for viewers. Resolves once the change shows; a picture
61
+ * that cannot be loaded, or a segmenter that cannot start, rejects and leaves the effects as they were.
62
+ */
63
+ update(changes: VideoEffectsUpdate): Promise<void>;
64
+ /** The effects in force now. */
65
+ readonly settings: {
66
+ background: 'none' | 'blur' | 'image';
67
+ blur: number;
68
+ beauty: BeautySettings | null;
69
+ };
70
+ /** How hard the device works: the person is found every `segmentEvery` frames, in `segmentMs` on average. */
71
+ readonly stats: {
72
+ segmentEvery: number;
73
+ segmentMs: number;
74
+ overloaded: boolean;
75
+ };
76
+ }
77
+ /** What finds the person: MediaPipe's ImageSegmenter, or a stand-in in tests. */
78
+ export interface PersonSegmenter {
79
+ /** Find the person in `input`; `use` gets the confidence (0-1) of each pixel being the person, at `input`'s size. */
80
+ segment(input: TexImageSource, timestampMs: number, use: (confidence: Float32Array) => void): void;
81
+ close(): void;
82
+ }
83
+ /** Stood in for by tests. */
84
+ export interface VideoEffectsDeps {
85
+ loadSegmenter(wasmPath: string, modelUrl: string): Promise<PersonSegmenter>;
86
+ /** How frames are taken and given back; chosen from the browser's features when absent. */
87
+ pump?: 'insertable' | 'canvas';
88
+ }
89
+ /** Whether this browser can run the effects (WebGL2, and a way to take and give back frames). */
90
+ export declare function isVideoEffectsSupported(): boolean;
91
+ /** Virtual background and beauty, for `client.setVideoProcessor()`. */
92
+ export declare function createVideoEffects(options?: VideoEffectsOptions, stand?: Partial<VideoEffectsDeps>): VideoEffects;
93
+ //# sourceMappingURL=video-effects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-effects.d.ts","sourceRoot":"","sources":["../../src/video-effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAWL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,YAAY,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEjH,yGAAyG;AACzG,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,+FAA+F;AAC/F,eAAO,MAAM,uBAAuB,uHAAuH,CAAC;AAC5J;;;GAGG;AACH,eAAO,MAAM,uBAAuB,2IAA2I,CAAC;AAEhL,MAAM,WAAW,mBAAmB;IAClC,gHAAgH;IAChH,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oHAAoH;IACpH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