Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Krisp example #47

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "33f65a3cbc52f8c19295723af9cbecc2195484e1",
"version" : "3.5.0"
"revision" : "46072478ca365fe48370993833cb22de9b41567f",
"version" : "3.5.2"
}
},
{
Expand All @@ -54,6 +54,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-krisp-noise-filter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/livekit/swift-krisp-noise-filter",
"state" : {
"revision" : "5c4608111033f1ac13edf64a335a1b9902c5496e",
"version" : "0.0.3"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
Expand All @@ -68,17 +77,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "9f0c76544701845ad98716f3f6a774a892152bcb",
"version" : "1.26.0"
"revision" : "e17d61f26df0f0e06f58f6977ba05a097a720106",
"version" : "1.27.1"
}
},
{
"identity" : "webrtc-xcframework",
"kind" : "remoteSourceControl",
"location" : "https://github.com/livekit/webrtc-xcframework.git",
"state" : {
"revision" : "5640582dbac33b193608574d4aa2a8d5d825db74",
"version" : "125.6422.2"
"revision" : "c0395fecffce2bc694835501aec11b17d793afaf",
"version" : "125.6422.4"
}
}
],
Expand Down
27 changes: 27 additions & 0 deletions LiveKitExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
6867533C27A65652003707B9 /* AppContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6867533A27A65652003707B9 /* AppContext.swift */; };
687230F82B14AE0A0098CCE6 /* PublishOptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 687230F72B14AE0A0098CCE6 /* PublishOptionsView.swift */; };
687230F92B14AE0A0098CCE6 /* PublishOptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 687230F72B14AE0A0098CCE6 /* PublishOptionsView.swift */; };
687B93942BA7307D00FDD013 /* LiveKitKrispNoiseFilter in Frameworks */ = {isa = PBXBuildFile; productRef = 687B93932BA7307D00FDD013 /* LiveKitKrispNoiseFilter */; };
68816CC127B4D6BC00E24622 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 68816CC027B4D6BC00E24622 /* KeychainAccess */; };
68816CC327B4D94200E24622 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 68816CC227B4D94200E24622 /* KeychainAccess */; };
68816CC527B4DCD500E24622 /* SecureStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68816CC427B4DCD500E24622 /* SecureStore.swift */; };
Expand Down Expand Up @@ -64,6 +65,16 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
683522152BA705A100FD50A9 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
68EA18EB27F2E91100F9AE48 /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -124,6 +135,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
687B93942BA7307D00FDD013 /* LiveKitKrispNoiseFilter in Frameworks */,
68FBA43F2A38B49C0015853E /* LiveKit in Frameworks */,
680FE2F227A8EF7700B6F6DB /* SFSafeSymbols in Frameworks */,
68816CC127B4D6BC00E24622 /* KeychainAccess in Frameworks */,
Expand Down Expand Up @@ -283,6 +295,7 @@
68B38540271E780700711D5F /* Frameworks */,
68B38541271E780700711D5F /* Resources */,
68EA18EB27F2E91100F9AE48 /* Embed Foundation Extensions */,
683522152BA705A100FD50A9 /* Embed Frameworks */,
);
buildRules = (
);
Expand All @@ -294,6 +307,7 @@
680FE2F127A8EF7700B6F6DB /* SFSafeSymbols */,
68816CC027B4D6BC00E24622 /* KeychainAccess */,
68FBA43E2A38B49C0015853E /* LiveKit */,
687B93932BA7307D00FDD013 /* LiveKitKrispNoiseFilter */,
);
productName = "Multiplatform-SwiftUI (iOS)";
productReference = 68B38543271E780700711D5F /* LiveKitExample.app */;
Expand Down Expand Up @@ -356,6 +370,7 @@
680FE2F027A8EF7700B6F6DB /* XCRemoteSwiftPackageReference "SFSafeSymbols" */,
68816CBF27B4D6BC00E24622 /* XCRemoteSwiftPackageReference "KeychainAccess" */,
68FBA43D2A38B49C0015853E /* XCRemoteSwiftPackageReference "client-sdk-swift" */,
68A4AEFC2C51E6A3001F3DA9 /* XCRemoteSwiftPackageReference "swift-krisp-noise-filter" */,
);
productRefGroup = 68B38544271E780700711D5F /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -839,6 +854,14 @@
minimumVersion = 4.2.2;
};
};
68A4AEFC2C51E6A3001F3DA9 /* XCRemoteSwiftPackageReference "swift-krisp-noise-filter" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/livekit/swift-krisp-noise-filter";
requirement = {
kind = exactVersion;
version = 0.0.3;
};
};
68FBA43D2A38B49C0015853E /* XCRemoteSwiftPackageReference "client-sdk-swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/livekit/client-sdk-swift";
Expand Down Expand Up @@ -868,6 +891,10 @@
isa = XCSwiftPackageProductDependency;
productName = LiveKit;
};
687B93932BA7307D00FDD013 /* LiveKitKrispNoiseFilter */ = {
isa = XCSwiftPackageProductDependency;
productName = LiveKitKrispNoiseFilter;
};
68816CC027B4D6BC00E24622 /* KeychainAccess */ = {
isa = XCSwiftPackageProductDependency;
package = 68816CBF27B4D6BC00E24622 /* XCRemoteSwiftPackageReference "KeychainAccess" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "bf59b79f5d4ea0a54ef7e929b035c5821f5094ee990a7a369ad0cb3713f6c62d",
"originHash" : "d4d1ddd5dbcd10b536e607b5cee6e6e561f9e6b49a06ae90e7bc0ed8971f7540",
"pins" : [
{
"identity" : "client-sdk-swift",
Expand Down Expand Up @@ -28,6 +28,15 @@
"version" : "5.3.0"
}
},
{
"identity" : "swift-krisp-noise-filter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/livekit/swift-krisp-noise-filter",
"state" : {
"revision" : "5c4608111033f1ac13edf64a335a1b9902c5496e",
"version" : "0.0.3"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
Expand All @@ -42,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "9f0c76544701845ad98716f3f6a774a892152bcb",
"version" : "1.26.0"
"revision" : "e17d61f26df0f0e06f58f6977ba05a097a720106",
"version" : "1.27.1"
}
},
{
Expand Down
20 changes: 20 additions & 0 deletions Shared/Controllers/AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import Combine
import LiveKit
import SwiftUI

#if os(iOS)
import LiveKitKrispNoiseFilter
#endif

// This class contains the logic to control behavior of the whole app.
final class AppContext: ObservableObject {
private let store: ValueStore<Preferences>
Expand Down Expand Up @@ -66,6 +70,18 @@ final class AppContext: ObservableObject {
didSet { AudioManager.shared.isSpeakerOutputPreferred = preferSpeakerOutput }
}

#if os(iOS)
// Krisp noise filter example
lazy var krispProcessor = LiveKitKrispNoiseFilter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiroshihorie can we add ObservableObject to LiveKitKrispNoiseFilter so it can be passed in @EnvironmentObject? That would be a more intuitive way to integrate into SwiftUI


@Published var isKrispEnabled: Bool = false {
didSet {
// Runtime toggling of audio processor
krispProcessor.isEnabled = isKrispEnabled
}
}
#endif

public init(store: ValueStore<Preferences>) {
self.store = store

Expand All @@ -86,5 +102,9 @@ final class AppContext: ObservableObject {
self.inputDevice = audioManager.inputDevice
}
}

#if os(iOS)
AudioManager.shared.capturePostProcessingDelegate = krispProcessor
#endif
}
}
6 changes: 6 additions & 0 deletions Shared/LiveKitExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ struct RoomContextView: View {
.environmentObject(roomCtx.room)
.environment(\.colorScheme, .dark)
.foregroundColor(Color.white)
.onAppear {
#if os(iOS)
// Attach RoomDelegate to KrispProcessor
roomCtx.room.add(delegate: appCtx.krispProcessor)
#endif
}
.onDisappear {
print("\(String(describing: type(of: self))) onDisappear")
Task {
Expand Down
3 changes: 3 additions & 0 deletions Shared/RoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ struct RoomView: View {
Toggle("Prefer speaker output", isOn: $appCtx.preferSpeakerOutput)

Toggle("E2EE enabled", isOn: $roomCtx.isE2eeEnabled)
#if os(iOS)
Toggle("Krisp Audio Filter Enabled", isOn: $appCtx.isKrispEnabled)
#endif
}

} label: {
Expand Down