whisper.rn 0.3.9 → 0.4.0-rc.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/cpp/whisper.h CHANGED
@@ -334,6 +334,11 @@ extern "C" {
334
334
  // If it returns false, the computation is aborted
335
335
  typedef bool (*whisper_encoder_begin_callback)(struct whisper_context * ctx, struct whisper_state * state, void * user_data);
336
336
 
337
+ // Abort callback
338
+ // If not NULL, called before ggml computation
339
+ // If it returns true, the computation is aborted
340
+ typedef bool (*whisper_abort_callback)(void * user_data);
341
+
337
342
  // Logits filter callback
338
343
  // Can be used to modify the logits before sampling
339
344
  // If not NULL, called after applying temperature to logits
@@ -428,6 +433,10 @@ extern "C" {
428
433
  whisper_encoder_begin_callback encoder_begin_callback;
429
434
  void * encoder_begin_callback_user_data;
430
435
 
436
+ // called each time before ggml computation starts
437
+ whisper_abort_callback abort_callback;
438
+ void * abort_callback_user_data;
439
+
431
440
  // called by each decoder to filter obtained logits
432
441
  whisper_logits_filter_callback logits_filter_callback;
433
442
  void * logits_filter_callback_user_data;
@@ -485,6 +494,7 @@ extern "C" {
485
494
 
486
495
  // Get whether the next segment is predicted as a speaker turn
487
496
  WHISPER_API bool whisper_full_get_segment_speaker_turn_next(struct whisper_context * ctx, int i_segment);
497
+ WHISPER_API bool whisper_full_get_segment_speaker_turn_next_from_state(struct whisper_state * state, int i_segment);
488
498
 
489
499
  // Get the text of the specified segment
490
500
  WHISPER_API const char * whisper_full_get_segment_text (struct whisper_context * ctx, int i_segment);
@@ -349,7 +349,7 @@ struct rnwhisper_segments_callback_data {
349
349
  params.new_segment_callback = [](struct whisper_context * ctx, struct whisper_state * /*state*/, int n_new, void * user_data) {
350
350
  struct rnwhisper_segments_callback_data *data = (struct rnwhisper_segments_callback_data *)user_data;
351
351
  data->total_n_new += n_new;
352
-
352
+
353
353
  NSString *text = @"";
354
354
  NSMutableArray *segments = [[NSMutableArray alloc] init];
355
355
  for (int i = data->total_n_new - n_new; i < data->total_n_new; i++) {
@@ -451,7 +451,7 @@ struct rnwhisper_segments_callback_data {
451
451
  if (options[@"maxContext"] != nil) {
452
452
  params.n_max_text_ctx = [options[@"maxContext"] intValue];
453
453
  }
454
-
454
+
455
455
  if (options[@"offset"] != nil) {
456
456
  params.offset_ms = [options[@"offset"] intValue];
457
457
  }
@@ -467,16 +467,22 @@ struct rnwhisper_segments_callback_data {
467
467
  if (options[@"temperatureInc"] != nil) {
468
468
  params.temperature_inc = [options[@"temperature_inc"] floatValue];
469
469
  }
470
-
470
+
471
471
  if (options[@"prompt"] != nil) {
472
472
  params.initial_prompt = [options[@"prompt"] UTF8String];
473
473
  }
474
474
 
475
+ // abort handler
475
476
  params.encoder_begin_callback = [](struct whisper_context * /*ctx*/, struct whisper_state * /*state*/, void * user_data) {
476
477
  bool is_aborted = *(bool*)user_data;
477
478
  return !is_aborted;
478
479
  };
479
480
  params.encoder_begin_callback_user_data = rn_whisper_assign_abort_map(jobId);
481
+ params.abort_callback = [](void * user_data) {
482
+ bool is_aborted = *(bool*)user_data;
483
+ return is_aborted;
484
+ };
485
+ params.abort_callback_user_data = rn_whisper_assign_abort_map(jobId);
480
486
 
481
487
  return params;
482
488
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whisper.rn",
3
- "version": "0.3.9",
3
+ "version": "0.4.0-rc.0",
4
4
  "description": "React Native binding of whisper.cpp",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,7 +1,7 @@
1
1
  require "json"
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
- base_ld_flags = "-framework Accelerate"
4
+ base_ld_flags = "-framework Accelerate -framework Foundation -framework Metal -framework MetalKit"
5
5
  base_compiler_flags = "-DWSP_GGML_USE_ACCELERATE -Wno-shorten-64-to-32"
6
6
  folly_compiler_flags = "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma"
7
7
 
@@ -16,6 +16,11 @@ if ENV['RNWHISPER_DISABLE_COREML'] != '1' then
16
16
  base_compiler_flags += " -DWHISPER_USE_COREML -DWHISPER_COREML_ALLOW_FALLBACK"
17
17
  end
18
18
 
19
+ # TODO: Enable Metal by default when we have use_gpu param
20
+ if ENV["RNWHISPER_ENABLE_METAL"] == "1" then
21
+ base_compiler_flags += " -DWSP_GGML_USE_METAL" # -DWSP_GGML_METAL_NDEBUG
22
+ end
23
+
19
24
  Pod::Spec.new do |s|
20
25
  s.name = "whisper-rn"
21
26
  s.version = package["version"]
@@ -28,6 +33,7 @@ Pod::Spec.new do |s|
28
33
  s.source = { :git => "https://github.com/mybigday/whisper.rn.git", :tag => "#{s.version}" }
29
34
 
30
35
  s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp,c,m,mm}"
36
+ s.resources = "cpp/**/*.{metal}"
31
37
 
32
38
  s.dependency "React-Core"
33
39
 
@@ -45,7 +51,7 @@ Pod::Spec.new do |s|
45
51
  s.pod_target_xcconfig = {
46
52
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
47
53
  "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
48
- "OTHER_LDFLAGS" => "-framework Accelerate",
54
+ "OTHER_LDFLAGS" => base_ld_flags,
49
55
  "OTHER_CFLAGS" => base_optimizer_flags,
50
56
  "OTHER_CPLUSPLUSFLAGS" => new_arch_cpp_flags + " " + base_optimizer_flags
51
57
  }