Skip to content

Commit 30f7310

Browse files
authored
node : add additional params (ggml-org#2000)
* Add additional params to addon.node * Add comma_in_time as parameter * Fix tests
1 parent 17fa62d commit 30f7310

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const whisperParamsMock = {
1212
model: path.join(__dirname, "../../../models/ggml-base.en.bin"),
1313
fname_inp: path.join(__dirname, "../../../samples/jfk.wav"),
1414
use_gpu: true,
15+
no_prints: true,
16+
comma_in_time: false,
17+
translate: true,
1518
no_timestamps: false,
1619
};
1720

examples/addon.node/addon.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ struct whisper_params {
3636
bool print_colors = false;
3737
bool print_progress = false;
3838
bool no_timestamps = false;
39+
bool no_prints = false;
3940
bool use_gpu = true;
41+
bool comma_in_time = true;
4042

4143
std::string language = "en";
4244
std::string prompt;
@@ -120,7 +122,14 @@ void whisper_print_segment_callback(struct whisper_context * ctx, struct whisper
120122
}
121123
}
122124

125+
void cb_log_disable(enum ggml_log_level, const char *, void *) {}
126+
123127
int run(whisper_params &params, std::vector<std::vector<std::string>> &result) {
128+
129+
if (params.no_prints) {
130+
whisper_log_set(cb_log_disable, NULL);
131+
}
132+
124133
if (params.fname_inp.empty()) {
125134
fprintf(stderr, "error: no input files specified\n");
126135
return 2;
@@ -155,14 +164,14 @@ int run(whisper_params &params, std::vector<std::vector<std::string>> &result) {
155164
}
156165

157166
// print system information
158-
{
167+
if (!params.no_prints) {
159168
fprintf(stderr, "\n");
160169
fprintf(stderr, "system_info: n_threads = %d / %d | %s\n",
161170
params.n_threads*params.n_processors, std::thread::hardware_concurrency(), whisper_print_system_info());
162171
}
163172

164173
// print some info about the processing
165-
{
174+
if (!params.no_prints) {
166175
fprintf(stderr, "\n");
167176
if (!whisper_is_multilingual(ctx)) {
168177
if (params.language != "en" || params.translate) {
@@ -248,8 +257,8 @@ int run(whisper_params &params, std::vector<std::vector<std::string>> &result) {
248257
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
249258
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
250259

251-
result[i].emplace_back(to_timestamp(t0, true));
252-
result[i].emplace_back(to_timestamp(t1, true));
260+
result[i].emplace_back(to_timestamp(t0, params.comma_in_time));
261+
result[i].emplace_back(to_timestamp(t1, params.comma_in_time));
253262
result[i].emplace_back(text);
254263
}
255264

@@ -300,13 +309,17 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
300309
std::string model = whisper_params.Get("model").As<Napi::String>();
301310
std::string input = whisper_params.Get("fname_inp").As<Napi::String>();
302311
bool use_gpu = whisper_params.Get("use_gpu").As<Napi::Boolean>();
312+
bool no_prints = whisper_params.Get("no_prints").As<Napi::Boolean>();
303313
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>();
304315

305316
params.language = language;
306317
params.model = model;
307318
params.fname_inp.emplace_back(input);
308319
params.use_gpu = use_gpu;
320+
params.no_prints = no_prints;
309321
params.no_timestamps = no_timestamps;
322+
params.comma_in_time = comma_in_time;
310323

311324
Napi::Function callback = info[1].As<Napi::Function>();
312325
Worker* worker = new Worker(callback, params);

examples/addon.node/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ const whisperAsync = promisify(whisper);
1010
const whisperParams = {
1111
language: "en",
1212
model: path.join(__dirname, "../../models/ggml-base.en.bin"),
13-
fname_inp: "../../samples/jfk.wav",
13+
fname_inp: path.join(__dirname, "../../samples/jfk.wav"),
1414
use_gpu: true,
15+
no_prints: true,
16+
comma_in_time: false,
17+
translate: true,
1518
no_timestamps: false,
1619
};
1720

@@ -34,5 +37,6 @@ for (const key in params) {
3437
console.log("whisperParams =", whisperParams);
3538

3639
whisperAsync(whisperParams).then((result) => {
37-
console.log(`Result from whisper: ${result}`);
40+
console.log();
41+
console.log(result);
3842
});

0 commit comments

Comments
 (0)