Spaces:
Running
Running
valVk
commited on
node : add additional params (#2000)
Browse files* Add additional params to addon.node
* Add comma_in_time as parameter
* Fix tests
examples/addon.node/__test__/whisper.spec.js
CHANGED
|
@@ -12,6 +12,9 @@ const whisperParamsMock = {
|
|
| 12 |
model: path.join(__dirname, "../../../models/ggml-base.en.bin"),
|
| 13 |
fname_inp: path.join(__dirname, "../../../samples/jfk.wav"),
|
| 14 |
use_gpu: true,
|
|
|
|
|
|
|
|
|
|
| 15 |
no_timestamps: false,
|
| 16 |
};
|
| 17 |
|
|
|
|
| 12 |
model: path.join(__dirname, "../../../models/ggml-base.en.bin"),
|
| 13 |
fname_inp: path.join(__dirname, "../../../samples/jfk.wav"),
|
| 14 |
use_gpu: true,
|
| 15 |
+
no_prints: true,
|
| 16 |
+
comma_in_time: false,
|
| 17 |
+
translate: true,
|
| 18 |
no_timestamps: false,
|
| 19 |
};
|
| 20 |
|
examples/addon.node/addon.cpp
CHANGED
|
@@ -36,7 +36,9 @@ struct whisper_params {
|
|
| 36 |
bool print_colors = false;
|
| 37 |
bool print_progress = false;
|
| 38 |
bool no_timestamps = false;
|
|
|
|
| 39 |
bool use_gpu = true;
|
|
|
|
| 40 |
|
| 41 |
std::string language = "en";
|
| 42 |
std::string prompt;
|
|
@@ -120,7 +122,14 @@ void whisper_print_segment_callback(struct whisper_context * ctx, struct whisper
|
|
| 120 |
}
|
| 121 |
}
|
| 122 |
|
|
|
|
|
|
|
| 123 |
int run(whisper_params ¶ms, std::vector<std::vector<std::string>> &result) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
if (params.fname_inp.empty()) {
|
| 125 |
fprintf(stderr, "error: no input files specified\n");
|
| 126 |
return 2;
|
|
@@ -155,14 +164,14 @@ int run(whisper_params ¶ms, std::vector<std::vector<std::string>> &result) {
|
|
| 155 |
}
|
| 156 |
|
| 157 |
// print system information
|
| 158 |
-
{
|
| 159 |
fprintf(stderr, "\n");
|
| 160 |
fprintf(stderr, "system_info: n_threads = %d / %d | %s\n",
|
| 161 |
params.n_threads*params.n_processors, std::thread::hardware_concurrency(), whisper_print_system_info());
|
| 162 |
}
|
| 163 |
|
| 164 |
// print some info about the processing
|
| 165 |
-
{
|
| 166 |
fprintf(stderr, "\n");
|
| 167 |
if (!whisper_is_multilingual(ctx)) {
|
| 168 |
if (params.language != "en" || params.translate) {
|
|
@@ -248,8 +257,8 @@ int run(whisper_params ¶ms, std::vector<std::vector<std::string>> &result) {
|
|
| 248 |
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
|
| 249 |
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
| 250 |
|
| 251 |
-
result[i].emplace_back(to_timestamp(t0,
|
| 252 |
-
result[i].emplace_back(to_timestamp(t1,
|
| 253 |
result[i].emplace_back(text);
|
| 254 |
}
|
| 255 |
|
|
@@ -300,13 +309,17 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
|
|
| 300 |
std::string model = whisper_params.Get("model").As<Napi::String>();
|
| 301 |
std::string input = whisper_params.Get("fname_inp").As<Napi::String>();
|
| 302 |
bool use_gpu = whisper_params.Get("use_gpu").As<Napi::Boolean>();
|
|
|
|
| 303 |
bool no_timestamps = whisper_params.Get("no_timestamps").As<Napi::Boolean>();
|
|
|
|
| 304 |
|
| 305 |
params.language = language;
|
| 306 |
params.model = model;
|
| 307 |
params.fname_inp.emplace_back(input);
|
| 308 |
params.use_gpu = use_gpu;
|
|
|
|
| 309 |
params.no_timestamps = no_timestamps;
|
|
|
|
| 310 |
|
| 311 |
Napi::Function callback = info[1].As<Napi::Function>();
|
| 312 |
Worker* worker = new Worker(callback, params);
|
|
|
|
| 36 |
bool print_colors = false;
|
| 37 |
bool print_progress = false;
|
| 38 |
bool no_timestamps = false;
|
| 39 |
+
bool no_prints = false;
|
| 40 |
bool use_gpu = true;
|
| 41 |
+
bool comma_in_time = true;
|
| 42 |
|
| 43 |
std::string language = "en";
|
| 44 |
std::string prompt;
|
|
|
|
| 122 |
}
|
| 123 |
}
|
| 124 |
|
| 125 |
+
void cb_log_disable(enum ggml_log_level, const char *, void *) {}
|
| 126 |
+
|
| 127 |
int run(whisper_params ¶ms, std::vector<std::vector<std::string>> &result) {
|
| 128 |
+
|
| 129 |
+
if (params.no_prints) {
|
| 130 |
+
whisper_log_set(cb_log_disable, NULL);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
if (params.fname_inp.empty()) {
|
| 134 |
fprintf(stderr, "error: no input files specified\n");
|
| 135 |
return 2;
|
|
|
|
| 164 |
}
|
| 165 |
|
| 166 |
// print system information
|
| 167 |
+
if (!params.no_prints) {
|
| 168 |
fprintf(stderr, "\n");
|
| 169 |
fprintf(stderr, "system_info: n_threads = %d / %d | %s\n",
|
| 170 |
params.n_threads*params.n_processors, std::thread::hardware_concurrency(), whisper_print_system_info());
|
| 171 |
}
|
| 172 |
|
| 173 |
// print some info about the processing
|
| 174 |
+
if (!params.no_prints) {
|
| 175 |
fprintf(stderr, "\n");
|
| 176 |
if (!whisper_is_multilingual(ctx)) {
|
| 177 |
if (params.language != "en" || params.translate) {
|
|
|
|
| 257 |
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
|
| 258 |
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
| 259 |
|
| 260 |
+
result[i].emplace_back(to_timestamp(t0, params.comma_in_time));
|
| 261 |
+
result[i].emplace_back(to_timestamp(t1, params.comma_in_time));
|
| 262 |
result[i].emplace_back(text);
|
| 263 |
}
|
| 264 |
|
|
|
|
| 309 |
std::string model = whisper_params.Get("model").As<Napi::String>();
|
| 310 |
std::string input = whisper_params.Get("fname_inp").As<Napi::String>();
|
| 311 |
bool use_gpu = whisper_params.Get("use_gpu").As<Napi::Boolean>();
|
| 312 |
+
bool no_prints = whisper_params.Get("no_prints").As<Napi::Boolean>();
|
| 313 |
bool no_timestamps = whisper_params.Get("no_timestamps").As<Napi::Boolean>();
|
| 314 |
+
bool comma_in_time = whisper_params.Get("comma_in_time").As<Napi::Boolean>();
|
| 315 |
|
| 316 |
params.language = language;
|
| 317 |
params.model = model;
|
| 318 |
params.fname_inp.emplace_back(input);
|
| 319 |
params.use_gpu = use_gpu;
|
| 320 |
+
params.no_prints = no_prints;
|
| 321 |
params.no_timestamps = no_timestamps;
|
| 322 |
+
params.comma_in_time = comma_in_time;
|
| 323 |
|
| 324 |
Napi::Function callback = info[1].As<Napi::Function>();
|
| 325 |
Worker* worker = new Worker(callback, params);
|
examples/addon.node/index.js
CHANGED
|
@@ -10,8 +10,11 @@ const whisperAsync = promisify(whisper);
|
|
| 10 |
const whisperParams = {
|
| 11 |
language: "en",
|
| 12 |
model: path.join(__dirname, "../../models/ggml-base.en.bin"),
|
| 13 |
-
fname_inp: "../../samples/jfk.wav",
|
| 14 |
use_gpu: true,
|
|
|
|
|
|
|
|
|
|
| 15 |
no_timestamps: false,
|
| 16 |
};
|
| 17 |
|
|
@@ -34,5 +37,6 @@ for (const key in params) {
|
|
| 34 |
console.log("whisperParams =", whisperParams);
|
| 35 |
|
| 36 |
whisperAsync(whisperParams).then((result) => {
|
| 37 |
-
console.log(
|
|
|
|
| 38 |
});
|
|
|
|
| 10 |
const whisperParams = {
|
| 11 |
language: "en",
|
| 12 |
model: path.join(__dirname, "../../models/ggml-base.en.bin"),
|
| 13 |
+
fname_inp: path.join(__dirname, "../../samples/jfk.wav"),
|
| 14 |
use_gpu: true,
|
| 15 |
+
no_prints: true,
|
| 16 |
+
comma_in_time: false,
|
| 17 |
+
translate: true,
|
| 18 |
no_timestamps: false,
|
| 19 |
};
|
| 20 |
|
|
|
|
| 37 |
console.log("whisperParams =", whisperParams);
|
| 38 |
|
| 39 |
whisperAsync(whisperParams).then((result) => {
|
| 40 |
+
console.log();
|
| 41 |
+
console.log(result);
|
| 42 |
});
|