2023-03-22 20:19:22 +00:00
|
|
|
const path = require("path");
|
|
|
|
const { whisper } = require(path.join(
|
|
|
|
__dirname,
|
2024-05-02 21:52:55 +00:00
|
|
|
"../../build/Release/addon.node"
|
2023-03-22 20:19:22 +00:00
|
|
|
));
|
|
|
|
const { promisify } = require("util");
|
|
|
|
|
|
|
|
const whisperAsync = promisify(whisper);
|
2023-02-04 07:10:25 +00:00
|
|
|
|
|
|
|
const whisperParams = {
|
2023-03-22 20:19:22 +00:00
|
|
|
language: "en",
|
|
|
|
model: path.join(__dirname, "../../models/ggml-base.en.bin"),
|
2024-05-13 12:15:43 +00:00
|
|
|
fname_inp: path.join(__dirname, "../../samples/jfk.wav"),
|
2023-11-06 09:04:24 +00:00
|
|
|
use_gpu: true,
|
2024-05-20 06:08:48 +00:00
|
|
|
flash_attn: false,
|
2024-05-13 12:15:43 +00:00
|
|
|
no_prints: true,
|
|
|
|
comma_in_time: false,
|
|
|
|
translate: true,
|
2024-05-02 21:52:55 +00:00
|
|
|
no_timestamps: false,
|
2024-05-13 12:22:23 +00:00
|
|
|
audio_ctx: 0,
|
2023-02-04 07:10:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const arguments = process.argv.slice(2);
|
|
|
|
const params = Object.fromEntries(
|
2023-03-22 20:19:22 +00:00
|
|
|
arguments.reduce((pre, item) => {
|
|
|
|
if (item.startsWith("--")) {
|
2024-05-13 12:22:23 +00:00
|
|
|
const [key, value] = item.slice(2).split("=");
|
|
|
|
if (key === "audio_ctx") {
|
|
|
|
whisperParams[key] = parseInt(value);
|
|
|
|
} else {
|
|
|
|
whisperParams[key] = value;
|
|
|
|
}
|
|
|
|
return pre;
|
2023-03-22 20:19:22 +00:00
|
|
|
}
|
|
|
|
return pre;
|
|
|
|
}, [])
|
2023-02-04 07:10:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
for (const key in params) {
|
2023-03-22 20:19:22 +00:00
|
|
|
if (whisperParams.hasOwnProperty(key)) {
|
|
|
|
whisperParams[key] = params[key];
|
|
|
|
}
|
2023-02-04 07:10:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 20:19:22 +00:00
|
|
|
console.log("whisperParams =", whisperParams);
|
|
|
|
|
|
|
|
whisperAsync(whisperParams).then((result) => {
|
2024-05-13 12:15:43 +00:00
|
|
|
console.log();
|
|
|
|
console.log(result);
|
2023-03-22 20:19:22 +00:00
|
|
|
});
|