Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if (WHISPER_COREML)
set(TARGET whisper.coreml)

add_library(${TARGET}
coreml/whisper-compat.m
coreml/whisper-encoder.h
coreml/whisper-encoder.mm
coreml/whisper-encoder-impl.h
Expand All @@ -76,6 +77,7 @@ if (WHISPER_COREML)
COMPILE_FLAGS "-fobjc-arc"
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
)

set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
endif()

Expand Down
10 changes: 10 additions & 0 deletions src/coreml/whisper-compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <CoreML/CoreML.h>

@interface MLModel (Compat)
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;

- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
options:(MLPredictionOptions *) options
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
@end
35 changes: 35 additions & 0 deletions src/coreml/whisper-compat.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#import "whisper-compat.h"
#import <Foundation/Foundation.h>

@implementation MLModel (Compat)

#if !defined(MAC_OS_X_VERSION_14_00) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_14_00

- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
[NSOperationQueue.new addOperationWithBlock:^{
NSError *error = nil;
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input error:&error];

[NSOperationQueue.mainQueue addOperationWithBlock:^{
completionHandler(prediction, error);
}];
}];
}

- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
options:(MLPredictionOptions *) options
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
[NSOperationQueue.new addOperationWithBlock:^{
NSError *error = nil;
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input options:options error:&error];

[NSOperationQueue.mainQueue addOperationWithBlock:^{
completionHandler(prediction, error);
}];
}];
}

#endif

@end
1 change: 1 addition & 0 deletions src/coreml/whisper-decoder-impl.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
#endif

#import "whisper-compat.h"
#import "whisper-decoder-impl.h"

@implementation whisper_decoder_implInput
Expand Down
1 change: 1 addition & 0 deletions src/coreml/whisper-encoder-impl.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
#endif

#import "whisper-compat.h"
#import "whisper-encoder-impl.h"

@implementation whisper_encoder_implInput
Expand Down
Loading