]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
node : add additional params (#2000)
authorvalVk <redacted>
Mon, 13 May 2024 12:15:43 +0000 (15:15 +0300)
committerGitHub <redacted>
Mon, 13 May 2024 12:15:43 +0000 (15:15 +0300)
* Add additional params to addon.node

* Add comma_in_time as parameter

* Fix tests

examples/addon.node/__test__/whisper.spec.js
examples/addon.node/addon.cpp
examples/addon.node/index.js

index c0367a8c5872478f224460d6aa8ed96074226fca..2f264fd3af5f1cf4e7b3a5f2da35fc5c654febbe 100644 (file)
@@ -12,6 +12,9 @@ const whisperParamsMock = {
   model: path.join(__dirname, "../../../models/ggml-base.en.bin"),
   fname_inp: path.join(__dirname, "../../../samples/jfk.wav"),
   use_gpu: true,
+  no_prints: true,
+  comma_in_time: false,
+  translate: true,
   no_timestamps: false,
 };
 
index 8988f9edc1d0b92904a82abb2f449d19c508e0b3..85576311ca939ad9f2761a3c0dfbbd35be92888d 100644 (file)
@@ -36,7 +36,9 @@ struct whisper_params {
     bool print_colors   = false;
     bool print_progress = false;
     bool no_timestamps  = false;
+    bool no_prints      = false;
     bool use_gpu        = true;
+    bool comma_in_time  = true;
 
     std::string language = "en";
     std::string prompt;
@@ -120,7 +122,14 @@ void whisper_print_segment_callback(struct whisper_context * ctx, struct whisper
     }
 }
 
+void cb_log_disable(enum ggml_log_level, const char *, void *) {}
+
 int run(whisper_params &params, std::vector<std::vector<std::string>> &result) {
+
+    if (params.no_prints) {
+        whisper_log_set(cb_log_disable, NULL);
+    }
+
     if (params.fname_inp.empty()) {
         fprintf(stderr, "error: no input files specified\n");
         return 2;
@@ -155,14 +164,14 @@ int run(whisper_params &params, std::vector<std::vector<std::string>> &result) {
         }
 
         // print system information
-        {
+        if (!params.no_prints) {
             fprintf(stderr, "\n");
             fprintf(stderr, "system_info: n_threads = %d / %d | %s\n",
                     params.n_threads*params.n_processors, std::thread::hardware_concurrency(), whisper_print_system_info());
         }
 
         // print some info about the processing
-        {
+        if (!params.no_prints) {
             fprintf(stderr, "\n");
             if (!whisper_is_multilingual(ctx)) {
                 if (params.language != "en" || params.translate) {
@@ -248,8 +257,8 @@ int run(whisper_params &params, std::vector<std::vector<std::string>> &result) {
         const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
         const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
 
-        result[i].emplace_back(to_timestamp(t0, true));
-        result[i].emplace_back(to_timestamp(t1, true));
+        result[i].emplace_back(to_timestamp(t0, params.comma_in_time));
+        result[i].emplace_back(to_timestamp(t1, params.comma_in_time));
         result[i].emplace_back(text);
     }
 
@@ -300,13 +309,17 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
   std::string model = whisper_params.Get("model").As<Napi::String>();
   std::string input = whisper_params.Get("fname_inp").As<Napi::String>();
   bool use_gpu = whisper_params.Get("use_gpu").As<Napi::Boolean>();
+  bool no_prints = whisper_params.Get("no_prints").As<Napi::Boolean>();
   bool no_timestamps = whisper_params.Get("no_timestamps").As<Napi::Boolean>();
+  bool comma_in_time = whisper_params.Get("comma_in_time").As<Napi::Boolean>();
 
   params.language = language;
   params.model = model;
   params.fname_inp.emplace_back(input);
   params.use_gpu = use_gpu;
+  params.no_prints = no_prints;
   params.no_timestamps = no_timestamps;
+  params.comma_in_time = comma_in_time;
 
   Napi::Function callback = info[1].As<Napi::Function>();
   Worker* worker = new Worker(callback, params);
index 9156a52de0744714fb85ef6e72ec6dcfb3a23397..90bd6fc2ff4b71f043403f95fd41d26d491e1eff 100644 (file)
@@ -10,8 +10,11 @@ const whisperAsync = promisify(whisper);
 const whisperParams = {
   language: "en",
   model: path.join(__dirname, "../../models/ggml-base.en.bin"),
-  fname_inp: "../../samples/jfk.wav",
+  fname_inp: path.join(__dirname, "../../samples/jfk.wav"),
   use_gpu: true,
+  no_prints: true,
+  comma_in_time: false,
+  translate: true,
   no_timestamps: false,
 };
 
@@ -34,5 +37,6 @@ for (const key in params) {
 console.log("whisperParams =", whisperParams);
 
 whisperAsync(whisperParams).then((result) => {
-  console.log(`Result from whisper: ${result}`);
+  console.log();
+  console.log(result);
 });