Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat call noise filtering (#2463)

Will Hutchinsonf218c20040ca
diff --git a/js/app/bun.lock b/js/app/bun.lock
index 6c2ae77439..070b41f521 100644
--- a/js/app/bun.lock
+++ b/js/app/bun.lock
@@ -36,6 +36,7 @@
"@lexical/selection": "^0.32.1",
"@lexical/table": "^0.32.1",
"@lexical/utils": "^0.32.1",
+ "@livekit/krisp-noise-filter": "^0.4.1",
"@lukemorales/query-key-factory": "^1.3.4",
"@normy/query-core": "^0.21.0",
"@phosphor-icons/core": "^2.1.1",
@@ -744,6 +745,8 @@
"@lezer/rust": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0" } }, "sha512-Lz5sIPBdF2FUXcWeCu1//ojFAZqzTQNRga0aYv6dYXqJqPfMdCAI0NzajWUd4Xijj1IKJLtjoXRPMvTKWBcqKg=="],
+ "@livekit/krisp-noise-filter": ["@livekit/[email protected]", "", { "dependencies": { "@livekit/mutex": "^1.1.1" }, "peerDependencies": { "livekit-client": "^2.0.8" } }, "sha512-r27IbCCLqR3qaK5a1fiMQEmV551EubwdZDtge/Fp7T/MoQspQQMA229H8No3KK67j6KLQ5wRhOd0swl0uvyaCw=="],
+
"@livekit/mutex": ["@livekit/[email protected]", "", {}, "sha512-EsshAucklmpuUAfkABPxJNhzj9v2sG7JuzFDL4ML1oJQSV14sqrpTYnsaOudMAw9yOaW53NU3QQTlUQoRs4czw=="],
"@livekit/protocol": ["@livekit/[email protected]", "", { "dependencies": { "@bufbuild/protobuf": "^1.10.0" } }, "sha512-/vfhDUGcUKO8Q43r6i+5FrDhl5oZjm/X3U4x2Iciqvgn5C8qbj+57YPcWSJ1kyIZm5Cm6AV2nAPjMm3ETD/iyg=="],
diff --git a/js/app/package.json b/js/app/package.json
index 308bcc42ec..dab5ee880d 100644
--- a/js/app/package.json
+++ b/js/app/package.json
@@ -53,6 +53,7 @@
"@lexical/selection": "^0.32.1",
"@lexical/table": "^0.32.1",
"@lexical/utils": "^0.32.1",
+ "@livekit/krisp-noise-filter": "^0.4.1",
"@lukemorales/query-key-factory": "^1.3.4",
"@normy/query-core": "^0.21.0",
"@phosphor-icons/core": "^2.1.1",
diff --git a/js/app/packages/channel/Call/CallContext.tsx b/js/app/packages/channel/Call/CallContext.tsx
index 61bd5073ec..e053ca5dc4 100644
--- a/js/app/packages/channel/Call/CallContext.tsx
+++ b/js/app/packages/channel/Call/CallContext.tsx
@@ -7,6 +7,10 @@ import {
type LocalTrackPublication,
type LocalTrack,
} from 'livekit-client';
+import {
+ KrispNoiseFilter,
+ isKrispNoiseFilterSupported,
+} from '@livekit/krisp-noise-filter';
import {
createContext,
createSignal,
@@ -45,6 +49,7 @@ type CallStoreState = {
activeAudioInputDeviceId: string | null;
activeAudioOutputDeviceId: string | null;
activeVideoInputDeviceId: string | null;
+ isNoiseSuppressed: boolean;
};
const initialState: CallStoreState = {
@@ -62,6 +67,7 @@ const initialState: CallStoreState = {
activeAudioInputDeviceId: null,
activeAudioOutputDeviceId: null,
activeVideoInputDeviceId: null,
+ isNoiseSuppressed: false,
};
export type CallState = {
@@ -115,6 +121,10 @@ export type CallState = {
switchAudioOutput: (deviceId: string) => Promise<void>;
/** Switch active video input device */
switchVideoInput: (deviceId: string) => Promise<void>;
+ /** Whether Krisp noise suppression is active */
+ isNoiseSuppressed: () => boolean;
+ /** Toggle Krisp noise suppression on/off */
+ toggleNoiseSuppression: () => Promise<void>;
};
const CallContext = createContext<CallState>();
@@ -138,6 +148,9 @@ export function useCallContextOptional(): CallState | undefined {
function createCallState() {
const [room, setRoom] = createSignal<Room | null>(null);
const [store, setStore] = createStore<CallStoreState>({ ...initialState });
+ const [krispFilter, setKrispFilter] = createSignal<ReturnType<
+ typeof KrispNoiseFilter
+ > | null>(null);
// --- internal helpers ---
@@ -181,6 +194,11 @@ function createCallState() {
}
function destroyRoom() {
+ const krisp = krispFilter();
+ if (krisp) {
+ krisp.destroy();
+ setKrispFilter(null);
+ }
const r = room();
if (r) {
r.removeAllListeners();
@@ -347,7 +365,13 @@ function createCallState() {
// Reuse existing room instance (same channel, e.g. leave then rejoin)
targetRoom = room()!;
} else {
- targetRoom = new Room();
+ targetRoom = new Room({
+ audioCaptureDefaults: {
+ noiseSuppression: true,
+ echoCancellation: true,
+ autoGainControl: true,
+ },
+ });
attachRoomListeners(targetRoom);
setRoom(targetRoom);
}
@@ -375,6 +399,23 @@ function createCallState() {
setStore('isAudioMuted', false);
setStore('isVideoMuted', true);
+ // Register Krisp noise filter on the mic track
+ if (isKrispNoiseFilterSupported()) {
+ try {
+ const micPub = targetRoom.localParticipant.getTrackPublication(
+ Track.Source.Microphone
+ );
+ if (micPub?.track) {
+ const krisp = KrispNoiseFilter();
+ await (micPub.track as LocalTrack).setProcessor(krisp);
+ setKrispFilter(krisp);
+ setStore('isNoiseSuppressed', true);
+ }
+ } catch (e) {
+ console.error('failed to enable Krisp noise filter', e);
+ }
+ }
+
// Enumerate available devices and track active ones
await enumerateDevices();
trackActiveDevices(targetRoom);
@@ -456,6 +497,18 @@ function createCallState() {
}
}
+ async function toggleNoiseSuppression() {
+ const krisp = krispFilter();
+ if (!krisp) return;
+ try {
+ const newEnabled = !store.isNoiseSuppressed;
+ await krisp.setEnabled(newEnabled);
+ setStore('isNoiseSuppressed', newEnabled);
+ } catch (e) {
+ console.error('failed to toggle noise suppression', e);
+ }
+ }
+
// --- cleanup ---
const handleBeforeUnload = () => {
@@ -518,6 +571,8 @@ function createCallState() {
switchAudioInput,
switchAudioOutput,
switchVideoInput,
+ isNoiseSuppressed: () => store.isNoiseSuppressed,
+ toggleNoiseSuppression,
};
return state;