whisper.rn 0.4.0-rc.7 → 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.
- package/android/src/main/CMakeLists.txt +2 -1
- package/android/src/main/java/com/rnwhisper/AudioUtils.java +27 -12
- package/android/src/main/java/com/rnwhisper/RNWhisper.java +75 -34
- package/android/src/main/java/com/rnwhisper/WhisperContext.java +20 -3
- package/android/src/main/jni.cpp +29 -1
- package/android/src/newarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
- package/android/src/oldarch/java/com/rnwhisper/RNWhisperModule.java +10 -0
- package/cpp/coreml/whisper-encoder.mm +1 -1
- package/cpp/ggml-aarch64.c +3209 -0
- package/cpp/ggml-aarch64.h +39 -0
- package/cpp/ggml-alloc.c +732 -494
- package/cpp/ggml-alloc.h +47 -63
- package/cpp/ggml-backend-impl.h +162 -47
- package/cpp/ggml-backend.cpp +2635 -0
- package/cpp/ggml-backend.h +216 -71
- package/cpp/ggml-common.h +1853 -0
- package/cpp/ggml-cpu-impl.h +614 -0
- package/cpp/ggml-impl.h +144 -178
- package/cpp/ggml-metal.h +14 -60
- package/cpp/ggml-metal.m +3437 -2097
- package/cpp/ggml-quants.c +12559 -4189
- package/cpp/ggml-quants.h +135 -212
- package/cpp/ggml-whisper.metallib +0 -0
- package/cpp/ggml.c +9029 -5219
- package/cpp/ggml.h +673 -338
- package/cpp/rn-whisper.cpp +91 -0
- package/cpp/rn-whisper.h +2 -0
- package/cpp/whisper.cpp +1476 -675
- package/cpp/whisper.h +84 -28
- package/ios/RNWhisper.mm +124 -37
- package/ios/RNWhisperAudioUtils.h +1 -0
- package/ios/RNWhisperAudioUtils.m +20 -13
- package/ios/RNWhisperContext.h +3 -2
- package/ios/RNWhisperContext.mm +41 -8
- package/jest/mock.js +9 -1
- package/lib/commonjs/NativeRNWhisper.js.map +1 -1
- package/lib/commonjs/index.js +48 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/NativeRNWhisper.js.map +1 -1
- package/lib/module/index.js +48 -19
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/NativeRNWhisper.d.ts +6 -3
- package/lib/typescript/NativeRNWhisper.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +25 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/NativeRNWhisper.ts +12 -3
- package/src/index.ts +63 -24
- package/src/version.json +1 -1
- package/whisper-rn.podspec +9 -2
- package/cpp/ggml-backend.c +0 -1357
- package/cpp/ggml-metal-whisper.metal +0 -4908
package/cpp/rn-whisper.cpp
CHANGED
|
@@ -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;
|