whisper.rn 0.3.0-rc.7 → 0.3.1

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 CHANGED
@@ -21,7 +21,11 @@ React Native binding of [whisper.cpp](https://github.com/ggerganov/whisper.cpp).
21
21
  npm install whisper.rn
22
22
  ```
23
23
 
24
- Then re-run `npx pod-install` again for iOS.
24
+ For iOS, please re-run `npx pod-install` again.
25
+
26
+ 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.
27
+
28
+ For Android, 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).
25
29
 
26
30
  For Expo, you will need to prebuild the project before using it. See [Expo guide](https://docs.expo.io/guides/using-libraries/#using-a-library-in-a-expo-project) for more details.
27
31
 
@@ -43,6 +47,9 @@ Add the following line to ```android/app/src/main/AndroidManifest.xml```
43
47
  ```xml
44
48
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
45
49
  ```
50
+ ## Tips & Tricks
51
+
52
+ The [Tips & Tricks](docs/TIPS.md) document is a collection of tips and tricks for using `whisper.rn`.
46
53
 
47
54
  ## Usage
48
55
 
@@ -119,7 +126,9 @@ module.exports = {
119
126
  }
120
127
  ```
121
128
 
122
- Please note that it will significantly increase the size of the app in release mode.
129
+ Please note that:
130
+ - It will significantly increase the size of the app in release mode.
131
+ - The RN packager is not allowed file size larger than 2GB, so it not able to use original f16 `large` model (2.9GB), you can use quantized models instead.
123
132
 
124
133
  ## Core ML support
125
134
 
@@ -189,7 +198,7 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
189
198
 
190
199
  ## Troubleshooting
191
200
 
192
- See the [troubleshooting](TROUBLESHOOTING.md) if you encounter any problem while using `whisper.rn`.
201
+ See the [troubleshooting](docs/TROUBLESHOOTING.md) if you encounter any problem while using `whisper.rn`.
193
202
 
194
203
  ## License
195
204
 
@@ -282,6 +282,26 @@ public class WhisperContext {
282
282
  eventEmitter.emit(eventName, event);
283
283
  }
284
284
 
285
+ private void emitProgress(int progress) {
286
+ WritableMap event = Arguments.createMap();
287
+ event.putInt("contextId", WhisperContext.this.id);
288
+ event.putInt("jobId", jobId);
289
+ event.putInt("progress", progress);
290
+ eventEmitter.emit("@RNWhisper_onTranscribeProgress", event);
291
+ }
292
+
293
+ private static class ProgressCallback {
294
+ WhisperContext context;
295
+
296
+ public ProgressCallback(WhisperContext context) {
297
+ this.context = context;
298
+ }
299
+
300
+ void onProgress(int progress) {
301
+ context.emitProgress(progress);
302
+ }
303
+ }
304
+
285
305
  public WritableMap transcribeInputStream(int jobId, InputStream inputStream, ReadableMap options) throws IOException, Exception {
286
306
  this.jobId = jobId;
287
307
  isTranscribing = true;
@@ -334,7 +354,9 @@ public class WhisperContext {
334
354
  // jstring language,
335
355
  options.hasKey("language") ? options.getString("language") : "auto",
336
356
  // jstring prompt
337
- options.hasKey("prompt") ? options.getString("prompt") : null
357
+ options.hasKey("prompt") ? options.getString("prompt") : null,
358
+ // ProgressCallback progressCallback
359
+ options.hasKey("onProgress") && options.getBoolean("onProgress") ? new ProgressCallback(this) : null
338
360
  );
339
361
  }
340
362
 
@@ -469,6 +491,7 @@ public class WhisperContext {
469
491
  }
470
492
  }
471
493
 
494
+
472
495
  protected static native long initContext(String modelPath);
473
496
  protected static native long initContextWithAsset(AssetManager assetManager, String modelPath);
474
497
  protected static native long initContextWithInputStream(PushbackInputStream inputStream);
@@ -491,7 +514,8 @@ public class WhisperContext {
491
514
  boolean speed_up,
492
515
  boolean translate,
493
516
  String language,
494
- String prompt
517
+ String prompt,
518
+ ProgressCallback progressCallback
495
519
  );
496
520
  protected static native void abortTranscribe(int jobId);
497
521
  protected static native void abortAllTranscribe();
@@ -184,6 +184,11 @@ Java_com_rnwhisper_WhisperContext_initContextWithInputStream(
184
184
  return reinterpret_cast<jlong>(context);
185
185
  }
186
186
 
187
+ struct progress_callback_context {
188
+ JNIEnv *env;
189
+ jobject progress_callback_instance;
190
+ };
191
+
187
192
  JNIEXPORT jint JNICALL
188
193
  Java_com_rnwhisper_WhisperContext_fullTranscribe(
189
194
  JNIEnv *env,
@@ -206,7 +211,8 @@ Java_com_rnwhisper_WhisperContext_fullTranscribe(
206
211
  jboolean speed_up,
207
212
  jboolean translate,
208
213
  jstring language,
209
- jstring prompt
214
+ jstring prompt,
215
+ jobject progress_callback_instance
210
216
  ) {
211
217
  UNUSED(thiz);
212
218
  struct whisper_context *context = reinterpret_cast<struct whisper_context *>(context_ptr);
@@ -274,6 +280,21 @@ Java_com_rnwhisper_WhisperContext_fullTranscribe(
274
280
  };
275
281
  params.encoder_begin_callback_user_data = rn_whisper_assign_abort_map(job_id);
276
282
 
283
+ if (progress_callback_instance != nullptr) {
284
+ params.progress_callback = [](struct whisper_context * /*ctx*/, struct whisper_state * /*state*/, int progress, void * user_data) {
285
+ progress_callback_context *cb_ctx = (progress_callback_context *)user_data;
286
+ JNIEnv *env = cb_ctx->env;
287
+ jobject progress_callback_instance = cb_ctx->progress_callback_instance;
288
+ jclass progress_callback_class = env->GetObjectClass(progress_callback_instance);
289
+ jmethodID onProgress = env->GetMethodID(progress_callback_class, "onProgress", "(I)V");
290
+ env->CallVoidMethod(progress_callback_instance, onProgress, progress);
291
+ };
292
+ progress_callback_context *cb_ctx = new progress_callback_context;
293
+ cb_ctx->env = env;
294
+ cb_ctx->progress_callback_instance = env->NewGlobalRef(progress_callback_instance);
295
+ params.progress_callback_user_data = cb_ctx;
296
+ }
297
+
277
298
  LOGI("About to reset timings");
278
299
  whisper_reset_timings(context);
279
300