whisper.rn 0.4.0-rc.8 → 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.
Files changed (201) hide show
  1. package/README.md +5 -1
  2. package/android/build.gradle +12 -3
  3. package/android/src/main/CMakeLists.txt +44 -13
  4. package/android/src/main/java/com/rnwhisper/AudioUtils.java +27 -12
  5. package/android/src/main/java/com/rnwhisper/RNWhisper.java +75 -34
  6. package/android/src/main/java/com/rnwhisper/WhisperContext.java +53 -38
  7. package/android/src/main/jni.cpp +38 -1
  8. package/android/src/main/jniLibs/arm64-v8a/librnwhisper.so +0 -0
  9. package/android/src/main/jniLibs/arm64-v8a/librnwhisper_v8fp16_va_2.so +0 -0
  10. package/android/src/main/jniLibs/armeabi-v7a/librnwhisper.so +0 -0
  11. package/android/src/main/jniLibs/armeabi-v7a/librnwhisper_vfpv4.so +0 -0
  12. package/android/src/main/jniLibs/x86_64/librnwhisper.so +0 -0
  13. package/android/src/main/jniLibs/x86_64/librnwhisper_x86_64.so +0 -0
  14. package/android/src/newarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
  15. package/android/src/oldarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
  16. package/cpp/coreml/whisper-compat.h +10 -0
  17. package/cpp/coreml/whisper-compat.m +35 -0
  18. package/cpp/coreml/whisper-decoder-impl.h +27 -15
  19. package/cpp/coreml/whisper-decoder-impl.m +36 -10
  20. package/cpp/coreml/whisper-encoder-impl.h +21 -9
  21. package/cpp/coreml/whisper-encoder-impl.m +29 -3
  22. package/cpp/ggml-alloc.c +727 -517
  23. package/cpp/ggml-alloc.h +47 -65
  24. package/cpp/ggml-backend-impl.h +196 -57
  25. package/cpp/ggml-backend-reg.cpp +591 -0
  26. package/cpp/ggml-backend.cpp +2016 -0
  27. package/cpp/ggml-backend.h +234 -89
  28. package/cpp/ggml-common.h +1861 -0
  29. package/cpp/ggml-cpp.h +39 -0
  30. package/cpp/ggml-cpu/amx/amx.cpp +221 -0
  31. package/cpp/ggml-cpu/amx/amx.h +8 -0
  32. package/cpp/ggml-cpu/amx/common.h +91 -0
  33. package/cpp/ggml-cpu/amx/mmq.cpp +2511 -0
  34. package/cpp/ggml-cpu/amx/mmq.h +10 -0
  35. package/cpp/ggml-cpu/arch/arm/cpu-feats.cpp +94 -0
  36. package/cpp/ggml-cpu/arch/arm/quants.c +4113 -0
  37. package/cpp/ggml-cpu/arch/arm/repack.cpp +2162 -0
  38. package/cpp/ggml-cpu/arch/x86/cpu-feats.cpp +327 -0
  39. package/cpp/ggml-cpu/arch/x86/quants.c +4310 -0
  40. package/cpp/ggml-cpu/arch/x86/repack.cpp +3284 -0
  41. package/cpp/ggml-cpu/arch-fallback.h +184 -0
  42. package/cpp/ggml-cpu/binary-ops.cpp +158 -0
  43. package/cpp/ggml-cpu/binary-ops.h +16 -0
  44. package/cpp/ggml-cpu/common.h +72 -0
  45. package/cpp/ggml-cpu/ggml-cpu-impl.h +511 -0
  46. package/cpp/ggml-cpu/ggml-cpu.c +3473 -0
  47. package/cpp/ggml-cpu/ggml-cpu.cpp +671 -0
  48. package/cpp/ggml-cpu/ops.cpp +9085 -0
  49. package/cpp/ggml-cpu/ops.h +111 -0
  50. package/cpp/ggml-cpu/quants.c +1157 -0
  51. package/cpp/ggml-cpu/quants.h +89 -0
  52. package/cpp/ggml-cpu/repack.cpp +1570 -0
  53. package/cpp/ggml-cpu/repack.h +98 -0
  54. package/cpp/ggml-cpu/simd-mappings.h +1006 -0
  55. package/cpp/ggml-cpu/traits.cpp +36 -0
  56. package/cpp/ggml-cpu/traits.h +38 -0
  57. package/cpp/ggml-cpu/unary-ops.cpp +186 -0
  58. package/cpp/ggml-cpu/unary-ops.h +28 -0
  59. package/cpp/ggml-cpu/vec.cpp +321 -0
  60. package/cpp/ggml-cpu/vec.h +973 -0
  61. package/cpp/ggml-cpu.h +143 -0
  62. package/cpp/ggml-impl.h +525 -168
  63. package/cpp/ggml-metal-impl.h +622 -0
  64. package/cpp/ggml-metal.h +16 -14
  65. package/cpp/ggml-metal.m +5289 -1859
  66. package/cpp/ggml-opt.cpp +1037 -0
  67. package/cpp/ggml-opt.h +237 -0
  68. package/cpp/ggml-quants.c +2916 -6877
  69. package/cpp/ggml-quants.h +87 -249
  70. package/cpp/ggml-threading.cpp +12 -0
  71. package/cpp/ggml-threading.h +14 -0
  72. package/cpp/ggml-whisper-sim.metallib +0 -0
  73. package/cpp/ggml-whisper.metallib +0 -0
  74. package/cpp/ggml.c +3293 -16770
  75. package/cpp/ggml.h +778 -835
  76. package/cpp/gguf.cpp +1347 -0
  77. package/cpp/gguf.h +202 -0
  78. package/cpp/rn-whisper.cpp +84 -0
  79. package/cpp/rn-whisper.h +2 -0
  80. package/cpp/whisper-arch.h +197 -0
  81. package/cpp/whisper.cpp +3240 -944
  82. package/cpp/whisper.h +144 -31
  83. package/ios/CMakeLists.txt +95 -0
  84. package/ios/RNWhisper.h +5 -0
  85. package/ios/RNWhisper.mm +124 -37
  86. package/ios/RNWhisperAudioUtils.h +1 -0
  87. package/ios/RNWhisperAudioUtils.m +24 -13
  88. package/ios/RNWhisperContext.h +8 -2
  89. package/ios/RNWhisperContext.mm +42 -8
  90. package/ios/rnwhisper.xcframework/Info.plist +74 -0
  91. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
  92. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
  93. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-backend.h +354 -0
  94. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-common.h +1861 -0
  95. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
  96. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
  97. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-impl.h +603 -0
  98. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
  99. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-metal.h +66 -0
  100. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-opt.h +237 -0
  101. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-quants.h +100 -0
  102. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml-threading.h +14 -0
  103. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/ggml.h +2221 -0
  104. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/gguf.h +202 -0
  105. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
  106. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
  107. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/rn-whisper.h +52 -0
  108. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper-arch.h +197 -0
  109. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Headers/whisper.h +739 -0
  110. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/Info.plist +0 -0
  111. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/ggml-whisper.metallib +0 -0
  112. package/ios/rnwhisper.xcframework/ios-arm64/rnwhisper.framework/rnwhisper +0 -0
  113. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
  114. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
  115. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +354 -0
  116. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-common.h +1861 -0
  117. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
  118. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
  119. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +603 -0
  120. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
  121. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +66 -0
  122. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-opt.h +237 -0
  123. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-quants.h +100 -0
  124. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-threading.h +14 -0
  125. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +2221 -0
  126. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/gguf.h +202 -0
  127. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
  128. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
  129. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +52 -0
  130. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper-arch.h +197 -0
  131. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +739 -0
  132. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
  133. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +101 -0
  134. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/ggml-whisper-sim.metallib +0 -0
  135. package/ios/rnwhisper.xcframework/ios-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
  136. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
  137. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
  138. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-backend.h +354 -0
  139. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-common.h +1861 -0
  140. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
  141. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
  142. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-impl.h +603 -0
  143. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
  144. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-metal.h +66 -0
  145. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-opt.h +237 -0
  146. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-quants.h +100 -0
  147. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml-threading.h +14 -0
  148. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/ggml.h +2221 -0
  149. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/gguf.h +202 -0
  150. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
  151. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
  152. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/rn-whisper.h +52 -0
  153. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper-arch.h +197 -0
  154. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Headers/whisper.h +739 -0
  155. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/Info.plist +0 -0
  156. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/ggml-whisper.metallib +0 -0
  157. package/ios/rnwhisper.xcframework/tvos-arm64/rnwhisper.framework/rnwhisper +0 -0
  158. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-alloc.h +76 -0
  159. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend-impl.h +255 -0
  160. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-backend.h +354 -0
  161. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-common.h +1861 -0
  162. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpp.h +39 -0
  163. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-cpu.h +143 -0
  164. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-impl.h +603 -0
  165. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal-impl.h +622 -0
  166. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-metal.h +66 -0
  167. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-opt.h +237 -0
  168. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-quants.h +100 -0
  169. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml-threading.h +14 -0
  170. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/ggml.h +2221 -0
  171. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/gguf.h +202 -0
  172. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-audioutils.h +14 -0
  173. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper-log.h +11 -0
  174. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/rn-whisper.h +52 -0
  175. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper-arch.h +197 -0
  176. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Headers/whisper.h +739 -0
  177. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/Info.plist +0 -0
  178. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/_CodeSignature/CodeResources +101 -0
  179. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/ggml-whisper-sim.metallib +0 -0
  180. package/ios/rnwhisper.xcframework/tvos-arm64_x86_64-simulator/rnwhisper.framework/rnwhisper +0 -0
  181. package/jest/mock.js +14 -1
  182. package/lib/commonjs/NativeRNWhisper.js.map +1 -1
  183. package/lib/commonjs/index.js +48 -19
  184. package/lib/commonjs/index.js.map +1 -1
  185. package/lib/commonjs/version.json +1 -1
  186. package/lib/module/NativeRNWhisper.js.map +1 -1
  187. package/lib/module/index.js +48 -19
  188. package/lib/module/index.js.map +1 -1
  189. package/lib/module/version.json +1 -1
  190. package/lib/typescript/NativeRNWhisper.d.ts +6 -3
  191. package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
  192. package/lib/typescript/index.d.ts +25 -3
  193. package/lib/typescript/index.d.ts.map +1 -1
  194. package/package.json +15 -10
  195. package/src/NativeRNWhisper.ts +12 -3
  196. package/src/index.ts +63 -24
  197. package/src/version.json +1 -1
  198. package/whisper-rn.podspec +18 -18
  199. package/cpp/README.md +0 -4
  200. package/cpp/ggml-backend.c +0 -1718
  201. package/cpp/ggml-metal-whisper.metal +0 -5820
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
- For build, 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).
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
 
@@ -53,9 +53,18 @@ android {
53
53
  }
54
54
  }
55
55
  }
56
- externalNativeBuild {
57
- cmake {
58
- path = file('src/main/CMakeLists.txt')
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,15 +2,35 @@ cmake_minimum_required(VERSION 3.10)
2
2
 
3
3
  project(whisper.rn)
4
4
 
5
- set(CMAKE_CXX_STANDARD 11)
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
- ${RNWHISPER_LIB_DIR}/ggml-backend.c
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
33
+ ${RNWHISPER_LIB_DIR}/gguf.cpp
14
34
  ${RNWHISPER_LIB_DIR}/whisper.cpp
15
35
  ${RNWHISPER_LIB_DIR}/rn-audioutils.cpp
16
36
  ${RNWHISPER_LIB_DIR}/rn-whisper.cpp
@@ -19,45 +39,56 @@ set(
19
39
 
20
40
  find_library(LOG_LIB log)
21
41
 
22
- 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
+
23
50
  add_library(
24
51
  ${target_name}
25
52
  SHARED
26
53
  ${SOURCE_FILES}
54
+ ${SOURCE_FILES_ARCH}
27
55
  )
28
56
 
29
57
  target_link_libraries(${target_name} ${LOG_LIB} android)
30
58
 
31
- if (${target_name} STREQUAL "whisper_v8fp16_va")
32
- target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)
33
- elseif (${target_name} STREQUAL "whisper_vfpv4")
34
- 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)
35
61
  endif ()
36
62
 
63
+ target_compile_options(${target_name} PRIVATE -DWSP_GGML_USE_CPU -DWSP_GGML_USE_CPU_REPACK -pthread ${cpu_flags})
64
+
37
65
  if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
38
66
  target_compile_options(${target_name} PRIVATE -DRNWHISPER_ANDROID_ENABLE_LOGGING)
39
67
  endif ()
40
68
 
41
69
  # NOTE: If you want to debug the native code, you can uncomment if and endif
70
+ # Note that it will be extremely slow
42
71
  # if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
43
-
44
- target_compile_options(${target_name} PRIVATE -O3 -DNDEBUG -pthread)
72
+ target_compile_options(${target_name} PRIVATE -O3 -DNDEBUG)
45
73
  target_compile_options(${target_name} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
46
74
  target_compile_options(${target_name} PRIVATE -ffunction-sections -fdata-sections)
47
75
 
48
76
  target_link_options(${target_name} PRIVATE -Wl,--gc-sections)
49
77
  target_link_options(${target_name} PRIVATE -Wl,--exclude-libs,ALL)
50
78
  target_link_options(${target_name} PRIVATE -flto)
51
-
52
79
  # endif ()
53
80
  endfunction()
54
81
 
55
- build_library("whisper") # Default target
82
+ build_library("rnwhisper" "generic" "")
56
83
 
57
84
  if (${ANDROID_ABI} STREQUAL "arm64-v8a")
58
- build_library("whisper_v8fp16_va")
85
+ build_library("rnwhisper_v8fp16_va_2" "arm" "-march=armv8.2-a+fp16")
59
86
  elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
60
- build_library("whisper_vfpv4")
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")
61
91
  endif ()
62
92
 
93
+
63
94
  include_directories(${RNWHISPER_LIB_DIR})
@@ -2,8 +2,6 @@ package com.rnwhisper;
2
2
 
3
3
  import android.util.Log;
4
4
 
5
- import java.io.IOException;
6
- import java.io.FileReader;
7
5
  import java.io.ByteArrayOutputStream;
8
6
  import java.io.File;
9
7
  import java.io.IOException;
@@ -11,23 +9,22 @@ import java.io.InputStream;
11
9
  import java.nio.ByteBuffer;
12
10
  import java.nio.ByteOrder;
13
11
  import java.nio.ShortBuffer;
12
+ import java.util.Base64;
13
+
14
+ import java.util.Arrays;
14
15
 
15
16
  public class AudioUtils {
16
17
  private static final String NAME = "RNWhisperAudioUtils";
17
18
 
18
- public static float[] decodeWaveFile(InputStream inputStream) throws IOException {
19
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
20
- byte[] buffer = new byte[1024];
21
- int bytesRead;
22
- while ((bytesRead = inputStream.read(buffer)) != -1) {
23
- baos.write(buffer, 0, bytesRead);
24
- }
25
- ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray());
19
+ private static float[] bufferToFloatArray(byte[] buffer, Boolean cutHeader) {
20
+ ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
26
21
  byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
27
- byteBuffer.position(44);
28
22
  ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
29
23
  short[] shortArray = new short[shortBuffer.limit()];
30
24
  shortBuffer.get(shortArray);
25
+ if (cutHeader) {
26
+ shortArray = Arrays.copyOfRange(shortArray, 44, shortArray.length);
27
+ }
31
28
  float[] floatArray = new float[shortArray.length];
32
29
  for (int i = 0; i < shortArray.length; i++) {
33
30
  floatArray[i] = ((float) shortArray[i]) / 32767.0f;
@@ -36,4 +33,22 @@ public class AudioUtils {
36
33
  }
37
34
  return floatArray;
38
35
  }
39
- }
36
+
37
+ public static float[] decodeWaveFile(InputStream inputStream) throws IOException {
38
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
39
+ byte[] buffer = new byte[1024];
40
+ int bytesRead;
41
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
42
+ baos.write(buffer, 0, bytesRead);
43
+ }
44
+ return bufferToFloatArray(baos.toByteArray(), true);
45
+ }
46
+
47
+ public static float[] decodeWaveData(String dataBase64) throws IOException {
48
+ return bufferToFloatArray(Base64.getDecoder().decode(dataBase64), true);
49
+ }
50
+
51
+ public static float[] decodePcmData(String dataBase64) {
52
+ return bufferToFloatArray(Base64.getDecoder().decode(dataBase64), false);
53
+ }
54
+ }
@@ -19,6 +19,7 @@ import java.util.HashMap;
19
19
  import java.util.Random;
20
20
  import java.io.File;
21
21
  import java.io.FileInputStream;
22
+ import java.io.InputStream;
22
23
  import java.io.PushbackInputStream;
23
24
 
24
25
  public class RNWhisper implements LifecycleEventListener {
@@ -119,44 +120,16 @@ public class RNWhisper implements LifecycleEventListener {
119
120
  tasks.put(task, "initContext");
120
121
  }
121
122
 
122
- public void transcribeFile(double id, double jobId, String filePath, ReadableMap options, Promise promise) {
123
- final WhisperContext context = contexts.get((int) id);
124
- if (context == null) {
125
- promise.reject("Context not found");
126
- return;
127
- }
128
- if (context.isCapturing()) {
129
- promise.reject("The context is in realtime transcribe mode");
130
- return;
131
- }
132
- if (context.isTranscribing()) {
133
- promise.reject("Context is already transcribing");
134
- return;
135
- }
123
+ private AsyncTask transcribe(WhisperContext context, double jobId, final float[] audioData, final ReadableMap options, Promise promise) {
136
124
  AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
137
125
  private Exception exception;
138
126
 
139
127
  @Override
140
128
  protected WritableMap doInBackground(Void... voids) {
141
129
  try {
142
- String waveFilePath = filePath;
143
-
144
- if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
145
- waveFilePath = downloader.downloadFile(filePath);
146
- }
147
-
148
- int resId = getResourceIdentifier(waveFilePath);
149
- if (resId > 0) {
150
- return context.transcribeInputStream(
151
- (int) jobId,
152
- reactContext.getResources().openRawResource(resId),
153
- options
154
- );
155
- }
156
-
157
- return context.transcribeInputStream(
130
+ return context.transcribe(
158
131
  (int) jobId,
159
- new FileInputStream(new File(waveFilePath)),
132
+ audioData,
160
133
  options
161
134
  );
162
135
  } catch (Exception e) {
@@ -175,7 +148,66 @@ public class RNWhisper implements LifecycleEventListener {
175
148
  tasks.remove(this);
176
149
  }
177
150
  }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
178
- tasks.put(task, "transcribeFile-" + id);
151
+ return task;
152
+ }
153
+
154
+ public void transcribeFile(double id, double jobId, String filePathOrBase64, ReadableMap options, Promise promise) {
155
+ final WhisperContext context = contexts.get((int) id);
156
+ if (context == null) {
157
+ promise.reject("Context not found");
158
+ return;
159
+ }
160
+ if (context.isCapturing()) {
161
+ promise.reject("The context is in realtime transcribe mode");
162
+ return;
163
+ }
164
+ if (context.isTranscribing()) {
165
+ promise.reject("Context is already transcribing");
166
+ return;
167
+ }
168
+
169
+ String waveFilePath = filePathOrBase64;
170
+ try {
171
+ if (filePathOrBase64.startsWith("http://") || filePathOrBase64.startsWith("https://")) {
172
+ waveFilePath = downloader.downloadFile(filePathOrBase64);
173
+ }
174
+
175
+ float[] audioData;
176
+ int resId = getResourceIdentifier(waveFilePath);
177
+ if (resId > 0) {
178
+ audioData = AudioUtils.decodeWaveFile(reactContext.getResources().openRawResource(resId));
179
+ } else if (filePathOrBase64.startsWith("data:audio/wav;base64,")) {
180
+ audioData = AudioUtils.decodeWaveData(filePathOrBase64);
181
+ } else {
182
+ audioData = AudioUtils.decodeWaveFile(new FileInputStream(new File(waveFilePath)));
183
+ }
184
+
185
+ AsyncTask task = transcribe(context, jobId, audioData, options, promise);
186
+ tasks.put(task, "transcribeFile-" + id);
187
+ } catch (Exception e) {
188
+ promise.reject(e);
189
+ }
190
+ }
191
+
192
+ public void transcribeData(double id, double jobId, String dataBase64, ReadableMap options, Promise promise) {
193
+ final WhisperContext context = contexts.get((int) id);
194
+ if (context == null) {
195
+ promise.reject("Context not found");
196
+ return;
197
+ }
198
+ if (context.isCapturing()) {
199
+ promise.reject("The context is in realtime transcribe mode");
200
+ return;
201
+ }
202
+ if (context.isTranscribing()) {
203
+ promise.reject("Context is already transcribing");
204
+ return;
205
+ }
206
+
207
+ float[] audioData = AudioUtils.decodePcmData(dataBase64);
208
+ AsyncTask task = transcribe(context, jobId, audioData, options, promise);
209
+
210
+ tasks.put(task, "transcribeData-" + id);
179
211
  }
180
212
 
181
213
  public void startRealtimeTranscribe(double id, double jobId, ReadableMap options, Promise promise) {
@@ -211,7 +243,7 @@ public class RNWhisper implements LifecycleEventListener {
211
243
  context.stopTranscribe((int) jobId);
212
244
  AsyncTask completionTask = null;
213
245
  for (AsyncTask task : tasks.keySet()) {
214
- if (tasks.get(task).equals("transcribeFile-" + id)) {
246
+ if (tasks.get(task).equals("transcribeFile-" + id) || tasks.get(task).equals("transcribeData-" + id)) {
215
247
  task.get();
216
248
  break;
217
249
  }
@@ -235,6 +267,15 @@ public class RNWhisper implements LifecycleEventListener {
235
267
  tasks.put(task, "abortTranscribe-" + id);
236
268
  }
237
269
 
270
+ public void bench(double id, double nThreads, Promise promise) {
271
+ final WhisperContext context = contexts.get((int) id);
272
+ if (context == null) {
273
+ promise.reject("Context not found");
274
+ return;
275
+ }
276
+ promise.resolve(context.bench((int) nThreads));
277
+ }
278
+
238
279
  public void releaseContext(double id, Promise promise) {
239
280
  final int contextId = (int) id;
240
281
  AsyncTask task = new AsyncTask<Void, Void, Void>() {
@@ -250,7 +291,7 @@ public class RNWhisper implements LifecycleEventListener {
250
291
  context.stopCurrentTranscribe();
251
292
  AsyncTask completionTask = null;
252
293
  for (AsyncTask task : tasks.keySet()) {
253
- if (tasks.get(task).equals("transcribeFile-" + contextId)) {
294
+ if (tasks.get(task).equals("transcribeFile-" + contextId) || tasks.get(task).equals("transcribeData-" + contextId)) {
254
295
  task.get();
255
296
  break;
256
297
  }
@@ -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;
@@ -53,6 +55,7 @@ public class WhisperContext {
53
55
  private boolean isCapturing = false;
54
56
  private boolean isStoppedByAction = false;
55
57
  private boolean isTranscribing = false;
58
+ private boolean isTdrzEnable = false;
56
59
  private Thread rootFullHandler = null;
57
60
  private Thread fullHandler = null;
58
61
 
@@ -73,6 +76,7 @@ public class WhisperContext {
73
76
  isCapturing = false;
74
77
  isStoppedByAction = false;
75
78
  isTranscribing = false;
79
+ isTdrzEnable = false;
76
80
  rootFullHandler = null;
77
81
  fullHandler = null;
78
82
  }
@@ -113,6 +117,8 @@ public class WhisperContext {
113
117
  double realtimeAudioMinSec = options.hasKey("realtimeAudioMinSec") ? options.getDouble("realtimeAudioMinSec") : 0;
114
118
  final double audioMinSec = realtimeAudioMinSec > 0.5 && realtimeAudioMinSec <= audioSliceSec ? realtimeAudioMinSec : 1;
115
119
 
120
+ this.isTdrzEnable = options.hasKey("tdrzEnable") && options.getBoolean("tdrzEnable");
121
+
116
122
  createRealtimeTranscribeJob(jobId, context, options);
117
123
 
118
124
  sliceNSamples = new ArrayList<Integer>();
@@ -328,15 +334,15 @@ public class WhisperContext {
328
334
  }
329
335
  }
330
336
 
331
- public WritableMap transcribeInputStream(int jobId, InputStream inputStream, ReadableMap options) throws IOException, Exception {
337
+ public WritableMap transcribe(int jobId, float[] audioData, ReadableMap options) throws IOException, Exception {
332
338
  if (isCapturing || isTranscribing) {
333
339
  throw new Exception("Context is already in capturing or transcribing");
334
340
  }
335
341
  rewind();
336
-
337
342
  this.jobId = jobId;
343
+ this.isTdrzEnable = options.hasKey("tdrzEnable") && options.getBoolean("tdrzEnable");
344
+
338
345
  isTranscribing = true;
339
- float[] audioData = AudioUtils.decodeWaveFile(inputStream);
340
346
 
341
347
  boolean hasProgressCallback = options.hasKey("onProgress") && options.getBoolean("onProgress");
342
348
  boolean hasNewSegmentsCallback = options.hasKey("onNewSegments") && options.getBoolean("onNewSegments");
@@ -368,8 +374,15 @@ public class WhisperContext {
368
374
 
369
375
  WritableMap data = Arguments.createMap();
370
376
  WritableArray segments = Arguments.createArray();
377
+
371
378
  for (int i = 0; i < count; i++) {
372
379
  String text = getTextSegment(context, i);
380
+
381
+ // If tdrzEnable is enabled and speaker turn is detected
382
+ if (this.isTdrzEnable && getTextSegmentSpeakerTurnNext(context, i)) {
383
+ text += " [SPEAKER_TURN]";
384
+ }
385
+
373
386
  builder.append(text);
374
387
 
375
388
  WritableMap segment = Arguments.createMap();
@@ -411,6 +424,10 @@ public class WhisperContext {
411
424
  stopTranscribe(this.jobId);
412
425
  }
413
426
 
427
+ public String bench(int n_threads) {
428
+ return bench(context, n_threads);
429
+ }
430
+
414
431
  public void release() {
415
432
  stopCurrentTranscribe();
416
433
  freeContext(context);
@@ -418,64 +435,60 @@ public class WhisperContext {
418
435
 
419
436
  static {
420
437
  Log.d(NAME, "Primary ABI: " + Build.SUPPORTED_ABIS[0]);
421
- boolean loadVfpv4 = false;
422
- boolean loadV8fp16 = false;
423
- if (isArmeabiV7a()) {
424
- // armeabi-v7a needs runtime detection support
425
- String cpuInfo = cpuInfo();
426
- if (cpuInfo != null) {
427
- Log.d(NAME, "CPU info: " + cpuInfo);
428
- if (cpuInfo.contains("vfpv4")) {
429
- Log.d(NAME, "CPU supports vfpv4");
430
- loadVfpv4 = true;
431
- }
432
- }
433
- } else if (isArmeabiV8a()) {
434
- // ARMv8.2a needs runtime detection support
435
- String cpuInfo = cpuInfo();
436
- if (cpuInfo != null) {
437
- Log.d(NAME, "CPU info: " + cpuInfo);
438
- if (cpuInfo.contains("fphp")) {
439
- Log.d(NAME, "CPU supports fp16 arithmetic");
440
- loadV8fp16 = true;
441
- }
442
- }
443
- }
444
438
 
445
- if (loadVfpv4) {
446
- Log.d(NAME, "Loading libwhisper_vfpv4.so");
447
- System.loadLibrary("whisper_vfpv4");
448
- } else if (loadV8fp16) {
449
- Log.d(NAME, "Loading libwhisper_v8fp16_va.so");
450
- System.loadLibrary("whisper_v8fp16_va");
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";
451
458
  } else {
452
- Log.d(NAME, "Loading libwhisper.so");
453
- System.loadLibrary("whisper");
459
+ Log.d(NAME, "ARM32 is not supported, skipping loading library");
454
460
  }
455
461
  }
456
462
 
463
+ private static boolean isArm64V8a() {
464
+ return Build.SUPPORTED_ABIS[0].equals("arm64-v8a");
465
+ }
466
+
457
467
  private static boolean isArmeabiV7a() {
458
468
  return Build.SUPPORTED_ABIS[0].equals("armeabi-v7a");
459
469
  }
460
470
 
461
- private static boolean isArmeabiV8a() {
462
- return Build.SUPPORTED_ABIS[0].equals("arm64-v8a");
471
+ private static boolean isX86_64() {
472
+ return Build.SUPPORTED_ABIS[0].equals("x86_64");
463
473
  }
464
474
 
465
- private static String cpuInfo() {
475
+ private static String getCpuFeatures() {
466
476
  File file = new File("/proc/cpuinfo");
467
477
  StringBuilder stringBuilder = new StringBuilder();
468
478
  try {
469
479
  BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
470
480
  String line;
471
481
  while ((line = bufferedReader.readLine()) != null) {
482
+ if (line.startsWith("Features")) {
472
483
  stringBuilder.append(line);
484
+ break;
485
+ }
473
486
  }
474
487
  bufferedReader.close();
475
488
  return stringBuilder.toString();
476
489
  } catch (IOException e) {
477
490
  Log.w(NAME, "Couldn't read /proc/cpuinfo", e);
478
- return null;
491
+ return "";
479
492
  }
480
493
  }
481
494
 
@@ -499,6 +512,7 @@ public class WhisperContext {
499
512
  protected static native String getTextSegment(long context, int index);
500
513
  protected static native int getTextSegmentT0(long context, int index);
501
514
  protected static native int getTextSegmentT1(long context, int index);
515
+ protected static native boolean getTextSegmentSpeakerTurnNext(long context, int index);
502
516
 
503
517
  protected static native void createRealtimeTranscribeJob(
504
518
  int job_id,
@@ -514,4 +528,5 @@ public class WhisperContext {
514
528
  int slice_index,
515
529
  int n_samples
516
530
  );
531
+ protected static native String bench(long context, int n_threads);
517
532
  }
@@ -155,6 +155,11 @@ 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
160
+ cparams.dtw_token_timestamps = false;
161
+ // cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
162
+
158
163
  struct whisper_context *context = nullptr;
159
164
  const char *model_path_chars = env->GetStringUTFChars(model_path_str, nullptr);
160
165
  context = whisper_init_from_file_with_params(model_path_chars, cparams);
@@ -171,6 +176,11 @@ Java_com_rnwhisper_WhisperContext_initContextWithAsset(
171
176
  ) {
172
177
  UNUSED(thiz);
173
178
  struct whisper_context_params cparams;
179
+
180
+ // TODO: Expose dtw_token_timestamps and dtw_aheads_preset
181
+ cparams.dtw_token_timestamps = false;
182
+ // cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
183
+
174
184
  struct whisper_context *context = nullptr;
175
185
  const char *model_path_chars = env->GetStringUTFChars(model_path_str, nullptr);
176
186
  context = whisper_init_from_asset(env, asset_manager, model_path_chars, cparams);
@@ -186,6 +196,11 @@ Java_com_rnwhisper_WhisperContext_initContextWithInputStream(
186
196
  ) {
187
197
  UNUSED(thiz);
188
198
  struct whisper_context_params cparams;
199
+
200
+ // TODO: Expose dtw_token_timestamps and dtw_aheads_preset
201
+ cparams.dtw_token_timestamps = false;
202
+ // cparams.dtw_aheads_preset = WHISPER_AHEADS_BASE;
203
+
189
204
  struct whisper_context *context = nullptr;
190
205
  context = whisper_init_from_input_stream(env, input_stream, cparams);
191
206
  return reinterpret_cast<jlong>(context);
@@ -206,8 +221,8 @@ struct whisper_full_params createFullParams(JNIEnv *env, jobject options) {
206
221
  int n_threads = readablemap::getInt(env, options, "maxThreads", default_n_threads);
207
222
  params.n_threads = n_threads > 0 ? n_threads : default_n_threads;
208
223
  params.translate = readablemap::getBool(env, options, "translate", false);
209
- params.speed_up = readablemap::getBool(env, options, "speedUp", false);
210
224
  params.token_timestamps = readablemap::getBool(env, options, "tokenTimestamps", false);
225
+ params.tdrz_enable = readablemap::getBool(env, options, "tdrzEnable", false);
211
226
  params.offset_ms = 0;
212
227
  params.no_context = true;
213
228
  params.single_segment = false;
@@ -493,4 +508,26 @@ Java_com_rnwhisper_WhisperContext_freeContext(
493
508
  whisper_free(context);
494
509
  }
495
510
 
511
+ JNIEXPORT jboolean JNICALL
512
+ Java_com_rnwhisper_WhisperContext_getTextSegmentSpeakerTurnNext(
513
+ JNIEnv *env, jobject thiz, jlong context_ptr, jint index) {
514
+ UNUSED(env);
515
+ UNUSED(thiz);
516
+ struct whisper_context *context = reinterpret_cast<struct whisper_context *>(context_ptr);
517
+ return whisper_full_get_segment_speaker_turn_next(context, index);
518
+ }
519
+
520
+ JNIEXPORT jstring JNICALL
521
+ Java_com_rnwhisper_WhisperContext_bench(
522
+ JNIEnv *env,
523
+ jobject thiz,
524
+ jlong context_ptr,
525
+ jint n_threads
526
+ ) {
527
+ UNUSED(thiz);
528
+ struct whisper_context *context = reinterpret_cast<struct whisper_context *>(context_ptr);
529
+ std::string result = rnwhisper::bench(context, n_threads);
530
+ return env->NewStringUTF(result.c_str());
531
+ }
532
+
496
533
  } // extern "C"
@@ -47,6 +47,11 @@ public class RNWhisperModule extends NativeRNWhisperSpec {
47
47
  rnwhisper.transcribeFile(id, jobId, filePath, options, promise);
48
48
  }
49
49
 
50
+ @ReactMethod
51
+ public void transcribeData(double id, double jobId, String dataBase64, ReadableMap options, Promise promise) {
52
+ rnwhisper.transcribeData(id, jobId, dataBase64, options, promise);
53
+ }
54
+
50
55
  @ReactMethod
51
56
  public void startRealtimeTranscribe(double id, double jobId, ReadableMap options, Promise promise) {
52
57
  rnwhisper.startRealtimeTranscribe(id, jobId, options, promise);
@@ -57,6 +62,11 @@ public class RNWhisperModule extends NativeRNWhisperSpec {
57
62
  rnwhisper.abortTranscribe(contextId, jobId, promise);
58
63
  }
59
64
 
65
+ @ReactMethod
66
+ public void bench(double id, double nThreads, Promise promise) {
67
+ rnwhisper.bench(id, nThreads, promise);
68
+ }
69
+
60
70
  @ReactMethod
61
71
  public void releaseContext(double id, Promise promise) {
62
72
  rnwhisper.releaseContext(id, promise);