ggerganov commited on
Commit
35a7fcb
·
unverified ·
1 Parent(s): 6c66a1b

ref #16, #22 : add "offset" argument

Browse files

Allows to start processing the input audio at some offset from the
beginning. Useful for splitting a long job into multiple tasks.

Files changed (3) hide show
  1. main.cpp +5 -0
  2. whisper.cpp +3 -1
  3. whisper.h +1 -0
main.cpp CHANGED
@@ -28,6 +28,7 @@ std::string to_timestamp(int64_t t) {
28
  struct whisper_params {
29
  int32_t seed = -1; // RNG seed, not used currently
30
  int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
 
31
 
32
  bool verbose = false;
33
  bool translate = false;
@@ -55,6 +56,8 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
55
  params.seed = std::stoi(argv[++i]);
56
  } else if (arg == "-t" || arg == "--threads") {
57
  params.n_threads = std::stoi(argv[++i]);
 
 
58
  } else if (arg == "-v" || arg == "--verbose") {
59
  params.verbose = true;
60
  } else if (arg == "--translate") {
@@ -95,6 +98,7 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
95
  fprintf(stderr, " -h, --help show this help message and exit\n");
96
  fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
97
  fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
 
98
  fprintf(stderr, " -v, --verbose verbose output\n");
99
  fprintf(stderr, " --translate translate from source language to english\n");
100
  fprintf(stderr, " -ps, --print_special print special tokens\n");
@@ -203,6 +207,7 @@ int main(int argc, char ** argv) {
203
  wparams.translate = params.translate;
204
  wparams.language = params.language.c_str();
205
  wparams.n_threads = params.n_threads;
 
206
 
207
  if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
208
  fprintf(stderr, "%s: failed to process audio\n", argv[0]);
 
28
  struct whisper_params {
29
  int32_t seed = -1; // RNG seed, not used currently
30
  int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
31
+ int32_t offset_ms = 0;
32
 
33
  bool verbose = false;
34
  bool translate = false;
 
56
  params.seed = std::stoi(argv[++i]);
57
  } else if (arg == "-t" || arg == "--threads") {
58
  params.n_threads = std::stoi(argv[++i]);
59
+ } else if (arg == "-o" || arg == "--offset") {
60
+ params.offset_ms = std::stoi(argv[++i]);
61
  } else if (arg == "-v" || arg == "--verbose") {
62
  params.verbose = true;
63
  } else if (arg == "--translate") {
 
98
  fprintf(stderr, " -h, --help show this help message and exit\n");
99
  fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
100
  fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
101
+ fprintf(stderr, " -o N, --offset N offset in milliseconds (default: %d)\n", params.offset_ms);
102
  fprintf(stderr, " -v, --verbose verbose output\n");
103
  fprintf(stderr, " --translate translate from source language to english\n");
104
  fprintf(stderr, " -ps, --print_special print special tokens\n");
 
207
  wparams.translate = params.translate;
208
  wparams.language = params.language.c_str();
209
  wparams.n_threads = params.n_threads;
210
+ wparams.offset_ms = params.offset_ms;
211
 
212
  if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
213
  fprintf(stderr, "%s: failed to process audio\n", argv[0]);
whisper.cpp CHANGED
@@ -2256,6 +2256,7 @@ struct whisper_full_params whisper_full_default_params(enum whisper_decode_strat
2256
  result = (struct whisper_full_params) {
2257
  .strategy = WHISPER_DECODE_GREEDY,
2258
  .n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
 
2259
 
2260
  .translate = false,
2261
  .print_special_tokens = false,
@@ -2275,6 +2276,7 @@ struct whisper_full_params whisper_full_default_params(enum whisper_decode_strat
2275
  result = (struct whisper_full_params) {
2276
  .strategy = WHISPER_DECODE_GREEDY,
2277
  .n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
 
2278
 
2279
  .translate = false,
2280
  .print_special_tokens = false,
@@ -2329,7 +2331,7 @@ int whisper_full(
2329
  int progress_step = 5;
2330
 
2331
  // main loop
2332
- int seek = 0;
2333
  while (true) {
2334
  int progress_cur = (100*seek)/whisper_n_len(ctx);
2335
  while (progress_cur >= progress_prev + progress_step) {
 
2256
  result = (struct whisper_full_params) {
2257
  .strategy = WHISPER_DECODE_GREEDY,
2258
  .n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
2259
+ .offset_ms = 0,
2260
 
2261
  .translate = false,
2262
  .print_special_tokens = false,
 
2276
  result = (struct whisper_full_params) {
2277
  .strategy = WHISPER_DECODE_GREEDY,
2278
  .n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
2279
+ .offset_ms = 0,
2280
 
2281
  .translate = false,
2282
  .print_special_tokens = false,
 
2331
  int progress_step = 5;
2332
 
2333
  // main loop
2334
+ int seek = params.offset_ms/10;
2335
  while (true) {
2336
  int progress_cur = (100*seek)/whisper_n_len(ctx);
2337
  while (progress_cur >= progress_prev + progress_step) {
whisper.h CHANGED
@@ -102,6 +102,7 @@ extern "C" {
102
  enum whisper_decode_strategy strategy;
103
 
104
  int n_threads;
 
105
 
106
  bool translate;
107
  bool print_special_tokens;
 
102
  enum whisper_decode_strategy strategy;
103
 
104
  int n_threads;
105
+ int offset_ms;
106
 
107
  bool translate;
108
  bool print_special_tokens;