]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
ref #16, #22 : add "offset" argument
authorGeorgi Gerganov <redacted>
Fri, 7 Oct 2022 19:00:40 +0000 (22:00 +0300)
committerGeorgi Gerganov <redacted>
Fri, 7 Oct 2022 19:00:40 +0000 (22:00 +0300)
Allows to start processing the input audio at some offset from the
beginning. Useful for splitting a long job into multiple tasks.

main.cpp
whisper.cpp
whisper.h

index d363ab7e071daa9e5bdf1ba719497f3dd22afde6..9769b7ff61d78519bab00155edf8d1f55d9ba245 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -28,6 +28,7 @@ std::string to_timestamp(int64_t t) {
 struct whisper_params {
     int32_t seed      = -1; // RNG seed, not used currently
     int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
+    int32_t offset_ms = 0;
 
     bool verbose              = false;
     bool translate            = false;
@@ -55,6 +56,8 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
             params.seed = std::stoi(argv[++i]);
         } else if (arg == "-t" || arg == "--threads") {
             params.n_threads = std::stoi(argv[++i]);
+        } else if (arg == "-o" || arg == "--offset") {
+            params.offset_ms = std::stoi(argv[++i]);
         } else if (arg == "-v" || arg == "--verbose") {
             params.verbose = true;
         } else if (arg == "--translate") {
@@ -95,6 +98,7 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
     fprintf(stderr, "  -h,       --help           show this help message and exit\n");
     fprintf(stderr, "  -s SEED,  --seed SEED      RNG seed (default: -1)\n");
     fprintf(stderr, "  -t N,     --threads N      number of threads to use during computation (default: %d)\n", params.n_threads);
+    fprintf(stderr, "  -o N,     --offset N       offset in milliseconds (default: %d)\n", params.offset_ms);
     fprintf(stderr, "  -v,       --verbose        verbose output\n");
     fprintf(stderr, "            --translate      translate from source language to english\n");
     fprintf(stderr, "  -ps,      --print_special  print special tokens\n");
@@ -203,6 +207,7 @@ int main(int argc, char ** argv) {
             wparams.translate            = params.translate;
             wparams.language             = params.language.c_str();
             wparams.n_threads            = params.n_threads;
+            wparams.offset_ms            = params.offset_ms;
 
             if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
                 fprintf(stderr, "%s: failed to process audio\n", argv[0]);
index 46a4caa03238acd125e1d5cc51e09f7109bf24d3..ca0c6a44a189b7b75e34999c8447ce569088cc84 100644 (file)
@@ -2256,6 +2256,7 @@ struct whisper_full_params whisper_full_default_params(enum whisper_decode_strat
                 result = (struct whisper_full_params) {
                     .strategy  = WHISPER_DECODE_GREEDY,
                     .n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
+                    .offset_ms = 0,
 
                     .translate            = false,
                     .print_special_tokens = false,
@@ -2275,6 +2276,7 @@ struct whisper_full_params whisper_full_default_params(enum whisper_decode_strat
                 result = (struct whisper_full_params) {
                     .strategy  = WHISPER_DECODE_GREEDY,
                     .n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
+                    .offset_ms = 0,
 
                     .translate            = false,
                     .print_special_tokens = false,
@@ -2329,7 +2331,7 @@ int whisper_full(
     int progress_step = 5;
 
     // main loop
-    int seek = 0;
+    int seek = params.offset_ms/10;
     while (true) {
         int progress_cur = (100*seek)/whisper_n_len(ctx);
         while (progress_cur >= progress_prev + progress_step) {
index 2df5bdfb763378b608ff6086ed8187c5d1eb3b9b..78e08b76ae9e4279d64b3e3413ffae8855586491 100644 (file)
--- a/whisper.h
+++ b/whisper.h
@@ -102,6 +102,7 @@ extern "C" {
         enum whisper_decode_strategy strategy;
 
         int n_threads;
+        int offset_ms;
 
         bool translate;
         bool print_special_tokens;