Skip to content

Commit

Permalink
Checkpoint of new listener from Atila.
Browse files Browse the repository at this point in the history
Screwed up and used watch app reference. Working but moving to iOS
  • Loading branch information
scosman committed Apr 3, 2024
1 parent a647f09 commit a0e8ca8
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 9 deletions.
41 changes: 41 additions & 0 deletions ios/voicebox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
E029C3442B2CA77F00E2687A /* ggml-alloc.c in Sources */ = {isa = PBXBuildFile; fileRef = E029C3382B2CA6D200E2687A /* ggml-alloc.c */; };
E029C3452B2CA77F00E2687A /* ggml-backend.c in Sources */ = {isa = PBXBuildFile; fileRef = E029C33A2B2CA6D200E2687A /* ggml-backend.c */; };
E029C3462B2CA77F00E2687A /* ggml-metal.m in Sources */ = {isa = PBXBuildFile; fileRef = E029C33B2B2CA6D200E2687A /* ggml-metal.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E0487CC92BBD93A100568D2A /* WhisperKit in Frameworks */ = {isa = PBXBuildFile; productRef = E0487CC82BBD93A100568D2A /* WhisperKit */; };
E0487CCC2BBDB62900568D2A /* VBListener.m in Sources */ = {isa = PBXBuildFile; fileRef = E0487CCB2BBDB62900568D2A /* VBListener.m */; };
E0487CCF2BBDBEDF00568D2A /* VBSwiftListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0487CCE2BBDBEDF00568D2A /* VBSwiftListener.swift */; };
E049ED3D293FCC38002080BD /* VBButton.m in Sources */ = {isa = PBXBuildFile; fileRef = E049ED3C293FCC38002080BD /* VBButton.m */; };
E049ED41293FCC5D002080BD /* VBMagicEnhancer.m in Sources */ = {isa = PBXBuildFile; fileRef = E049ED40293FCC5D002080BD /* VBMagicEnhancer.m */; };
E049ED45293FFB93002080BD /* VBEnhanceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E049ED44293FFB93002080BD /* VBEnhanceViewController.m */; };
Expand Down Expand Up @@ -95,6 +98,10 @@
E029C3392B2CA6D200E2687A /* ggml-backend-impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ggml-backend-impl.h"; sourceTree = "<group>"; };
E029C33A2B2CA6D200E2687A /* ggml-backend.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "ggml-backend.c"; sourceTree = "<group>"; };
E029C33B2B2CA6D200E2687A /* ggml-metal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ggml-metal.m"; sourceTree = "<group>"; };
E0487CCA2BBDB62900568D2A /* VBListener.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VBListener.h; sourceTree = "<group>"; };
E0487CCB2BBDB62900568D2A /* VBListener.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VBListener.m; sourceTree = "<group>"; };
E0487CCD2BBDBEDE00568D2A /* voicebox-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "voicebox-Bridging-Header.h"; sourceTree = "<group>"; };
E0487CCE2BBDBEDF00568D2A /* VBSwiftListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VBSwiftListener.swift; sourceTree = "<group>"; };
E049ED3B293FCC38002080BD /* VBButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VBButton.h; sourceTree = "<group>"; };
E049ED3C293FCC38002080BD /* VBButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VBButton.m; sourceTree = "<group>"; };
E049ED3F293FCC5D002080BD /* VBMagicEnhancer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VBMagicEnhancer.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,6 +161,7 @@
files = (
E0A442652BAA01AC006C27CB /* CriticalMoments in Frameworks */,
E02611112BAF450B00DE2A0E /* CriticalMoments in Frameworks */,
E0487CC92BBD93A100568D2A /* WhisperKit in Frameworks */,
E052B08D2BAF331E00E9415B /* CriticalMoments in Frameworks */,
E057C5572BAB38B3003158E4 /* CriticalMoments in Frameworks */,
);
Expand Down Expand Up @@ -214,6 +222,10 @@
E04A331F294A347300EF6628 /* OpenAiApiRequest.h */,
E04A3320294A347300EF6628 /* OpenAiApiRequest.m */,
E0D56EE32B9CECA100F24F6E /* VBResponseOption.h */,
E0487CCA2BBDB62900568D2A /* VBListener.h */,
E0487CCB2BBDB62900568D2A /* VBListener.m */,
E0487CCE2BBDBEDF00568D2A /* VBSwiftListener.swift */,
E0487CCD2BBDBEDE00568D2A /* voicebox-Bridging-Header.h */,
);
path = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -356,6 +368,7 @@
E057C5562BAB38B3003158E4 /* CriticalMoments */,
E052B08C2BAF331E00E9415B /* CriticalMoments */,
E02611102BAF450B00DE2A0E /* CriticalMoments */,
E0487CC82BBD93A100568D2A /* WhisperKit */,
);
productName = voicebox;
productReference = E0BBF1E9293EEE9000FB7FF9 /* voicebox.app */;
Expand Down Expand Up @@ -408,6 +421,7 @@
TargetAttributes = {
E0BBF1E8293EEE9000FB7FF9 = {
CreatedOnToolsVersion = 14.0.1;
LastSwiftMigration = 1530;
};
E0BBF203293EEE9100FB7FF9 = {
CreatedOnToolsVersion = 14.0.1;
Expand All @@ -430,6 +444,7 @@
mainGroup = E0BBF1E0293EEE9000FB7FF9;
packageReferences = (
E026110F2BAF450B00DE2A0E /* XCRemoteSwiftPackageReference "criticalmoments" */,
E0487CC72BBD93A100568D2A /* XCRemoteSwiftPackageReference "whisperkit" */,
);
productRefGroup = E0BBF1EA293EEE9000FB7FF9 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -488,6 +503,7 @@
E0A894DF29DB28790059AFEE /* whisper.h in Sources */,
E04A3321294A347300EF6628 /* OpenAiApiRequest.m in Sources */,
E0BBF1F4293EEE9000FB7FF9 /* MainViewController.m in Sources */,
E0487CCF2BBDBEDF00568D2A /* VBSwiftListener.swift in Sources */,
E0CE98B3295D393B00FF9CA5 /* whisper.cpp in Sources */,
E029C3402B2CA6D200E2687A /* ggml-alloc.c in Sources */,
E049ED41293FCC5D002080BD /* VBMagicEnhancer.m in Sources */,
Expand All @@ -506,6 +522,7 @@
E029C3422B2CA6D200E2687A /* ggml-metal.m in Sources */,
E0BBF1F1293EEE9000FB7FF9 /* SceneDelegate.m in Sources */,
E029C3412B2CA6D200E2687A /* ggml-backend.c in Sources */,
E0487CCC2BBDB62900568D2A /* VBListener.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -679,6 +696,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3555VWY9R9;
Expand All @@ -700,6 +718,9 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "voicebox/Util/voicebox-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -709,6 +730,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3555VWY9R9;
Expand All @@ -730,13 +752,16 @@
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "voicebox/Util/voicebox-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
E0BBF21C293EEE9100FB7FF9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -755,6 +780,7 @@
E0BBF21D293EEE9100FB7FF9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -773,6 +799,7 @@
E0BBF21F293EEE9100FB7FF9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
Expand All @@ -789,6 +816,7 @@
E0BBF220293EEE9100FB7FF9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
Expand Down Expand Up @@ -852,6 +880,14 @@
minimumVersion = 0.9.2;
};
};
E0487CC72BBD93A100568D2A /* XCRemoteSwiftPackageReference "whisperkit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/argmaxinc/whisperkit";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -860,6 +896,11 @@
package = E026110F2BAF450B00DE2A0E /* XCRemoteSwiftPackageReference "criticalmoments" */;
productName = CriticalMoments;
};
E0487CC82BBD93A100568D2A /* WhisperKit */ = {
isa = XCSwiftPackageProductDependency;
package = E0487CC72BBD93A100568D2A /* XCRemoteSwiftPackageReference "whisperkit" */;
productName = WhisperKit;
};
E052B08C2BAF331E00E9415B /* CriticalMoments */ = {
isa = XCSwiftPackageProductDependency;
productName = CriticalMoments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "b6d1eb20c2e42a5c64d10d3b5ef89157291eb4491dd1e210f3ceb88bd15580b1",
"originHash" : "831847cfee78fa24ed1c08f30a2695ecc6a378354dcbf2120f29fbb03cd127b1",
"pins" : [
{
"identity" : "criticalmoments",
Expand All @@ -9,7 +9,34 @@
"revision" : "2cef8c0b6208ef6fd7b97b6151bc3ffc8fff40c4",
"version" : "0.9.2"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
}
},
{
"identity" : "swift-transformers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/huggingface/swift-transformers.git",
"state" : {
"revision" : "74b94211bdc741694ed7e700a1104c72e5ba68fe",
"version" : "0.1.7"
}
},
{
"identity" : "whisperkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/argmaxinc/whisperkit",
"state" : {
"branch" : "main",
"revision" : "5572cd63c763c82c973077659c34a20e90d2afed"
}
}
],
"version" : 2
"version" : 3
}
2 changes: 1 addition & 1 deletion ios/voicebox/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef Constants_h
#define Constants_h

#define LISTEN_ENABLED false
#define LISTEN_ENABLED true

#define ACCESSIBLE_SYSTEM_SPACING_MULTIPLE 3.0

Expand Down
16 changes: 12 additions & 4 deletions ios/voicebox/UI/ListenViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "ListenViewController.h"

#import "../Util/VBListener.h"
#import "Constants.h"
#import "VBAudioListener.h"

Expand All @@ -21,6 +22,13 @@ @interface ListenViewController () <VBAudioListenerDelegate>

@implementation ListenViewController

- (id<VBListenerProto>)listener
{
// My implementation vs Atila's
return [VBListener sharedInstance];
// return [VBAudioListener sharedInstance];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down Expand Up @@ -89,21 +97,21 @@ - (void)viewDidLoad
[NSLayoutConstraint activateConstraints:constraints];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[VBAudioListener sharedInstance] registerDelegate:self];
[[VBAudioListener sharedInstance] startListening];
[[self listener] registerDelegate:self];
[[self listener] startListening];
});
}

- (void)dealloc
{
[[VBAudioListener sharedInstance] deregisterDelegate:self];
[[self listener] deregisterDelegate:self];
}

- (void)closeButtonAction:(UIButton*)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[VBAudioListener sharedInstance] stopCapturing];
[[self listener] stopCapturing];
});
}

Expand Down
17 changes: 17 additions & 0 deletions ios/voicebox/Util/VBListener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// VBListener.h
// voicebox
//
// Created by Steve Cosman on 2024-04-03.
//

#import "../Whisper/VBAudioListener.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface VBListener : NSObject <VBListenerProto>

@end

NS_ASSUME_NONNULL_END
76 changes: 76 additions & 0 deletions ios/voicebox/Util/VBListener.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// VBListener.m
// voicebox
//
// Created by Steve Cosman on 2024-04-03.
//

#import "VBListener.h"

#import "voicebox-Swift.h"

@interface VBListener ()

@property (nonatomic, strong) NSHashTable* delegates;
@property (nonatomic, strong) VBSwiftListener* wk;
@end

@implementation VBListener

- (instancetype)init
{
self = [super init];
if (self) {
self.wk = [[VBSwiftListener alloc] init];
}
return self;
}

static VBListener* sharedInstance = nil;

+ (VBListener*)sharedInstance
{
@synchronized(VBListener.class) {
if (!sharedInstance) {
sharedInstance = [[self alloc] init];
}

return sharedInstance;
}
}

+ (void)releaseSharedInstance
{
@synchronized(VBListener.class) {
sharedInstance = nil;
}
}

- (void)registerDelegate:(id<VBAudioListenerDelegate>)delegate
{
[_delegates addObject:delegate];
}

- (void)deregisterDelegate:(id<VBAudioListenerDelegate>)delegate
{
[_delegates removeObject:delegate];
}

- (void)startListening
{
[self.wk startWithCompletionHandler:^(NSError* _Nullable err) {
if (err) {
NSLog(@"Error %@", err);
}
}];
}

- (void)stateUpdate:(bool)running segments:(nullable NSArray<NSString*>*)segments
{
}

- (void)stopCapturing
{
}

@end
Loading

0 comments on commit a0e8ca8

Please sign in to comment.