whisper.rn 0.4.0-rc.8 → 0.4.0-rc.9

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 (53) hide show
  1. package/android/src/main/CMakeLists.txt +2 -1
  2. package/android/src/main/java/com/rnwhisper/AudioUtils.java +27 -12
  3. package/android/src/main/java/com/rnwhisper/RNWhisper.java +75 -34
  4. package/android/src/main/java/com/rnwhisper/WhisperContext.java +20 -3
  5. package/android/src/main/jni.cpp +29 -1
  6. package/android/src/newarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
  7. package/android/src/oldarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
  8. package/cpp/ggml-aarch64.c +3209 -0
  9. package/cpp/ggml-aarch64.h +39 -0
  10. package/cpp/ggml-alloc.c +725 -517
  11. package/cpp/ggml-alloc.h +47 -65
  12. package/cpp/ggml-backend-impl.h +166 -55
  13. package/cpp/ggml-backend.cpp +2635 -0
  14. package/cpp/ggml-backend.h +202 -85
  15. package/cpp/ggml-common.h +1853 -0
  16. package/cpp/ggml-cpu-impl.h +614 -0
  17. package/cpp/ggml-impl.h +143 -180
  18. package/cpp/ggml-metal.h +13 -11
  19. package/cpp/ggml-metal.m +2955 -1632
  20. package/cpp/ggml-quants.c +9824 -3263
  21. package/cpp/ggml-quants.h +133 -248
  22. package/cpp/ggml-whisper.metallib +0 -0
  23. package/cpp/ggml.c +8482 -5142
  24. package/cpp/ggml.h +633 -349
  25. package/cpp/rn-whisper.cpp +91 -0
  26. package/cpp/rn-whisper.h +2 -0
  27. package/cpp/whisper.cpp +1427 -658
  28. package/cpp/whisper.h +84 -28
  29. package/ios/RNWhisper.mm +124 -37
  30. package/ios/RNWhisperAudioUtils.h +1 -0
  31. package/ios/RNWhisperAudioUtils.m +20 -13
  32. package/ios/RNWhisperContext.h +3 -2
  33. package/ios/RNWhisperContext.mm +39 -7
  34. package/jest/mock.js +9 -1
  35. package/lib/commonjs/NativeRNWhisper.js.map +1 -1
  36. package/lib/commonjs/index.js +48 -19
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/version.json +1 -1
  39. package/lib/module/NativeRNWhisper.js.map +1 -1
  40. package/lib/module/index.js +48 -19
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/version.json +1 -1
  43. package/lib/typescript/NativeRNWhisper.d.ts +6 -3
  44. package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
  45. package/lib/typescript/index.d.ts +25 -3
  46. package/lib/typescript/index.d.ts.map +1 -1
  47. package/package.json +6 -5
  48. package/src/NativeRNWhisper.ts +12 -3
  49. package/src/index.ts +63 -24
  50. package/src/version.json +1 -1
  51. package/whisper-rn.podspec +9 -2
  52. package/cpp/ggml-backend.c +0 -1718
  53. package/cpp/ggml-metal-whisper.metal +0 -5820
@@ -8,6 +8,97 @@
8
8
 
9
9
  namespace rnwhisper {
10
10
 
11
+ const char * system_info(void) {
12
+ static std::string s;
13
+ s = "";
14
+ if (wsp_ggml_cpu_has_avx() == 1) s += "AVX ";
15
+ if (wsp_ggml_cpu_has_avx2() == 1) s += "AVX2 ";
16
+ if (wsp_ggml_cpu_has_avx512() == 1) s += "AVX512 ";
17
+ if (wsp_ggml_cpu_has_fma() == 1) s += "FMA ";
18
+ if (wsp_ggml_cpu_has_neon() == 1) s += "NEON ";
19
+ if (wsp_ggml_cpu_has_arm_fma() == 1) s += "ARM_FMA ";
20
+ if (wsp_ggml_cpu_has_metal() == 1) s += "METAL ";
21
+ if (wsp_ggml_cpu_has_f16c() == 1) s += "F16C ";
22
+ if (wsp_ggml_cpu_has_fp16_va() == 1) s += "FP16_VA ";
23
+ if (wsp_ggml_cpu_has_blas() == 1) s += "BLAS ";
24
+ if (wsp_ggml_cpu_has_sse3() == 1) s += "SSE3 ";
25
+ if (wsp_ggml_cpu_has_ssse3() == 1) s += "SSSE3 ";
26
+ if (wsp_ggml_cpu_has_vsx() == 1) s += "VSX ";
27
+ #ifdef WHISPER_USE_COREML
28
+ s += "COREML ";
29
+ #endif
30
+ s.erase(s.find_last_not_of(" ") + 1);
31
+ return s.c_str();
32
+ }
33
+
34
+ std::string bench(struct whisper_context * ctx, int n_threads) {
35
+ const int n_mels = whisper_model_n_mels(ctx);
36
+
37
+ if (int ret = whisper_set_mel(ctx, nullptr, 0, n_mels)) {
38
+ return "error: failed to set mel: " + std::to_string(ret);
39
+ }
40
+ // heat encoder
41
+ if (int ret = whisper_encode(ctx, 0, n_threads) != 0) {
42
+ return "error: failed to encode: " + std::to_string(ret);
43
+ }
44
+
45
+ whisper_token tokens[512];
46
+ memset(tokens, 0, sizeof(tokens));
47
+
48
+ // prompt heat
49
+ if (int ret = whisper_decode(ctx, tokens, 256, 0, n_threads) != 0) {
50
+ return "error: failed to decode: " + std::to_string(ret);
51
+ }
52
+
53
+ // text-generation heat
54
+ if (int ret = whisper_decode(ctx, tokens, 1, 256, n_threads) != 0) {
55
+ return "error: failed to decode: " + std::to_string(ret);
56
+ }
57
+
58
+ whisper_reset_timings(ctx);
59
+
60
+ // actual run
61
+ if (int ret = whisper_encode(ctx, 0, n_threads) != 0) {
62
+ return "error: failed to encode: " + std::to_string(ret);
63
+ }
64
+
65
+ // text-generation
66
+ for (int i = 0; i < 256; i++) {
67
+ if (int ret = whisper_decode(ctx, tokens, 1, i, n_threads) != 0) {
68
+ return "error: failed to decode: " + std::to_string(ret);
69
+ }
70
+ }
71
+
72
+ // batched decoding
73
+ for (int i = 0; i < 64; i++) {
74
+ if (int ret = whisper_decode(ctx, tokens, 5, 0, n_threads) != 0) {
75
+ return "error: failed to decode: " + std::to_string(ret);
76
+ }
77
+ }
78
+
79
+ // prompt processing
80
+ for (int i = 0; i < 16; i++) {
81
+ if (int ret = whisper_decode(ctx, tokens, 256, 0, n_threads) != 0) {
82
+ return "error: failed to decode: " + std::to_string(ret);
83
+ }
84
+ }
85
+
86
+ const struct whisper_timings * timings = whisper_get_timings(ctx);
87
+
88
+ const int32_t n_encode = std::max(1, timings->n_encode);
89
+ const int32_t n_decode = std::max(1, timings->n_decode);
90
+ const int32_t n_batchd = std::max(1, timings->n_batchd);
91
+ const int32_t n_prompt = std::max(1, timings->n_prompt);
92
+
93
+ return std::string("[") +
94
+ "\"" + system_info() + "\"," +
95
+ std::to_string(n_threads) + "," +
96
+ std::to_string(1e-3f * timings->t_encode_us / n_encode) + "," +
97
+ std::to_string(1e-3f * timings->t_decode_us / n_decode) + "," +
98
+ std::to_string(1e-3f * timings->t_batchd_us / n_batchd) + "," +
99
+ std::to_string(1e-3f * timings->t_prompt_us / n_prompt) + "]";
100
+ }
101
+
11
102
  void high_pass_filter(std::vector<float> & data, float cutoff, float sample_rate) {
12
103
  const float rc = 1.0f / (2.0f * M_PI * cutoff);
13
104
  const float dt = 1.0f / sample_rate;
package/cpp/rn-whisper.h CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  namespace rnwhisper {
11
11
 
12
+ std::string bench(whisper_context * ctx, int n_threads);
13
+
12
14
  struct vad_params {
13
15
  bool use_vad = false;
14
16
  float vad_thold = 0.6f;