pajowu commited on
Commit
6ab2cc0
·
unverified ·
1 Parent(s): 48af9eb

whisper : add progress callback (#600)

Browse files
Files changed (2) hide show
  1. whisper.cpp +10 -0
  2. whisper.h +7 -0
whisper.cpp CHANGED
@@ -3152,6 +3152,9 @@ struct whisper_full_params whisper_full_default_params(enum whisper_sampling_str
3152
  /*.new_segment_callback =*/ nullptr,
3153
  /*.new_segment_callback_user_data =*/ nullptr,
3154
 
 
 
 
3155
  /*.encoder_begin_callback =*/ nullptr,
3156
  /*.encoder_begin_callback_user_data =*/ nullptr,
3157
 
@@ -3868,6 +3871,10 @@ int whisper_full_with_state(
3868
  fprintf(stderr, "%s: progress = %3d%%\n", __func__, progress_prev);
3869
  }
3870
  }
 
 
 
 
3871
 
3872
  // of only 1 second left, then stop
3873
  if (seek + 100 >= seek_end) {
@@ -4456,6 +4463,9 @@ int whisper_full_parallel(
4456
  params_cur.new_segment_callback = nullptr;
4457
  params_cur.new_segment_callback_user_data = nullptr;
4458
 
 
 
 
4459
  workers[i] = std::thread(whisper_full_with_state, ctx, states[i], std::move(params_cur), samples + start_samples, n_samples_cur);
4460
  }
4461
 
 
3152
  /*.new_segment_callback =*/ nullptr,
3153
  /*.new_segment_callback_user_data =*/ nullptr,
3154
 
3155
+ /*.progress_callback =*/ nullptr,
3156
+ /*.progress_callback_user_data =*/ nullptr,
3157
+
3158
  /*.encoder_begin_callback =*/ nullptr,
3159
  /*.encoder_begin_callback_user_data =*/ nullptr,
3160
 
 
3871
  fprintf(stderr, "%s: progress = %3d%%\n", __func__, progress_prev);
3872
  }
3873
  }
3874
+ if (params.progress_callback) {
3875
+ params.progress_callback(
3876
+ ctx, ctx->state, progress_prev, params.progress_callback_user_data);
3877
+ }
3878
 
3879
  // of only 1 second left, then stop
3880
  if (seek + 100 >= seek_end) {
 
4463
  params_cur.new_segment_callback = nullptr;
4464
  params_cur.new_segment_callback_user_data = nullptr;
4465
 
4466
+ params_cur.progress_callback = nullptr;
4467
+ params_cur.progress_callback_user_data = nullptr;
4468
+
4469
  workers[i] = std::thread(whisper_full_with_state, ctx, states[i], std::move(params_cur), samples + start_samples, n_samples_cur);
4470
  }
4471
 
whisper.h CHANGED
@@ -306,6 +306,9 @@ extern "C" {
306
  // Use the whisper_full_...() functions to obtain the text segments
307
  typedef void (*whisper_new_segment_callback)(struct whisper_context * ctx, struct whisper_state * state, int n_new, void * user_data);
308
 
 
 
 
309
  // Encoder begin callback
310
  // If not NULL, called before the encoder starts
311
  // If it returns false, the computation is aborted
@@ -392,6 +395,10 @@ extern "C" {
392
  whisper_new_segment_callback new_segment_callback;
393
  void * new_segment_callback_user_data;
394
 
 
 
 
 
395
  // called each time before the encoder starts
396
  whisper_encoder_begin_callback encoder_begin_callback;
397
  void * encoder_begin_callback_user_data;
 
306
  // Use the whisper_full_...() functions to obtain the text segments
307
  typedef void (*whisper_new_segment_callback)(struct whisper_context * ctx, struct whisper_state * state, int n_new, void * user_data);
308
 
309
+ // Progress callback
310
+ typedef void (*whisper_progress_callback)(struct whisper_context * ctx, struct whisper_state * state, int progress, void * user_data);
311
+
312
  // Encoder begin callback
313
  // If not NULL, called before the encoder starts
314
  // If it returns false, the computation is aborted
 
395
  whisper_new_segment_callback new_segment_callback;
396
  void * new_segment_callback_user_data;
397
 
398
+ // called on each progress update
399
+ whisper_progress_callback progress_callback;
400
+ void * progress_callback_user_data;
401
+
402
  // called each time before the encoder starts
403
  whisper_encoder_begin_callback encoder_begin_callback;
404
  void * encoder_begin_callback_user_data;