whisper.rn 0.4.0-rc.9 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/android/build.gradle +12 -3
- package/android/src/main/CMakeLists.txt +43 -13
- package/android/src/main/java/com/rnwhisper/WhisperContext.java +33 -35
- package/android/src/main/jni.cpp +9 -0
- package/android/src/main/jniLibs/arm64-v8a/librnwhisper.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librnwhisper_v8fp16_va_2.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/librnwhisper.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/librnwhisper_vfpv4.so +0 -0
- package/android/src/main/jniLibs/x86_64/librnwhisper.so +0 -0
- package/android/src/main/jniLibs/x86_64/librnwhisper_x86_64.so +0 -0
- package/cpp/coreml/whisper-compat.h +10 -0
- package/cpp/coreml/whisper-compat.m +35 -0
- package/cpp/coreml/whisper-decoder-impl.h +27 -15
- package/cpp/coreml/whisper-decoder-impl.m +36 -10
- package/cpp/coreml/whisper-encoder-impl.h +21 -9
- package/cpp/coreml/whisper-encoder-impl.m +29 -3
- package/cpp/ggml-alloc.c +39 -37
- package/cpp/ggml-alloc.h +1 -1
- package/cpp/ggml-backend-impl.h +55 -27
- package/cpp/ggml-backend-reg.cpp +591 -0
- package/cpp/ggml-backend.cpp +336 -955
- package/cpp/ggml-backend.h +70 -42
- package/cpp/ggml-common.h +57 -49
- package/cpp/ggml-cpp.h +39 -0
- package/cpp/ggml-cpu/amx/amx.cpp +221 -0
- package/cpp/ggml-cpu/amx/amx.h +8 -0
- package/cpp/ggml-cpu/amx/common.h +91 -0
- package/cpp/ggml-cpu/amx/mmq.cpp +2511 -0
- package/cpp/ggml-cpu/amx/mmq.h +10 -0
- package/cpp/ggml-cpu/arch/arm/cpu-feats.cpp +94 -0
- package/cpp/ggml-cpu/arch/arm/quants.c +4113 -0
- package/cpp/ggml-cpu/arch/arm/repack.cpp +2162 -0
- package/cpp/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
- package/cpp/ggml-cpu/arch/x86/quants.c +4310 -0
- package/cpp/ggml-cpu/arch/x86/repack.cpp +3284 -0
- package/cpp/ggml-cpu/arch-fallback.h +184 -0
- package/cpp/ggml-cpu/binary-ops.cpp +158 -0
- package/cpp/ggml-cpu/binary-ops.h +16 -0
- package/cpp/ggml-cpu/common.h +72 -0
- package/cpp/ggml-cpu/ggml-cpu-impl.h +511 -0
- package/cpp/ggml-cpu/ggml-cpu.c +3473 -0
- package/cpp/ggml-cpu/ggml-cpu.cpp +671 -0
- package/cpp/ggml-cpu/ops.cpp +9085 -0
- package/cpp/ggml-cpu/ops.h +111 -0
- package/cpp/ggml-cpu/quants.c +1157 -0
- package/cpp/ggml-cpu/quants.h +89 -0
- package/cpp/ggml-cpu/repack.cpp +1570 -0
- package/cpp/ggml-cpu/repack.h +98 -0
- package/cpp/ggml-cpu/simd-mappings.h +1006 -0
- package/cpp/ggml-cpu/traits.cpp +36 -0
- package/cpp/ggml-cpu/traits.h +38 -0
- package/cpp/ggml-cpu/unary-ops.cpp +186 -0
- package/cpp/ggml-cpu/unary-ops.h +28 -0
- package/cpp/ggml-cpu/vec.cpp +321 -0
- package/cpp/ggml-cpu/vec.h +973 -0
- package/cpp/ggml-cpu.h +143 -0
- package/cpp/ggml-impl.h +417 -23
- package/cpp/ggml-metal-impl.h +622 -0
- package/cpp/ggml-metal.h +9 -9
- package/cpp/ggml-metal.m +3451 -1344
- package/cpp/ggml-opt.cpp +1037 -0
- package/cpp/ggml-opt.h +237 -0
- package/cpp/ggml-quants.c +296 -10818
- package/cpp/ggml-quants.h +78 -125
- package/cpp/ggml-threading.cpp +12 -0
- package/cpp/ggml-threading.h +14 -0
- package/cpp/ggml-whisper-sim.metallib +0 -0
- package/cpp/ggml-whisper.metallib +0 -0
- package/cpp/ggml.c +4633 -21450
- package/cpp/ggml.h +320 -661
- package/cpp/gguf.cpp +1347 -0
- package/cpp/gguf.h +202 -0
- package/cpp/rn-whisper.cpp +4 -11
- package/cpp/whisper-arch.h +197 -0
- package/cpp/whisper.cpp +2022 -495
- package/cpp/whisper.h +75 -18
- package/ios/CMakeLists.txt +95 -0
- package/ios/RNWhisper.h +5 -0
- package/ios/RNWhisperAudioUtils.m +4 -0
- package/ios/RNWhisperContext.h +5 -0
- package/ios/RNWhisperContext.mm +4 -2
- package/ios/rnwhisper.xcframework/Info.plist +74 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/ggml-whisper.metallib +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/rnwhisper +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +101 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/ggml-whisper-sim.metallib +0 -0
- package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/ggml-whisper.metallib +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/rnwhisper +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +354 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-common.h +1861 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +603 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +66 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-opt.h +237 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-quants.h +100 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-threading.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +2221 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/gguf.h +202 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +52 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper-arch.h +197 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +739 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +101 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/ggml-whisper-sim.metallib +0 -0
- package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
- package/jest/mock.js +5 -0
- package/lib/commonjs/version.json +1 -1
- package/lib/module/version.json +1 -1
- package/package.json +10 -6
- package/src/version.json +1 -1
- package/whisper-rn.podspec +11 -18
- package/cpp/README.md +0 -4
- package/cpp/ggml-aarch64.c +0 -3209
- package/cpp/ggml-aarch64.h +0 -39
- package/cpp/ggml-cpu-impl.h +0 -614
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ npm install whisper.rn
|
|
|
25
25
|
|
|
26
26
|
Please re-run `npx pod-install` again.
|
|
27
27
|
|
|
28
|
+
By default, `whisper.rn` will use pre-built `rnwhisper.xcframework` for iOS. If you want to build from source, please set `RNWHISPER_BUILD_FROM_SOURCE` to `1` in your Podfile.
|
|
29
|
+
|
|
28
30
|
If you want to use `medium` or `large` model, the [Extended Virtual Addressing](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_kernel_extended-virtual-addressing) capability is recommended to enable on iOS project.
|
|
29
31
|
|
|
30
32
|
#### Android
|
|
@@ -36,7 +38,9 @@ Add proguard rule if it's enabled in project (android/app/proguard-rules.pro):
|
|
|
36
38
|
-keep class com.rnwhisper.** { *; }
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
By default, `whisper.rn` will use pre-built libraries for Android. If you want to build from source, please set `rnwhisperBuildFromSource` to `true` in `android/gradle.properties`.
|
|
42
|
+
|
|
43
|
+
For build from source, it's recommended to use `ndkVersion = "24.0.8215888"` (or above) in your root project build configuration for Apple Silicon Macs. Otherwise please follow this trobleshooting [issue](./TROUBLESHOOTING.md#android-got-build-error-unknown-host-cpu-architecture-arm64-on-apple-silicon-macs).
|
|
40
44
|
|
|
41
45
|
#### Expo
|
|
42
46
|
|
package/android/build.gradle
CHANGED
|
@@ -53,9 +53,18 @@ android {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
def rnwhisperBuildFromSource = project.properties["rnwhisperBuildFromSource"]
|
|
57
|
+
if (rnwhisperBuildFromSource == "true") {
|
|
58
|
+
externalNativeBuild {
|
|
59
|
+
cmake {
|
|
60
|
+
path = file('src/main/CMakeLists.txt')
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Exclude jniLibs
|
|
64
|
+
sourceSets {
|
|
65
|
+
main {
|
|
66
|
+
jniLibs.srcDirs = []
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
buildTypes {
|
|
@@ -2,16 +2,35 @@ cmake_minimum_required(VERSION 3.10)
|
|
|
2
2
|
|
|
3
3
|
project(whisper.rn)
|
|
4
4
|
|
|
5
|
-
set(CMAKE_CXX_STANDARD
|
|
5
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
6
6
|
set(RNWHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../cpp)
|
|
7
7
|
|
|
8
|
+
include_directories(
|
|
9
|
+
${RNWHISPER_LIB_DIR}
|
|
10
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu
|
|
11
|
+
)
|
|
12
|
+
|
|
8
13
|
set(
|
|
9
14
|
SOURCE_FILES
|
|
10
15
|
${RNWHISPER_LIB_DIR}/ggml.c
|
|
11
16
|
${RNWHISPER_LIB_DIR}/ggml-alloc.c
|
|
12
17
|
${RNWHISPER_LIB_DIR}/ggml-backend.cpp
|
|
18
|
+
${RNWHISPER_LIB_DIR}/ggml-backend-reg.cpp
|
|
19
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/amx/amx.cpp
|
|
20
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/amx/mmq.cpp
|
|
21
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/ggml-cpu.c
|
|
22
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/ggml-cpu.cpp
|
|
23
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/quants.c
|
|
24
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/traits.cpp
|
|
25
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/repack.cpp
|
|
26
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/unary-ops.cpp
|
|
27
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/binary-ops.cpp
|
|
28
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/vec.cpp
|
|
29
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/ops.cpp
|
|
30
|
+
${RNWHISPER_LIB_DIR}/ggml-opt.cpp
|
|
31
|
+
${RNWHISPER_LIB_DIR}/ggml-threading.cpp
|
|
13
32
|
${RNWHISPER_LIB_DIR}/ggml-quants.c
|
|
14
|
-
${RNWHISPER_LIB_DIR}/
|
|
33
|
+
${RNWHISPER_LIB_DIR}/gguf.cpp
|
|
15
34
|
${RNWHISPER_LIB_DIR}/whisper.cpp
|
|
16
35
|
${RNWHISPER_LIB_DIR}/rn-audioutils.cpp
|
|
17
36
|
${RNWHISPER_LIB_DIR}/rn-whisper.cpp
|
|
@@ -20,45 +39,56 @@ set(
|
|
|
20
39
|
|
|
21
40
|
find_library(LOG_LIB log)
|
|
22
41
|
|
|
23
|
-
function(build_library target_name)
|
|
42
|
+
function(build_library target_name arch cpu_flags)
|
|
43
|
+
if (NOT ${arch} STREQUAL "generic")
|
|
44
|
+
set(SOURCE_FILES_ARCH
|
|
45
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/arch/${arch}/quants.c
|
|
46
|
+
${RNWHISPER_LIB_DIR}/ggml-cpu/arch/${arch}/repack.cpp
|
|
47
|
+
)
|
|
48
|
+
endif ()
|
|
49
|
+
|
|
24
50
|
add_library(
|
|
25
51
|
${target_name}
|
|
26
52
|
SHARED
|
|
27
53
|
${SOURCE_FILES}
|
|
54
|
+
${SOURCE_FILES_ARCH}
|
|
28
55
|
)
|
|
29
56
|
|
|
30
57
|
target_link_libraries(${target_name} ${LOG_LIB} android)
|
|
31
58
|
|
|
32
|
-
if (${
|
|
33
|
-
target_compile_options(${target_name} PRIVATE -
|
|
34
|
-
elseif (${target_name} STREQUAL "whisper_vfpv4")
|
|
35
|
-
target_compile_options(${target_name} PRIVATE -mfpu=neon-vfpv4)
|
|
59
|
+
if (${arch} STREQUAL "generic")
|
|
60
|
+
target_compile_options(${target_name} PRIVATE -DWSP_GGML_CPU_GENERIC)
|
|
36
61
|
endif ()
|
|
37
62
|
|
|
63
|
+
target_compile_options(${target_name} PRIVATE -DWSP_GGML_USE_CPU -DWSP_GGML_USE_CPU_REPACK -pthread ${cpu_flags})
|
|
64
|
+
|
|
38
65
|
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
|
|
39
66
|
target_compile_options(${target_name} PRIVATE -DRNWHISPER_ANDROID_ENABLE_LOGGING)
|
|
40
67
|
endif ()
|
|
41
68
|
|
|
42
69
|
# NOTE: If you want to debug the native code, you can uncomment if and endif
|
|
70
|
+
# Note that it will be extremely slow
|
|
43
71
|
# if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
|
|
44
|
-
|
|
45
|
-
target_compile_options(${target_name} PRIVATE -O3 -DNDEBUG -pthread)
|
|
72
|
+
target_compile_options(${target_name} PRIVATE -O3 -DNDEBUG)
|
|
46
73
|
target_compile_options(${target_name} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
|
|
47
74
|
target_compile_options(${target_name} PRIVATE -ffunction-sections -fdata-sections)
|
|
48
75
|
|
|
49
76
|
target_link_options(${target_name} PRIVATE -Wl,--gc-sections)
|
|
50
77
|
target_link_options(${target_name} PRIVATE -Wl,--exclude-libs,ALL)
|
|
51
78
|
target_link_options(${target_name} PRIVATE -flto)
|
|
52
|
-
|
|
53
79
|
# endif ()
|
|
54
80
|
endfunction()
|
|
55
81
|
|
|
56
|
-
build_library("
|
|
82
|
+
build_library("rnwhisper" "generic" "")
|
|
57
83
|
|
|
58
84
|
if (${ANDROID_ABI} STREQUAL "arm64-v8a")
|
|
59
|
-
build_library("
|
|
85
|
+
build_library("rnwhisper_v8fp16_va_2" "arm" "-march=armv8.2-a+fp16")
|
|
60
86
|
elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
|
|
61
|
-
build_library("
|
|
87
|
+
build_library("rnwhisper_vfpv4" "arm" "-mfpu=neon-vfpv4")
|
|
88
|
+
elseif (${ANDROID_ABI} STREQUAL "x86_64")
|
|
89
|
+
# x86_64 target
|
|
90
|
+
build_library("rnwhisper_x86_64" "x86" "-march=x86-64" "-mtune=intel" "-msse4.2" "-mpopcnt")
|
|
62
91
|
endif ()
|
|
63
92
|
|
|
93
|
+
|
|
64
94
|
include_directories(${RNWHISPER_LIB_DIR})
|
|
@@ -27,6 +27,8 @@ import java.io.PushbackInputStream;
|
|
|
27
27
|
public class WhisperContext {
|
|
28
28
|
public static final String NAME = "RNWhisperContext";
|
|
29
29
|
|
|
30
|
+
private static String loadedLibrary = "";
|
|
31
|
+
|
|
30
32
|
private static final int SAMPLE_RATE = 16000;
|
|
31
33
|
private static final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;
|
|
32
34
|
private static final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
|
|
@@ -433,64 +435,60 @@ public class WhisperContext {
|
|
|
433
435
|
|
|
434
436
|
static {
|
|
435
437
|
Log.d(NAME, "Primary ABI: " + Build.SUPPORTED_ABIS[0]);
|
|
436
|
-
boolean loadVfpv4 = false;
|
|
437
|
-
boolean loadV8fp16 = false;
|
|
438
|
-
if (isArmeabiV7a()) {
|
|
439
|
-
// armeabi-v7a needs runtime detection support
|
|
440
|
-
String cpuInfo = cpuInfo();
|
|
441
|
-
if (cpuInfo != null) {
|
|
442
|
-
Log.d(NAME, "CPU info: " + cpuInfo);
|
|
443
|
-
if (cpuInfo.contains("vfpv4")) {
|
|
444
|
-
Log.d(NAME, "CPU supports vfpv4");
|
|
445
|
-
loadVfpv4 = true;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
} else if (isArmeabiV8a()) {
|
|
449
|
-
// ARMv8.2a needs runtime detection support
|
|
450
|
-
String cpuInfo = cpuInfo();
|
|
451
|
-
if (cpuInfo != null) {
|
|
452
|
-
Log.d(NAME, "CPU info: " + cpuInfo);
|
|
453
|
-
if (cpuInfo.contains("fphp")) {
|
|
454
|
-
Log.d(NAME, "CPU supports fp16 arithmetic");
|
|
455
|
-
loadV8fp16 = true;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
438
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
439
|
+
String cpuFeatures = WhisperContext.getCpuFeatures();
|
|
440
|
+
Log.d(NAME, "CPU features: " + cpuFeatures);
|
|
441
|
+
boolean hasFp16 = cpuFeatures.contains("fp16") || cpuFeatures.contains("fphp");
|
|
442
|
+
Log.d(NAME, "- hasFp16: " + hasFp16);
|
|
443
|
+
|
|
444
|
+
if (WhisperContext.isArm64V8a()) {
|
|
445
|
+
if (hasFp16) {
|
|
446
|
+
Log.d(NAME, "Loading librnwhisper_v8fp16_va_2.so");
|
|
447
|
+
System.loadLibrary("rnwhisper_v8fp16_va_2");
|
|
448
|
+
loadedLibrary = "rnwhisper_v8fp16_va_2";
|
|
449
|
+
}
|
|
450
|
+
} else if (WhisperContext.isArmeabiV7a()) {
|
|
451
|
+
Log.d(NAME, "Loading librnwhisper_vfpv4.so");
|
|
452
|
+
System.loadLibrary("rnwhisper_vfpv4");
|
|
453
|
+
loadedLibrary = "rnwhisper_vfpv4";
|
|
454
|
+
} else if (WhisperContext.isX86_64()) {
|
|
455
|
+
Log.d(NAME, "Loading librnwhisper_x86_64.so");
|
|
456
|
+
System.loadLibrary("rnwhisper_x86_64");
|
|
457
|
+
loadedLibrary = "rnwhisper_x86_64";
|
|
466
458
|
} else {
|
|
467
|
-
Log.d(NAME, "
|
|
468
|
-
System.loadLibrary("whisper");
|
|
459
|
+
Log.d(NAME, "ARM32 is not supported, skipping loading library");
|
|
469
460
|
}
|
|
470
461
|
}
|
|
471
462
|
|
|
463
|
+
private static boolean isArm64V8a() {
|
|
464
|
+
return Build.SUPPORTED_ABIS[0].equals("arm64-v8a");
|
|
465
|
+
}
|
|
466
|
+
|
|
472
467
|
private static boolean isArmeabiV7a() {
|
|
473
468
|
return Build.SUPPORTED_ABIS[0].equals("armeabi-v7a");
|
|
474
469
|
}
|
|
475
470
|
|
|
476
|
-
private static boolean
|
|
477
|
-
return Build.SUPPORTED_ABIS[0].equals("
|
|
471
|
+
private static boolean isX86_64() {
|
|
472
|
+
return Build.SUPPORTED_ABIS[0].equals("x86_64");
|
|
478
473
|
}
|
|
479
474
|
|
|
480
|
-
private static String
|
|
475
|
+
private static String getCpuFeatures() {
|
|
481
476
|
File file = new File("/proc/cpuinfo");
|
|
482
477
|
StringBuilder stringBuilder = new StringBuilder();
|
|
483
478
|
try {
|
|
484
479
|
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
|
485
480
|
String line;
|
|
486
481
|
while ((line = bufferedReader.readLine()) != null) {
|
|
482
|
+
if (line.startsWith("Features")) {
|
|
487
483
|
stringBuilder.append(line);
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
488
486
|
}
|
|
489
487
|
bufferedReader.close();
|
|
490
488
|
return stringBuilder.toString();
|
|
491
489
|
} catch (IOException e) {
|
|
492
490
|
Log.w(NAME, "Couldn't read /proc/cpuinfo", e);
|
|
493
|
-
return
|
|
491
|
+
return "";
|
|
494
492
|
}
|
|
495
493
|
}
|
|
496
494
|
|
package/android/src/main/jni.cpp
CHANGED
|
@@ -155,7 +155,10 @@ Java_com_rnwhisper_WhisperContext_initContext(
|
|
|
155
155
|
JNIEnv *env, jobject thiz, jstring model_path_str) {
|
|
156
156
|
UNUSED(thiz);
|
|
157
157
|
struct whisper_context_params cparams;
|
|
158
|
+
|
|
159
|
+
// TODO: Expose dtw_token_timestamps and dtw_aheads_preset
|
|
158
160
|
cparams.dtw_token_timestamps = false;
|
|
161
|
+
// cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
|
|
159
162
|
|
|
160
163
|
struct whisper_context *context = nullptr;
|
|
161
164
|
const char *model_path_chars = env->GetStringUTFChars(model_path_str, nullptr);
|
|
@@ -173,7 +176,10 @@ Java_com_rnwhisper_WhisperContext_initContextWithAsset(
|
|
|
173
176
|
) {
|
|
174
177
|
UNUSED(thiz);
|
|
175
178
|
struct whisper_context_params cparams;
|
|
179
|
+
|
|
180
|
+
// TODO: Expose dtw_token_timestamps and dtw_aheads_preset
|
|
176
181
|
cparams.dtw_token_timestamps = false;
|
|
182
|
+
// cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
|
|
177
183
|
|
|
178
184
|
struct whisper_context *context = nullptr;
|
|
179
185
|
const char *model_path_chars = env->GetStringUTFChars(model_path_str, nullptr);
|
|
@@ -190,7 +196,10 @@ Java_com_rnwhisper_WhisperContext_initContextWithInputStream(
|
|
|
190
196
|
) {
|
|
191
197
|
UNUSED(thiz);
|
|
192
198
|
struct whisper_context_params cparams;
|
|
199
|
+
|
|
200
|
+
// TODO: Expose dtw_token_timestamps and dtw_aheads_preset
|
|
193
201
|
cparams.dtw_token_timestamps = false;
|
|
202
|
+
// cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
|
|
194
203
|
|
|
195
204
|
struct whisper_context *context = nullptr;
|
|
196
205
|
context = whisper_init_from_input_stream(env, input_stream, cparams);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <CoreML/CoreML.h>
|
|
2
|
+
|
|
3
|
+
@interface MLModel (Compat)
|
|
4
|
+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
|
5
|
+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
|
|
6
|
+
|
|
7
|
+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
|
8
|
+
options:(MLPredictionOptions *) options
|
|
9
|
+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
|
|
10
|
+
@end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#import "whisper-compat.h"
|
|
2
|
+
#import <Foundation/Foundation.h>
|
|
3
|
+
|
|
4
|
+
@implementation MLModel (Compat)
|
|
5
|
+
|
|
6
|
+
#if !defined(MAC_OS_X_VERSION_14_00) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_14_00
|
|
7
|
+
|
|
8
|
+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
|
9
|
+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
|
|
10
|
+
[NSOperationQueue.new addOperationWithBlock:^{
|
|
11
|
+
NSError *error = nil;
|
|
12
|
+
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input error:&error];
|
|
13
|
+
|
|
14
|
+
[NSOperationQueue.mainQueue addOperationWithBlock:^{
|
|
15
|
+
completionHandler(prediction, error);
|
|
16
|
+
}];
|
|
17
|
+
}];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
|
21
|
+
options:(MLPredictionOptions *) options
|
|
22
|
+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
|
|
23
|
+
[NSOperationQueue.new addOperationWithBlock:^{
|
|
24
|
+
NSError *error = nil;
|
|
25
|
+
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input options:options error:&error];
|
|
26
|
+
|
|
27
|
+
[NSOperationQueue.mainQueue addOperationWithBlock:^{
|
|
28
|
+
completionHandler(prediction, error);
|
|
29
|
+
}];
|
|
30
|
+
}];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
@end
|
|
@@ -11,36 +11,33 @@
|
|
|
11
11
|
|
|
12
12
|
NS_ASSUME_NONNULL_BEGIN
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
/// Model Prediction Input Type
|
|
16
|
-
API_AVAILABLE(macos(
|
|
15
|
+
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0)) __attribute__((visibility("hidden")))
|
|
17
16
|
@interface whisper_decoder_implInput : NSObject<MLFeatureProvider>
|
|
18
17
|
|
|
19
|
-
/// token_data as 1 by 1 matrix of
|
|
18
|
+
/// token_data as 1 by 1 matrix of floats
|
|
20
19
|
@property (readwrite, nonatomic, strong) MLMultiArray * token_data;
|
|
21
20
|
|
|
22
|
-
/// audio_data as 1 ×
|
|
21
|
+
/// audio_data as 1 × 1500 × 384 3-dimensional array of floats
|
|
23
22
|
@property (readwrite, nonatomic, strong) MLMultiArray * audio_data;
|
|
24
23
|
- (instancetype)init NS_UNAVAILABLE;
|
|
25
24
|
- (instancetype)initWithToken_data:(MLMultiArray *)token_data audio_data:(MLMultiArray *)audio_data NS_DESIGNATED_INITIALIZER;
|
|
26
25
|
|
|
27
26
|
@end
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
/// Model Prediction Output Type
|
|
31
|
-
API_AVAILABLE(macos(
|
|
29
|
+
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0)) __attribute__((visibility("hidden")))
|
|
32
30
|
@interface whisper_decoder_implOutput : NSObject<MLFeatureProvider>
|
|
33
31
|
|
|
34
|
-
///
|
|
35
|
-
@property (readwrite, nonatomic, strong) MLMultiArray *
|
|
32
|
+
/// cast_76 as multidimensional array of floats
|
|
33
|
+
@property (readwrite, nonatomic, strong) MLMultiArray * cast_76;
|
|
36
34
|
- (instancetype)init NS_UNAVAILABLE;
|
|
37
|
-
- (instancetype)
|
|
35
|
+
- (instancetype)initWithCast_76:(MLMultiArray *)cast_76 NS_DESIGNATED_INITIALIZER;
|
|
38
36
|
|
|
39
37
|
@end
|
|
40
38
|
|
|
41
|
-
|
|
42
39
|
/// Class for model loading and prediction
|
|
43
|
-
API_AVAILABLE(macos(
|
|
40
|
+
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0)) __attribute__((visibility("hidden")))
|
|
44
41
|
@interface whisper_decoder_impl : NSObject
|
|
45
42
|
@property (readonly, nonatomic, nullable) MLModel * model;
|
|
46
43
|
|
|
@@ -94,7 +91,7 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
94
91
|
@param configuration The model configuration
|
|
95
92
|
@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
93
|
*/
|
|
97
|
-
+ (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler;
|
|
94
|
+
+ (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0)) __attribute__((visibility("hidden")));
|
|
98
95
|
|
|
99
96
|
/**
|
|
100
97
|
Construct whisper_decoder_impl instance asynchronously with URL of .mlmodelc directory and optional configuration.
|
|
@@ -105,7 +102,7 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
105
102
|
@param configuration The model configuration
|
|
106
103
|
@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
104
|
*/
|
|
108
|
-
+ (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler;
|
|
105
|
+
+ (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_decoder_impl * _Nullable model, NSError * _Nullable error))handler API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0)) __attribute__((visibility("hidden")));
|
|
109
106
|
|
|
110
107
|
/**
|
|
111
108
|
Make a prediction using the standard interface
|
|
@@ -124,10 +121,25 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
124
121
|
*/
|
|
125
122
|
- (nullable whisper_decoder_implOutput *)predictionFromFeatures:(whisper_decoder_implInput *)input options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error;
|
|
126
123
|
|
|
124
|
+
/**
|
|
125
|
+
Make an asynchronous prediction using the standard interface
|
|
126
|
+
@param input an instance of whisper_decoder_implInput to predict from
|
|
127
|
+
@param completionHandler a block that will be called upon completion of the prediction. error will be nil if no error occurred.
|
|
128
|
+
*/
|
|
129
|
+
- (void)predictionFromFeatures:(whisper_decoder_implInput *)input completionHandler:(void (^)(whisper_decoder_implOutput * _Nullable output, NSError * _Nullable error))completionHandler API_AVAILABLE(macos(14.0), ios(17.0), watchos(10.0), tvos(17.0)) __attribute__((visibility("hidden")));
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
Make an asynchronous prediction using the standard interface
|
|
133
|
+
@param input an instance of whisper_decoder_implInput to predict from
|
|
134
|
+
@param options prediction options
|
|
135
|
+
@param completionHandler a block that will be called upon completion of the prediction. error will be nil if no error occurred.
|
|
136
|
+
*/
|
|
137
|
+
- (void)predictionFromFeatures:(whisper_decoder_implInput *)input options:(MLPredictionOptions *)options completionHandler:(void (^)(whisper_decoder_implOutput * _Nullable output, NSError * _Nullable error))completionHandler API_AVAILABLE(macos(14.0), ios(17.0), watchos(10.0), tvos(17.0)) __attribute__((visibility("hidden")));
|
|
138
|
+
|
|
127
139
|
/**
|
|
128
140
|
Make a prediction using the convenience interface
|
|
129
|
-
@param token_data
|
|
130
|
-
@param audio_data
|
|
141
|
+
@param token_data 1 by 1 matrix of floats
|
|
142
|
+
@param audio_data 1 × 1500 × 384 3-dimensional array of floats
|
|
131
143
|
@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
144
|
@return the prediction as whisper_decoder_implOutput
|
|
133
145
|
*/
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
|
|
9
9
|
#endif
|
|
10
10
|
|
|
11
|
+
#import "whisper-compat.h"
|
|
11
12
|
#import "whisper-decoder-impl.h"
|
|
12
13
|
|
|
13
14
|
@implementation whisper_decoder_implInput
|
|
@@ -39,21 +40,21 @@
|
|
|
39
40
|
|
|
40
41
|
@implementation whisper_decoder_implOutput
|
|
41
42
|
|
|
42
|
-
- (instancetype)
|
|
43
|
+
- (instancetype)initWithCast_76:(MLMultiArray *)cast_76 {
|
|
43
44
|
self = [super init];
|
|
44
45
|
if (self) {
|
|
45
|
-
|
|
46
|
+
_cast_76 = cast_76;
|
|
46
47
|
}
|
|
47
48
|
return self;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
- (NSSet<NSString *> *)featureNames {
|
|
51
|
-
return [NSSet setWithArray:@[@"
|
|
52
|
+
return [NSSet setWithArray:@[@"cast_76"]];
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
- (nullable MLFeatureValue *)featureValueForName:(NSString *)featureName {
|
|
55
|
-
if ([featureName isEqualToString:@"
|
|
56
|
-
return [MLFeatureValue featureValueWithMultiArray:self.
|
|
56
|
+
if ([featureName isEqualToString:@"cast_76"]) {
|
|
57
|
+
return [MLFeatureValue featureValueWithMultiArray:self.cast_76];
|
|
57
58
|
}
|
|
58
59
|
return nil;
|
|
59
60
|
}
|
|
@@ -80,10 +81,13 @@
|
|
|
80
81
|
Such application may want to use `-[MLModel initWithContentsOfURL:configuration:error:]` and `+URLOfModelInThisBundle` to create a MLModel object to pass-in.
|
|
81
82
|
*/
|
|
82
83
|
- (instancetype)initWithMLModel:(MLModel *)model {
|
|
84
|
+
if (model == nil) {
|
|
85
|
+
return nil;
|
|
86
|
+
}
|
|
83
87
|
self = [super init];
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
if (self != nil) {
|
|
89
|
+
_model = model;
|
|
90
|
+
}
|
|
87
91
|
return self;
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -177,7 +181,29 @@
|
|
|
177
181
|
- (nullable whisper_decoder_implOutput *)predictionFromFeatures:(whisper_decoder_implInput *)input options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error {
|
|
178
182
|
id<MLFeatureProvider> outFeatures = [self.model predictionFromFeatures:input options:options error:error];
|
|
179
183
|
if (!outFeatures) { return nil; }
|
|
180
|
-
return [[whisper_decoder_implOutput alloc]
|
|
184
|
+
return [[whisper_decoder_implOutput alloc] initWithCast_76:(MLMultiArray *)[outFeatures featureValueForName:@"cast_76"].multiArrayValue];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
- (void)predictionFromFeatures:(whisper_decoder_implInput *)input completionHandler:(void (^)(whisper_decoder_implOutput * _Nullable output, NSError * _Nullable error))completionHandler {
|
|
188
|
+
[self.model predictionFromFeatures:input completionHandler:^(id<MLFeatureProvider> prediction, NSError *predictionError) {
|
|
189
|
+
if (prediction != nil) {
|
|
190
|
+
whisper_decoder_implOutput *output = [[whisper_decoder_implOutput alloc] initWithCast_76:(MLMultiArray *)[prediction featureValueForName:@"cast_76"].multiArrayValue];
|
|
191
|
+
completionHandler(output, predictionError);
|
|
192
|
+
} else {
|
|
193
|
+
completionHandler(nil, predictionError);
|
|
194
|
+
}
|
|
195
|
+
}];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
- (void)predictionFromFeatures:(whisper_decoder_implInput *)input options:(MLPredictionOptions *)options completionHandler:(void (^)(whisper_decoder_implOutput * _Nullable output, NSError * _Nullable error))completionHandler {
|
|
199
|
+
[self.model predictionFromFeatures:input options:options completionHandler:^(id<MLFeatureProvider> prediction, NSError *predictionError) {
|
|
200
|
+
if (prediction != nil) {
|
|
201
|
+
whisper_decoder_implOutput *output = [[whisper_decoder_implOutput alloc] initWithCast_76:(MLMultiArray *)[prediction featureValueForName:@"cast_76"].multiArrayValue];
|
|
202
|
+
completionHandler(output, predictionError);
|
|
203
|
+
} else {
|
|
204
|
+
completionHandler(nil, predictionError);
|
|
205
|
+
}
|
|
206
|
+
}];
|
|
181
207
|
}
|
|
182
208
|
|
|
183
209
|
- (nullable whisper_decoder_implOutput *)predictionFromToken_data:(MLMultiArray *)token_data audio_data:(MLMultiArray *)audio_data error:(NSError * _Nullable __autoreleasing * _Nullable)error {
|
|
@@ -192,7 +218,7 @@
|
|
|
192
218
|
NSMutableArray<whisper_decoder_implOutput*> *results = [NSMutableArray arrayWithCapacity:(NSUInteger)outBatch.count];
|
|
193
219
|
for (NSInteger i = 0; i < outBatch.count; i++) {
|
|
194
220
|
id<MLFeatureProvider> resultProvider = [outBatch featuresAtIndex:i];
|
|
195
|
-
whisper_decoder_implOutput * result = [[whisper_decoder_implOutput alloc]
|
|
221
|
+
whisper_decoder_implOutput * result = [[whisper_decoder_implOutput alloc] initWithCast_76:(MLMultiArray *)[resultProvider featureValueForName:@"cast_76"].multiArrayValue];
|
|
196
222
|
[results addObject:result];
|
|
197
223
|
}
|
|
198
224
|
return results;
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
NS_ASSUME_NONNULL_BEGIN
|
|
13
13
|
|
|
14
|
-
|
|
15
14
|
/// Model Prediction Input Type
|
|
16
|
-
API_AVAILABLE(macos(
|
|
15
|
+
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0)) __attribute__((visibility("hidden")))
|
|
17
16
|
@interface whisper_encoder_implInput : NSObject<MLFeatureProvider>
|
|
18
17
|
|
|
19
18
|
/// logmel_data as 1 × 80 × 3000 3-dimensional array of floats
|
|
@@ -23,9 +22,8 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
23
22
|
|
|
24
23
|
@end
|
|
25
24
|
|
|
26
|
-
|
|
27
25
|
/// Model Prediction Output Type
|
|
28
|
-
API_AVAILABLE(macos(
|
|
26
|
+
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0)) __attribute__((visibility("hidden")))
|
|
29
27
|
@interface whisper_encoder_implOutput : NSObject<MLFeatureProvider>
|
|
30
28
|
|
|
31
29
|
/// output as multidimensional array of floats
|
|
@@ -35,9 +33,8 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
35
33
|
|
|
36
34
|
@end
|
|
37
35
|
|
|
38
|
-
|
|
39
36
|
/// Class for model loading and prediction
|
|
40
|
-
API_AVAILABLE(macos(
|
|
37
|
+
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0)) __attribute__((visibility("hidden")))
|
|
41
38
|
@interface whisper_encoder_impl : NSObject
|
|
42
39
|
@property (readonly, nonatomic, nullable) MLModel * model;
|
|
43
40
|
|
|
@@ -91,7 +88,7 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
91
88
|
@param configuration The model configuration
|
|
92
89
|
@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
90
|
*/
|
|
94
|
-
+ (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_encoder_impl * _Nullable model, NSError * _Nullable error))handler;
|
|
91
|
+
+ (void)loadWithConfiguration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_encoder_impl * _Nullable model, NSError * _Nullable error))handler API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0)) __attribute__((visibility("hidden")));
|
|
95
92
|
|
|
96
93
|
/**
|
|
97
94
|
Construct whisper_encoder_impl instance asynchronously with URL of .mlmodelc directory and optional configuration.
|
|
@@ -102,7 +99,7 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
102
99
|
@param configuration The model configuration
|
|
103
100
|
@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
101
|
*/
|
|
105
|
-
+ (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_encoder_impl * _Nullable model, NSError * _Nullable error))handler;
|
|
102
|
+
+ (void)loadContentsOfURL:(NSURL *)modelURL configuration:(MLModelConfiguration *)configuration completionHandler:(void (^)(whisper_encoder_impl * _Nullable model, NSError * _Nullable error))handler API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0)) __attribute__((visibility("hidden")));
|
|
106
103
|
|
|
107
104
|
/**
|
|
108
105
|
Make a prediction using the standard interface
|
|
@@ -121,9 +118,24 @@ API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0)) __attribute__((v
|
|
|
121
118
|
*/
|
|
122
119
|
- (nullable whisper_encoder_implOutput *)predictionFromFeatures:(whisper_encoder_implInput *)input options:(MLPredictionOptions *)options error:(NSError * _Nullable __autoreleasing * _Nullable)error;
|
|
123
120
|
|
|
121
|
+
/**
|
|
122
|
+
Make an asynchronous prediction using the standard interface
|
|
123
|
+
@param input an instance of whisper_encoder_implInput to predict from
|
|
124
|
+
@param completionHandler a block that will be called upon completion of the prediction. error will be nil if no error occurred.
|
|
125
|
+
*/
|
|
126
|
+
- (void)predictionFromFeatures:(whisper_encoder_implInput *)input completionHandler:(void (^)(whisper_encoder_implOutput * _Nullable output, NSError * _Nullable error))completionHandler API_AVAILABLE(macos(14.0), ios(17.0), watchos(10.0), tvos(17.0)) __attribute__((visibility("hidden")));
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
Make an asynchronous prediction using the standard interface
|
|
130
|
+
@param input an instance of whisper_encoder_implInput to predict from
|
|
131
|
+
@param options prediction options
|
|
132
|
+
@param completionHandler a block that will be called upon completion of the prediction. error will be nil if no error occurred.
|
|
133
|
+
*/
|
|
134
|
+
- (void)predictionFromFeatures:(whisper_encoder_implInput *)input options:(MLPredictionOptions *)options completionHandler:(void (^)(whisper_encoder_implOutput * _Nullable output, NSError * _Nullable error))completionHandler API_AVAILABLE(macos(14.0), ios(17.0), watchos(10.0), tvos(17.0)) __attribute__((visibility("hidden")));
|
|
135
|
+
|
|
124
136
|
/**
|
|
125
137
|
Make a prediction using the convenience interface
|
|
126
|
-
@param logmel_data
|
|
138
|
+
@param logmel_data 1 × 80 × 3000 3-dimensional array of floats
|
|
127
139
|
@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
140
|
@return the prediction as whisper_encoder_implOutput
|
|
129
141
|
*/
|