forked from ggerganov/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.
addon.node : using whisper as a Node.js addon (ggerganov#443)
* addon: implement node addon call whisper through cpp * addon: modify the license to MIT * addon: remove iostream * addon: rename dir * addon: fix typo * addon: configure cmake to build when cmake-js is used
- Loading branch information
1 parent
b2fc4c7
commit c306a7f
Showing
7 changed files
with
528 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
node_modules | ||
build |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
set(TARGET whisper-addon) | ||
|
||
# Base settings | ||
#================================================================== | ||
# env var supported by cmake-js | ||
add_definitions(-DNAPI_VERSION=4) | ||
include_directories(${CMAKE_JS_INC}) | ||
#================================================================== | ||
|
||
add_library(${TARGET} SHARED ${CMAKE_JS_SRC} addon.cpp) | ||
set_target_properties(${TARGET} PROPERTIES PREFIX "" SUFFIX ".node") | ||
|
||
include(DefaultTargetOptions) | ||
|
||
# Include N-API wrappers | ||
#================================================================== | ||
execute_process(COMMAND node -p "require('node-addon-api').include" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE NODE_ADDON_API_DIR | ||
) | ||
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) | ||
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) | ||
target_include_directories(${TARGET} PRIVATE ${NODE_ADDON_API_DIR}) | ||
#================================================================== | ||
|
||
target_link_libraries(${TARGET} ${CMAKE_JS_LIB} whisper ${CMAKE_THREAD_LIBS_INIT}) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# addon | ||
|
||
This is an addon demo that can **perform whisper model reasoning in `node` and `electron` environments**, based on [cmake-js](https://github.com/cmake-js/cmake-js). | ||
It can be used as a reference for using the whisper.cpp project in other node projects. | ||
|
||
## Install | ||
|
||
```shell | ||
npm install | ||
``` | ||
|
||
## Compile | ||
|
||
Make sure it is in the project root directory and compiled with make-js. | ||
|
||
```shell | ||
npx cmake-js compile -T whisper-addon | ||
``` | ||
|
||
For Electron addon and cmake-js options, you can see [cmake-js](https://github.com/cmake-js/cmake-js) and make very few configuration changes. | ||
|
||
> Such as appointing special cmake path: | ||
> ```shell | ||
> npx cmake-js compile -c 'xxx/cmake' -T whisper-addon | ||
> ``` | ||
## Run | ||
```shell | ||
cd examples/addon.node | ||
node index.js --language='language' --model='model-path' --fname_inp='file-path' | ||
``` | ||
Because this is a simple Demo, only the above parameters are set in the node environment. | ||
|
||
Other parameters can also be specified in the node environment. |
Oops, something went wrong.