diff --git a/.changeset/hip-weeks-promise.md b/.changeset/hip-weeks-promise.md new file mode 100644 index 0000000..62300f2 --- /dev/null +++ b/.changeset/hip-weeks-promise.md @@ -0,0 +1,5 @@ +--- +"smart-whisper": minor +--- + +Allow to disable debug info in production diff --git a/src/binding/model.cc b/src/binding/model.cc index 61e5366..29d7940 100644 --- a/src/binding/model.cc +++ b/src/binding/model.cc @@ -27,6 +27,18 @@ class LoadModelWorker : public Napi::AsyncWorker { whisper_context *context; }; +bool IsProduction(const Napi::Object global_env) { + Napi::Object process = global_env.Get("process").As(); + Napi::Object env = process.Get("env").As(); + Napi::Value nodeEnv = env.Get("NODE_ENV"); + if (nodeEnv.IsString()) { + Napi::String nodeEnvStr = nodeEnv.As(); + std::string envStr = nodeEnvStr.Utf8Value(); + return envStr == "production"; + } + return false; +} + Napi::Value LoadModel(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); @@ -42,6 +54,10 @@ Napi::Value LoadModel(const Napi::CallbackInfo &info) { Napi::Function callback = info[2].As(); + if (IsProduction(env.Global())) { + whisper_log_set([](ggml_log_level level, const char *text, void *user_data) {}, nullptr); + } + LoadModelWorker *worker = new LoadModelWorker(callback, model_path, params); worker->Queue();