whispercpp 1.2.0.2 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +165 -434
  5. data/Rakefile +46 -86
  6. data/ext/.gitignore +13 -0
  7. data/ext/cpu.mk +9 -0
  8. data/ext/{dr_wav.h → examples/dr_wav.h} +3560 -1179
  9. data/ext/extconf.rb +185 -7
  10. data/ext/ggml/include/ggml-alloc.h +76 -0
  11. data/ext/ggml/include/ggml-backend.h +352 -0
  12. data/ext/ggml/include/ggml-blas.h +25 -0
  13. data/ext/ggml/include/ggml-cann.h +123 -0
  14. data/ext/ggml/include/ggml-cpp.h +38 -0
  15. data/ext/ggml/include/ggml-cpu.h +135 -0
  16. data/ext/ggml/include/ggml-cuda.h +47 -0
  17. data/ext/ggml/include/ggml-kompute.h +50 -0
  18. data/ext/ggml/include/ggml-metal.h +66 -0
  19. data/ext/ggml/include/ggml-opencl.h +26 -0
  20. data/ext/ggml/include/ggml-opt.h +216 -0
  21. data/ext/ggml/include/ggml-rpc.h +28 -0
  22. data/ext/ggml/include/ggml-sycl.h +49 -0
  23. data/ext/ggml/include/ggml-vulkan.h +31 -0
  24. data/ext/ggml/include/ggml.h +2285 -0
  25. data/ext/ggml/src/ggml-alloc.c +1037 -0
  26. data/ext/ggml/src/ggml-amx/common.h +94 -0
  27. data/ext/ggml/src/ggml-amx/ggml-amx.cpp +446 -0
  28. data/ext/ggml/src/ggml-amx/mmq.cpp +2510 -0
  29. data/ext/ggml/src/ggml-amx/mmq.h +17 -0
  30. data/ext/ggml/src/ggml-backend-impl.h +256 -0
  31. data/ext/ggml/src/ggml-backend-reg.cpp +552 -0
  32. data/ext/ggml/src/ggml-backend.cpp +1999 -0
  33. data/ext/ggml/src/ggml-blas/ggml-blas.cpp +517 -0
  34. data/ext/ggml/src/ggml-cann/acl_tensor.cpp +175 -0
  35. data/ext/ggml/src/ggml-cann/acl_tensor.h +258 -0
  36. data/ext/ggml/src/ggml-cann/aclnn_ops.cpp +3427 -0
  37. data/ext/ggml/src/ggml-cann/aclnn_ops.h +592 -0
  38. data/ext/ggml/src/ggml-cann/common.h +286 -0
  39. data/ext/ggml/src/ggml-cann/ggml-cann.cpp +2188 -0
  40. data/ext/ggml/src/ggml-cann/kernels/ascendc_kernels.h +19 -0
  41. data/ext/ggml/src/ggml-cann/kernels/dup.cpp +236 -0
  42. data/ext/ggml/src/ggml-cann/kernels/get_row_f16.cpp +197 -0
  43. data/ext/ggml/src/ggml-cann/kernels/get_row_f32.cpp +190 -0
  44. data/ext/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +204 -0
  45. data/ext/ggml/src/ggml-cann/kernels/get_row_q8_0.cpp +191 -0
  46. data/ext/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +218 -0
  47. data/ext/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +216 -0
  48. data/ext/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +295 -0
  49. data/ext/ggml/src/ggml-common.h +1853 -0
  50. data/ext/ggml/src/ggml-cpu/amx/amx.cpp +220 -0
  51. data/ext/ggml/src/ggml-cpu/amx/amx.h +8 -0
  52. data/ext/ggml/src/ggml-cpu/amx/common.h +91 -0
  53. data/ext/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
  54. data/ext/ggml/src/ggml-cpu/amx/mmq.h +10 -0
  55. data/ext/ggml/src/ggml-cpu/cpu-feats-x86.cpp +323 -0
  56. data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.cpp +4262 -0
  57. data/ext/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
  58. data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
  59. data/ext/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
  60. data/ext/ggml/src/ggml-cpu/ggml-cpu-impl.h +386 -0
  61. data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.c +10835 -0
  62. data/ext/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
  63. data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.cpp +36 -0
  64. data/ext/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
  65. data/ext/ggml/src/ggml-cpu/ggml-cpu.c +14123 -0
  66. data/ext/ggml/src/ggml-cpu/ggml-cpu.cpp +622 -0
  67. data/ext/ggml/src/ggml-cpu/llamafile/sgemm.cpp +1884 -0
  68. data/ext/ggml/src/ggml-cpu/llamafile/sgemm.h +14 -0
  69. data/ext/ggml/src/ggml-cuda/vendors/cuda.h +14 -0
  70. data/ext/ggml/src/ggml-cuda/vendors/hip.h +186 -0
  71. data/ext/ggml/src/ggml-cuda/vendors/musa.h +134 -0
  72. data/ext/ggml/src/ggml-impl.h +556 -0
  73. data/ext/ggml/src/ggml-kompute/ggml-kompute.cpp +2251 -0
  74. data/ext/ggml/src/ggml-metal/ggml-metal-impl.h +288 -0
  75. data/ext/ggml/src/ggml-metal/ggml-metal.m +4884 -0
  76. data/ext/ggml/src/ggml-metal/ggml-metal.metal +6732 -0
  77. data/ext/ggml/src/ggml-opt.cpp +854 -0
  78. data/ext/ggml/src/ggml-quants.c +5238 -0
  79. data/ext/ggml/src/ggml-quants.h +100 -0
  80. data/ext/ggml/src/ggml-rpc/ggml-rpc.cpp +1406 -0
  81. data/ext/ggml/src/ggml-sycl/common.cpp +95 -0
  82. data/ext/ggml/src/ggml-sycl/concat.cpp +196 -0
  83. data/ext/ggml/src/ggml-sycl/conv.cpp +99 -0
  84. data/ext/ggml/src/ggml-sycl/convert.cpp +547 -0
  85. data/ext/ggml/src/ggml-sycl/dmmv.cpp +1023 -0
  86. data/ext/ggml/src/ggml-sycl/element_wise.cpp +1030 -0
  87. data/ext/ggml/src/ggml-sycl/ggml-sycl.cpp +4729 -0
  88. data/ext/ggml/src/ggml-sycl/im2col.cpp +126 -0
  89. data/ext/ggml/src/ggml-sycl/mmq.cpp +3031 -0
  90. data/ext/ggml/src/ggml-sycl/mmvq.cpp +1015 -0
  91. data/ext/ggml/src/ggml-sycl/norm.cpp +378 -0
  92. data/ext/ggml/src/ggml-sycl/outprod.cpp +56 -0
  93. data/ext/ggml/src/ggml-sycl/rope.cpp +276 -0
  94. data/ext/ggml/src/ggml-sycl/softmax.cpp +251 -0
  95. data/ext/ggml/src/ggml-sycl/tsembd.cpp +72 -0
  96. data/ext/ggml/src/ggml-sycl/wkv6.cpp +141 -0
  97. data/ext/ggml/src/ggml-threading.cpp +12 -0
  98. data/ext/ggml/src/ggml-threading.h +14 -0
  99. data/ext/ggml/src/ggml-vulkan/ggml-vulkan.cpp +8657 -0
  100. data/ext/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +593 -0
  101. data/ext/ggml/src/ggml.c +7694 -0
  102. data/ext/include/whisper.h +672 -0
  103. data/ext/metal-embed.mk +17 -0
  104. data/ext/metal.mk +6 -0
  105. data/ext/ruby_whisper.cpp +1608 -159
  106. data/ext/ruby_whisper.h +10 -0
  107. data/ext/scripts/get-flags.mk +38 -0
  108. data/ext/src/coreml/whisper-decoder-impl.h +146 -0
  109. data/ext/src/coreml/whisper-decoder-impl.m +201 -0
  110. data/ext/src/coreml/whisper-encoder-impl.h +142 -0
  111. data/ext/src/coreml/whisper-encoder-impl.m +197 -0
  112. data/ext/src/coreml/whisper-encoder.h +26 -0
  113. data/ext/src/openvino/whisper-openvino-encoder.cpp +108 -0
  114. data/ext/src/openvino/whisper-openvino-encoder.h +31 -0
  115. data/ext/src/whisper.cpp +7393 -0
  116. data/extsources.rb +6 -0
  117. data/lib/whisper/model/uri.rb +157 -0
  118. data/lib/whisper.rb +2 -0
  119. data/tests/helper.rb +7 -0
  120. data/tests/jfk_reader/.gitignore +5 -0
  121. data/tests/jfk_reader/extconf.rb +3 -0
  122. data/tests/jfk_reader/jfk_reader.c +68 -0
  123. data/tests/test_callback.rb +160 -0
  124. data/tests/test_error.rb +20 -0
  125. data/tests/test_model.rb +71 -0
  126. data/tests/test_package.rb +31 -0
  127. data/tests/test_params.rb +160 -0
  128. data/tests/test_segment.rb +83 -0
  129. data/tests/test_whisper.rb +211 -123
  130. data/whispercpp.gemspec +36 -0
  131. metadata +137 -11
  132. data/ext/ggml.c +0 -8616
  133. data/ext/ggml.h +0 -748
  134. data/ext/whisper.cpp +0 -4829
  135. data/ext/whisper.h +0 -402
data/ext/ruby_whisper.h CHANGED
@@ -3,6 +3,13 @@
3
3
 
4
4
  #include "whisper.h"
5
5
 
6
+ typedef struct {
7
+ VALUE *context;
8
+ VALUE user_data;
9
+ VALUE callback;
10
+ VALUE callbacks;
11
+ } ruby_whisper_callback_container;
12
+
6
13
  typedef struct {
7
14
  struct whisper_context *context;
8
15
  } ruby_whisper;
@@ -10,6 +17,9 @@ typedef struct {
10
17
  typedef struct {
11
18
  struct whisper_full_params params;
12
19
  bool diarize;
20
+ ruby_whisper_callback_container *new_segment_callback_container;
21
+ ruby_whisper_callback_container *progress_callback_container;
22
+ ruby_whisper_callback_container *abort_callback_container;
13
23
  } ruby_whisper_params;
14
24
 
15
25
  #endif
@@ -0,0 +1,38 @@
1
+ ifeq '' '$(findstring clang,$(shell $(GF_CC) --version))'
2
+ GF_CC_IS_GCC = 1
3
+ GF_CC_VER := $(shell { $(GF_CC) -dumpfullversion 2>/dev/null; echo; $(GF_CC) -dumpversion; } | awk -F. '/./ { printf("%02d%02d%02d", $$1, $$2, $$3); exit }')
4
+ else
5
+ GF_CC_IS_CLANG = 1
6
+ ifeq '' '$(findstring Apple,$(shell $(GF_CC) --version))'
7
+ GF_CC_IS_LLVM_CLANG = 1
8
+ else
9
+ GF_CC_IS_APPLE_CLANG = 1
10
+ endif
11
+ GF_CC_VER := \
12
+ $(shell $(GF_CC) --version | sed -n 's/^.* version \([0-9.]*\).*$$/\1/p' \
13
+ | awk -F. '{ printf("%02d%02d%02d", $$1, $$2, $$3) }')
14
+ endif
15
+
16
+ ifeq ($(GF_CC_IS_CLANG), 1)
17
+ # clang options
18
+ GF_CFLAGS = -Wunreachable-code-break -Wunreachable-code-return
19
+ GF_CXXFLAGS = -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi
20
+
21
+ ifneq '' '$(and $(GF_CC_IS_LLVM_CLANG),$(filter 1,$(shell expr $(GF_CC_VER) \>= 030800)))'
22
+ GF_CFLAGS += -Wdouble-promotion
23
+ endif
24
+ ifneq '' '$(and $(GF_CC_IS_APPLE_CLANG),$(filter 1,$(shell expr $(GF_CC_VER) \>= 070300)))'
25
+ GF_CFLAGS += -Wdouble-promotion
26
+ endif
27
+ else
28
+ # gcc options
29
+ GF_CFLAGS = -Wdouble-promotion
30
+ GF_CXXFLAGS = -Wno-array-bounds
31
+
32
+ ifeq ($(shell expr $(GF_CC_VER) \>= 070100), 1)
33
+ GF_CXXFLAGS += -Wno-format-truncation
34
+ endif
35
+ ifeq ($(shell expr $(GF_CC_VER) \>= 080100), 1)
36
+ GF_CXXFLAGS += -Wextra-semi
37
+ endif
38
+ endif
@@ -0,0 +1,146 @@
1
+ //
2
+ // whisper-decoder-impl.h
3
+ //
4
+ // This file was automatically generated and should not be edited.
5
+ //
6
+
7
+ #import <Foundation/Foundation.h>
8
+ #import <CoreML/CoreML.h>
9
+ #include <stdint.h>
10
+ #include <os/log.h>
11
+
12
+ NS_ASSUME_NONNULL_BEGIN
13
+
14
+
15
+ /// Model Prediction Input Type
16
+ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((visibility("hidden")))
17
+ @interface whisper_decoder_implInput : NSObject<MLFeatureProvider>
18
+
19
+ /// token_data as 1 by 1 matrix of 32-bit integers
20
+ @property (readwrite, nonatomic, strong) MLMultiArray * token_data;
21
+
22
+ /// audio_data as 1 × 384 × 1 × 1500 4-dimensional array of floats
23
+ @property (readwrite, nonatomic, strong) MLMultiArray * audio_data;
24
+ - (instancetype)init NS_UNAVAILABLE;
25
+ - (instancetype)initWithToken_data:(MLMultiArray *)token_data audio_data:(MLMultiArray *)audio_data NS_DESIGNATED_INITIALIZER;
26
+
27
+ @end
28
+
29
+
30
+ /// Model Prediction Output Type
31
+ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((visibility("hidden")))
32
+ @interface whisper_decoder_implOutput : NSObject<MLFeatureProvider>
33
+
34
+ /// var_1346 as multidimensional array of floats
35
+ @property (readwrite, nonatomic, strong) MLMultiArray * var_1346;
36
+ - (instancetype)init NS_UNAVAILABLE;
37
+ - (instancetype)initWithVar_1346:(MLMultiArray *)var_1346 NS_DESIGNATED_INITIALIZER;
38
+
39
+ @end
40
+
41
+
42
+ /// Class for model loading and prediction
43
+ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((visibility("hidden")))
44
+ @interface whisper_decoder_impl : NSObject
45
+ @property (readonly, nonatomic, nullable) MLModel * model;
46
+
47
+ /**
48
+ URL of the underlying .mlmodelc directory.
49
+ */
50
+ + (nullable NSURL *)URLOfModelInThisBundle;
51
+
52
+ /**
53
+ Initialize whisper_decoder_impl instance from an existing MLModel object.
54
+
55
+ Usually the application does not use this initializer unless it makes a subclass of whisper_decoder_impl.
56
+ Such application may want to use `-[MLModel initWithContentsOfURL:configuration:error:]` and `+URLOfModelInThisBundle` to create a MLModel object to pass-in.
57
+ */
58
+ - (instancetype)initWithMLModel:(MLModel *)model NS_DESIGNATED_INITIALIZER;
59
+
60
+ /**
61
+ Initialize whisper_decoder_impl instance with the model in this bundle.
62
+ */
63
+ - (nullable instancetype)init;
64
+
65
+ /**
66
+ Initialize whisper_decoder_impl instance with the model in this bundle.
67
+
68
+ @param configuration The model configuration object
69
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
70
+ */
71
+ - (nullable instancetype)initWithConfiguration:(MLModelConfiguration *)configuration error:(NSError * _Nullable __autoreleasing * _Nullable)error;
72
+
73
+ /**
74
+ Initialize whisper_decoder_impl instance from the model URL.
75
+
76
+ @param modelURL URL to the .mlmodelc directory for whisper_decoder_impl.
77
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
78
+ */
79
+ - (nullable instancetype)initWithContentsOfURL:(NSURL *)modelURL error:(NSError * _Nullable __autoreleasing * _Nullable)error;
80
+
81
+ /**
82
+ Initialize whisper_decoder_impl instance from the model URL.
83
+
84
+ @param modelURL URL to the .mlmodelc directory for whisper_decoder_impl.
85
+ @param configuration The model configuration object
86
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
87
+ */
88
+ - (nullable instancetype)initWithContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration error:(NSError * _Nullable __autoreleasing * _Nullable)error;
89
+
90
+ /**
91
+ Construct whisper_decoder_impl instance asynchronously with configuration.
92
+ Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
93
+
94
+ @param configuration The model configuration
95
+ @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid whisper_decoder_impl instance or NSError object.
96
+ */
97
+ + (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler;
98
+
99
+ /**
100
+ Construct whisper_decoder_impl instance asynchronously with URL of .mlmodelc directory and optional configuration.
101
+
102
+ Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
103
+
104
+ @param modelURL The model URL.
105
+ @param configuration The model configuration
106
+ @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid whisper_decoder_impl instance or NSError object.
107
+ */
108
+ + (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler;
109
+
110
+ /**
111
+ Make a prediction using the standard interface
112
+ @param input an instance of whisper_decoder_implInput to predict from
113
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
114
+ @return the prediction as whisper_decoder_implOutput
115
+ */
116
+ - (nullable whisper_decoder_implOutput *)predictionFromFeatures:(whisper_decoder_implInput *)input error:(NSError * _Nullable __autoreleasing * _Nullable)error;
117
+
118
+ /**
119
+ Make a prediction using the standard interface
120
+ @param input an instance of whisper_decoder_implInput to predict from
121
+ @param options prediction options
122
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
123
+ @return the prediction as whisper_decoder_implOutput
124
+ */
125
+ - (nullable whisper_decoder_implOutput *)predictionFromFeatures:(whisper_decoder_implInput *)input options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error;
126
+
127
+ /**
128
+ Make a prediction using the convenience interface
129
+ @param token_data as 1 by 1 matrix of 32-bit integers:
130
+ @param audio_data as 1 × 384 × 1 × 1500 4-dimensional array of floats:
131
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
132
+ @return the prediction as whisper_decoder_implOutput
133
+ */
134
+ - (nullable whisper_decoder_implOutput *)predictionFromToken_data:(MLMultiArray *)token_data audio_data:(MLMultiArray *)audio_data error:(NSError * _Nullable __autoreleasing * _Nullable)error;
135
+
136
+ /**
137
+ Batch prediction
138
+ @param inputArray array of whisper_decoder_implInput instances to obtain predictions from
139
+ @param options prediction options
140
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
141
+ @return the predictions as NSArray<whisper_decoder_implOutput *>
142
+ */
143
+ - (nullable NSArray<whisper_decoder_implOutput *> *)predictionsFromInputs:(NSArray<whisper_decoder_implInput*> *)inputArray options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error;
144
+ @end
145
+
146
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,201 @@
1
+ //
2
+ // whisper-decoder-impl.m
3
+ //
4
+ // This file was automatically generated and should not be edited.
5
+ //
6
+
7
+ #if !__has_feature(objc_arc)
8
+ #error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
9
+ #endif
10
+
11
+ #import "whisper-decoder-impl.h"
12
+
13
+ @implementation whisper_decoder_implInput
14
+
15
+ - (instancetype)initWithToken_data:(MLMultiArray *)token_data audio_data:(MLMultiArray *)audio_data {
16
+ self = [super init];
17
+ if (self) {
18
+ _token_data = token_data;
19
+ _audio_data = audio_data;
20
+ }
21
+ return self;
22
+ }
23
+
24
+ - (NSSet<NSString *> *)featureNames {
25
+ return [NSSet setWithArray:@[@"token_data", @"audio_data"]];
26
+ }
27
+
28
+ - (nullable MLFeatureValue *)featureValueForName:(NSString *)featureName {
29
+ if ([featureName isEqualToString:@"token_data"]) {
30
+ return [MLFeatureValue featureValueWithMultiArray:self.token_data];
31
+ }
32
+ if ([featureName isEqualToString:@"audio_data"]) {
33
+ return [MLFeatureValue featureValueWithMultiArray:self.audio_data];
34
+ }
35
+ return nil;
36
+ }
37
+
38
+ @end
39
+
40
+ @implementation whisper_decoder_implOutput
41
+
42
+ - (instancetype)initWithVar_1346:(MLMultiArray *)var_1346 {
43
+ self = [super init];
44
+ if (self) {
45
+ _var_1346 = var_1346;
46
+ }
47
+ return self;
48
+ }
49
+
50
+ - (NSSet<NSString *> *)featureNames {
51
+ return [NSSet setWithArray:@[@"var_1346"]];
52
+ }
53
+
54
+ - (nullable MLFeatureValue *)featureValueForName:(NSString *)featureName {
55
+ if ([featureName isEqualToString:@"var_1346"]) {
56
+ return [MLFeatureValue featureValueWithMultiArray:self.var_1346];
57
+ }
58
+ return nil;
59
+ }
60
+
61
+ @end
62
+
63
+ @implementation whisper_decoder_impl
64
+
65
+
66
+ /**
67
+ URL of the underlying .mlmodelc directory.
68
+ */
69
+ + (nullable NSURL *)URLOfModelInThisBundle {
70
+ NSString *assetPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"whisper_decoder_impl" ofType:@"mlmodelc"];
71
+ if (nil == assetPath) { os_log_error(OS_LOG_DEFAULT, "Could not load whisper-decoder-impl.mlmodelc in the bundle resource"); return nil; }
72
+ return [NSURL fileURLWithPath:assetPath];
73
+ }
74
+
75
+
76
+ /**
77
+ Initialize whisper_decoder_impl instance from an existing MLModel object.
78
+
79
+ Usually the application does not use this initializer unless it makes a subclass of whisper_decoder_impl.
80
+ Such application may want to use `-[MLModel initWithContentsOfURL:configuration:error:]` and `+URLOfModelInThisBundle` to create a MLModel object to pass-in.
81
+ */
82
+ - (instancetype)initWithMLModel:(MLModel *)model {
83
+ self = [super init];
84
+ if (!self) { return nil; }
85
+ _model = model;
86
+ if (_model == nil) { return nil; }
87
+ return self;
88
+ }
89
+
90
+
91
+ /**
92
+ Initialize whisper_decoder_impl instance with the model in this bundle.
93
+ */
94
+ - (nullable instancetype)init {
95
+ return [self initWithContentsOfURL:(NSURL * _Nonnull)self.class.URLOfModelInThisBundle error:nil];
96
+ }
97
+
98
+
99
+ /**
100
+ Initialize whisper_decoder_impl instance with the model in this bundle.
101
+
102
+ @param configuration The model configuration object
103
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
104
+ */
105
+ - (nullable instancetype)initWithConfiguration:(MLModelConfiguration *)configuration error:(NSError * _Nullable __autoreleasing * _Nullable)error {
106
+ return [self initWithContentsOfURL:(NSURL * _Nonnull)self.class.URLOfModelInThisBundle configuration:configuration error:error];
107
+ }
108
+
109
+
110
+ /**
111
+ Initialize whisper_decoder_impl instance from the model URL.
112
+
113
+ @param modelURL URL to the .mlmodelc directory for whisper_decoder_impl.
114
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
115
+ */
116
+ - (nullable instancetype)initWithContentsOfURL:(NSURL *)modelURL error:(NSError * _Nullable __autoreleasing * _Nullable)error {
117
+ MLModel *model = [MLModel modelWithContentsOfURL:modelURL error:error];
118
+ if (model == nil) { return nil; }
119
+ return [self initWithMLModel:model];
120
+ }
121
+
122
+
123
+ /**
124
+ Initialize whisper_decoder_impl instance from the model URL.
125
+
126
+ @param modelURL URL to the .mlmodelc directory for whisper_decoder_impl.
127
+ @param configuration The model configuration object
128
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
129
+ */
130
+ - (nullable instancetype)initWithContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration error:(NSError * _Nullable __autoreleasing * _Nullable)error {
131
+ MLModel *model = [MLModel modelWithContentsOfURL:modelURL configuration:configuration error:error];
132
+ if (model == nil) { return nil; }
133
+ return [self initWithMLModel:model];
134
+ }
135
+
136
+
137
+ /**
138
+ Construct whisper_decoder_impl instance asynchronously with configuration.
139
+ Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
140
+
141
+ @param configuration The model configuration
142
+ @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid whisper_decoder_impl instance or NSError object.
143
+ */
144
+ + (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler {
145
+ [self loadContentsOfURL:(NSURL * _Nonnull)[self URLOfModelInThisBundle]
146
+ configuration:configuration
147
+ completionHandler:handler];
148
+ }
149
+
150
+
151
+ /**
152
+ Construct whisper_decoder_impl instance asynchronously with URL of .mlmodelc directory and optional configuration.
153
+
154
+ Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
155
+
156
+ @param modelURL The model URL.
157
+ @param configuration The model configuration
158
+ @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid whisper_decoder_impl instance or NSError object.
159
+ */
160
+ + (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler {
161
+ [MLModel loadContentsOfURL:modelURL
162
+ configuration:configuration
163
+ completionHandler:^(MLModel *model, NSError *error) {
164
+ if (model != nil) {
165
+ whisper_decoder_impl *typedModel = [[whisper_decoder_impl alloc] initWithMLModel:model];
166
+ handler(typedModel, nil);
167
+ } else {
168
+ handler(nil, error);
169
+ }
170
+ }];
171
+ }
172
+
173
+ - (nullable whisper_decoder_implOutput *)predictionFromFeatures:(whisper_decoder_implInput *)input error:(NSError * _Nullable __autoreleasing * _Nullable)error {
174
+ return [self predictionFromFeatures:input options:[[MLPredictionOptions alloc] init] error:error];
175
+ }
176
+
177
+ - (nullable whisper_decoder_implOutput *)predictionFromFeatures:(whisper_decoder_implInput *)input options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error {
178
+ id<MLFeatureProvider> outFeatures = [self.model predictionFromFeatures:input options:options error:error];
179
+ if (!outFeatures) { return nil; }
180
+ return [[whisper_decoder_implOutput alloc] initWithVar_1346:(MLMultiArray *)[outFeatures featureValueForName:@"var_1346"].multiArrayValue];
181
+ }
182
+
183
+ - (nullable whisper_decoder_implOutput *)predictionFromToken_data:(MLMultiArray *)token_data audio_data:(MLMultiArray *)audio_data error:(NSError * _Nullable __autoreleasing * _Nullable)error {
184
+ whisper_decoder_implInput *input_ = [[whisper_decoder_implInput alloc] initWithToken_data:token_data audio_data:audio_data];
185
+ return [self predictionFromFeatures:input_ error:error];
186
+ }
187
+
188
+ - (nullable NSArray<whisper_decoder_implOutput *> *)predictionsFromInputs:(NSArray<whisper_decoder_implInput*> *)inputArray options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error {
189
+ id<MLBatchProvider> inBatch = [[MLArrayBatchProvider alloc] initWithFeatureProviderArray:inputArray];
190
+ id<MLBatchProvider> outBatch = [self.model predictionsFromBatch:inBatch options:options error:error];
191
+ if (!outBatch) { return nil; }
192
+ NSMutableArray<whisper_decoder_implOutput*> *results = [NSMutableArray arrayWithCapacity:(NSUInteger)outBatch.count];
193
+ for (NSInteger i = 0; i < outBatch.count; i++) {
194
+ id<MLFeatureProvider> resultProvider = [outBatch featuresAtIndex:i];
195
+ whisper_decoder_implOutput * result = [[whisper_decoder_implOutput alloc] initWithVar_1346:(MLMultiArray *)[resultProvider featureValueForName:@"var_1346"].multiArrayValue];
196
+ [results addObject:result];
197
+ }
198
+ return results;
199
+ }
200
+
201
+ @end
@@ -0,0 +1,142 @@
1
+ //
2
+ // whisper-encoder-impl.h
3
+ //
4
+ // This file was automatically generated and should not be edited.
5
+ //
6
+
7
+ #import <Foundation/Foundation.h>
8
+ #import <CoreML/CoreML.h>
9
+ #include <stdint.h>
10
+ #include <os/log.h>
11
+
12
+ NS_ASSUME_NONNULL_BEGIN
13
+
14
+
15
+ /// Model Prediction Input Type
16
+ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((visibility("hidden")))
17
+ @interface whisper_encoder_implInput : NSObject<MLFeatureProvider>
18
+
19
+ /// logmel_data as 1 × 80 × 3000 3-dimensional array of floats
20
+ @property (readwrite, nonatomic, strong) MLMultiArray * logmel_data;
21
+ - (instancetype)init NS_UNAVAILABLE;
22
+ - (instancetype)initWithLogmel_data:(MLMultiArray *)logmel_data NS_DESIGNATED_INITIALIZER;
23
+
24
+ @end
25
+
26
+
27
+ /// Model Prediction Output Type
28
+ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((visibility("hidden")))
29
+ @interface whisper_encoder_implOutput : NSObject<MLFeatureProvider>
30
+
31
+ /// output as multidimensional array of floats
32
+ @property (readwrite, nonatomic, strong) MLMultiArray * output;
33
+ - (instancetype)init NS_UNAVAILABLE;
34
+ - (instancetype)initWithOutput:(MLMultiArray *)output NS_DESIGNATED_INITIALIZER;
35
+
36
+ @end
37
+
38
+
39
+ /// Class for model loading and prediction
40
+ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((visibility("hidden")))
41
+ @interface whisper_encoder_impl : NSObject
42
+ @property (readonly, nonatomic, nullable) MLModel * model;
43
+
44
+ /**
45
+ URL of the underlying .mlmodelc directory.
46
+ */
47
+ + (nullable NSURL *)URLOfModelInThisBundle;
48
+
49
+ /**
50
+ Initialize whisper_encoder_impl instance from an existing MLModel object.
51
+
52
+ Usually the application does not use this initializer unless it makes a subclass of whisper_encoder_impl.
53
+ Such application may want to use `-[MLModel initWithContentsOfURL:configuration:error:]` and `+URLOfModelInThisBundle` to create a MLModel object to pass-in.
54
+ */
55
+ - (instancetype)initWithMLModel:(MLModel *)model NS_DESIGNATED_INITIALIZER;
56
+
57
+ /**
58
+ Initialize whisper_encoder_impl instance with the model in this bundle.
59
+ */
60
+ - (nullable instancetype)init;
61
+
62
+ /**
63
+ Initialize whisper_encoder_impl instance with the model in this bundle.
64
+
65
+ @param configuration The model configuration object
66
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
67
+ */
68
+ - (nullable instancetype)initWithConfiguration:(MLModelConfiguration *)configuration error:(NSError * _Nullable __autoreleasing * _Nullable)error;
69
+
70
+ /**
71
+ Initialize whisper_encoder_impl instance from the model URL.
72
+
73
+ @param modelURL URL to the .mlmodelc directory for whisper_encoder_impl.
74
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
75
+ */
76
+ - (nullable instancetype)initWithContentsOfURL:(NSURL *)modelURL error:(NSError * _Nullable __autoreleasing * _Nullable)error;
77
+
78
+ /**
79
+ Initialize whisper_encoder_impl instance from the model URL.
80
+
81
+ @param modelURL URL to the .mlmodelc directory for whisper_encoder_impl.
82
+ @param configuration The model configuration object
83
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
84
+ */
85
+ - (nullable instancetype)initWithContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration error:(NSError * _Nullable __autoreleasing * _Nullable)error;
86
+
87
+ /**
88
+ Construct whisper_encoder_impl instance asynchronously with configuration.
89
+ Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
90
+
91
+ @param configuration The model configuration
92
+ @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid whisper_encoder_impl instance or NSError object.
93
+ */
94
+ + (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_encoder_impl * _Nullable model, NSError * _Nullable error))handler;
95
+
96
+ /**
97
+ Construct whisper_encoder_impl instance asynchronously with URL of .mlmodelc directory and optional configuration.
98
+
99
+ Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
100
+
101
+ @param modelURL The model URL.
102
+ @param configuration The model configuration
103
+ @param handler When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid whisper_encoder_impl instance or NSError object.
104
+ */
105
+ + (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_encoder_impl * _Nullable model, NSError * _Nullable error))handler;
106
+
107
+ /**
108
+ Make a prediction using the standard interface
109
+ @param input an instance of whisper_encoder_implInput to predict from
110
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
111
+ @return the prediction as whisper_encoder_implOutput
112
+ */
113
+ - (nullable whisper_encoder_implOutput *)predictionFromFeatures:(whisper_encoder_implInput *)input error:(NSError * _Nullable __autoreleasing * _Nullable)error;
114
+
115
+ /**
116
+ Make a prediction using the standard interface
117
+ @param input an instance of whisper_encoder_implInput to predict from
118
+ @param options prediction options
119
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
120
+ @return the prediction as whisper_encoder_implOutput
121
+ */
122
+ - (nullable whisper_encoder_implOutput *)predictionFromFeatures:(whisper_encoder_implInput *)input options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error;
123
+
124
+ /**
125
+ Make a prediction using the convenience interface
126
+ @param logmel_data as 1 × n_mel × 3000 3-dimensional array of floats:
127
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
128
+ @return the prediction as whisper_encoder_implOutput
129
+ */
130
+ - (nullable whisper_encoder_implOutput *)predictionFromLogmel_data:(MLMultiArray *)logmel_data error:(NSError * _Nullable __autoreleasing * _Nullable)error;
131
+
132
+ /**
133
+ Batch prediction
134
+ @param inputArray array of whisper_encoder_implInput instances to obtain predictions from
135
+ @param options prediction options
136
+ @param error If an error occurs, upon return contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
137
+ @return the predictions as NSArray<whisper_encoder_implOutput *>
138
+ */
139
+ - (nullable NSArray<whisper_encoder_implOutput *> *)predictionsFromInputs:(NSArray<whisper_encoder_implInput*> *)inputArray options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error;
140
+ @end
141
+
142
+ NS_ASSUME_NONNULL_END