forked from chidiwilliams/whisper.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nodejs Addon blocking main thread. Implemented Napi::AsyncWorker (gge…
…rganov#642) * fixed blocking code on node addon * modify the example to run async * format * added logic to see the whisper output * added logic to see the whisper output * removed extra function for more clean example
- Loading branch information
Showing
2 changed files
with
72 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
const path = require('path'); | ||
const { whisper } = require(path.join(__dirname, '../../build/Release/whisper-addon')); | ||
const path = require("path"); | ||
const { whisper } = require(path.join( | ||
__dirname, | ||
"../../build/Release/whisper-addon" | ||
)); | ||
const { promisify } = require("util"); | ||
|
||
const whisperAsync = promisify(whisper); | ||
|
||
const whisperParams = { | ||
language: 'en', | ||
model: path.join(__dirname, '../../models/ggml-base.en.bin'), | ||
fname_inp: '', | ||
language: "en", | ||
model: path.join(__dirname, "../../models/ggml-base.en.bin"), | ||
fname_inp: "../../samples/jfk.wav", | ||
}; | ||
|
||
const arguments = process.argv.slice(2); | ||
const params = Object.fromEntries( | ||
arguments.reduce((pre, item) => { | ||
if (item.startsWith("--")) { | ||
return [...pre, item.slice(2).split("=")]; | ||
} | ||
return pre; | ||
}, []), | ||
arguments.reduce((pre, item) => { | ||
if (item.startsWith("--")) { | ||
return [...pre, item.slice(2).split("=")]; | ||
} | ||
return pre; | ||
}, []) | ||
); | ||
|
||
for (const key in params) { | ||
if (whisperParams.hasOwnProperty(key)) { | ||
whisperParams[key] = params[key]; | ||
} | ||
if (whisperParams.hasOwnProperty(key)) { | ||
whisperParams[key] = params[key]; | ||
} | ||
} | ||
|
||
console.log('whisperParams =', whisperParams); | ||
console.log(whisper(whisperParams)); | ||
console.log("whisperParams =", whisperParams); | ||
|
||
whisperAsync(whisperParams).then((result) => { | ||
console.log(`Result from whisper: ${result}`); | ||
}); |