-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command.wasm : add voice assistant example for the Web (#171)
Same as the command-line tool "command", but runs in the browser Also, added helper script "extra/deploy-wasm.sh" and fixed some timing constants for the WASM examples.
- Loading branch information
Showing
12 changed files
with
939 additions
and
28 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
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,47 @@ | ||
# | ||
# libcommand | ||
# | ||
|
||
set(TARGET libcommand) | ||
|
||
add_executable(${TARGET} | ||
emscripten.cpp | ||
) | ||
|
||
target_link_libraries(${TARGET} PRIVATE | ||
whisper | ||
) | ||
|
||
unset(EXTRA_FLAGS) | ||
|
||
if (WHISPER_WASM_SINGLE_FILE) | ||
set(EXTRA_FLAGS "-s SINGLE_FILE=1") | ||
message(STATUS "Embedding WASM inside command.js") | ||
|
||
add_custom_command( | ||
TARGET ${TARGET} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
${CMAKE_BINARY_DIR}/bin/libcommand.js | ||
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/command.wasm/command.js | ||
) | ||
endif() | ||
|
||
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \ | ||
--bind \ | ||
-s USE_PTHREADS=1 \ | ||
-s PTHREAD_POOL_SIZE=8 \ | ||
-s INITIAL_MEMORY=1024MB \ | ||
-s TOTAL_MEMORY=1024MB \ | ||
-s FORCE_FILESYSTEM=1 \ | ||
-s EXPORTED_RUNTIME_METHODS=\"['print', 'printErr', 'ccall', 'cwrap']\" \ | ||
${EXTRA_FLAGS} \ | ||
") | ||
|
||
# | ||
# command.wasm | ||
# | ||
|
||
set(TARGET command.wasm) | ||
|
||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/index-tmpl.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}/index.html @ONLY) | ||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../helpers.js ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET}/helpers.js @ONLY) |
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,23 @@ | ||
# command.wasm | ||
|
||
This is a basic Voice Assistant example that accepts voice commands from the microphone. | ||
It runs in fully in the browser via WebAseembly. | ||
|
||
Online demo: https://whisper.ggerganov.com/command/ | ||
|
||
Terminal version: https://github.com/ggerganov/whisper.cpp/examples/command | ||
|
||
## Build instructions | ||
|
||
```bash | ||
# build using Emscripten (v3.1.2) | ||
git clone https://github.com/ggerganov/whisper.cpp | ||
cd whisper.cpp | ||
mkdir build-em && cd build-em | ||
emcmake cmake .. | ||
make -j | ||
|
||
# copy the produced page to your HTTP path | ||
cp bin/command.wasm/* /path/to/html/ | ||
cp bin/libcommand.worker.js /path/to/html/ | ||
``` |
Oops, something went wrong.