-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add WebAssembly for Kws #648
Merged
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
484e666
add WebAssembly for Kws
lovemefan 2203911
remove debug code
lovemefan ec373d1
add readme
lovemefan 7c3ba66
add keywords
lovemefan 33559d3
add build script
lovemefan 4cb1074
adjust thread num
lovemefan c02d663
copy the code from pull request #642
lovemefan 3afb57f
update the error message
lovemefan 270bbae
adapt to c api of pull request #642
lovemefan 47d84f5
Enable keyword modification without recompilation in the solution
lovemefan 8623a4d
format code style
lovemefan 6cb41ef
update c api
lovemefan 4e37fdd
code style format: add a newline character at the end of the file
lovemefan be354fc
code style format: delete empty line
lovemefan a026fba
add copyright information
lovemefan 18c9322
merged latest code
lovemefan 7b7ee17
merged latest code
lovemefan a29c6ff
remove duplicate code when merge pr #642
lovemefan a3e940d
only do not check the hotwords file when SHERPA_ONNX_ENABLE_WASM_KWS on
lovemefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,55 @@ | ||||||
if(NOT $ENV{SHERPA_ONNX_IS_USING_BUILD_WASM_SH}) | ||||||
message(FATAL_ERROR "Please use ./build-wasm-kws.sh to build for wasm KWS") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
endif() | ||||||
|
||||||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder-epoch-12-avg-2-chunk-16-left-64.onnx") | ||||||
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder-epoch-12-avg-2-chunk-16-left-64.onnx does not exist") | ||||||
message(FATAL_ERROR "Please read ${CMAKE_CURRENT_SOURCE_DIR}/assets/README.md before you continue") | ||||||
endif() | ||||||
|
||||||
set(exported_functions | ||||||
AcceptWaveform | ||||||
CreateOnlineKws | ||||||
CreateOnlineKwsStream | ||||||
GetOnlineKwsStreamResult | ||||||
DecodeOnlineKwsStream | ||||||
DestroyOnlineKws | ||||||
DestroyOnlineKwsResult | ||||||
DestroyOnlineKwsStream | ||||||
IsOnlineKwsStreamReady | ||||||
InputFinished | ||||||
) | ||||||
set(mangled_exported_functions) | ||||||
foreach(x IN LISTS exported_functions) | ||||||
list(APPEND mangled_exported_functions "_${x}") | ||||||
endforeach() | ||||||
|
||||||
list(JOIN mangled_exported_functions "," all_exported_functions) | ||||||
|
||||||
include_directories(${CMAKE_SOURCE_DIR}) | ||||||
set(MY_FLAGS "-s FORCE_FILESYSTEM=1 -s INITIAL_MEMORY=512MB -s ALLOW_MEMORY_GROWTH=1") | ||||||
string(APPEND MY_FLAGS " -sSTACK_SIZE=10485760 ") | ||||||
string(APPEND MY_FLAGS " -sEXPORTED_FUNCTIONS=[_CopyHeap,_malloc,_free,${all_exported_functions}] ") | ||||||
string(APPEND MY_FLAGS "--preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets@. ") | ||||||
string(APPEND MY_FLAGS " -sEXPORTED_RUNTIME_METHODS=['ccall','stringToUTF8','setValue','getValue','lengthBytesUTF8','UTF8ToString'] ") | ||||||
message(STATUS "MY_FLAGS: ${MY_FLAGS}") | ||||||
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_FLAGS}") | ||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_FLAGS}") | ||||||
set(CMAKE_EXECUTBLE_LINKER_FLAGS "${CMAKE_EXECUTBLE_LINKER_FLAGS} ${MY_FLAGS}") | ||||||
|
||||||
add_executable(sherpa-onnx-wasm-kws-main sherpa-onnx-wasm-main-kws.cc) | ||||||
target_link_libraries(sherpa-onnx-wasm-kws-main sherpa-onnx-c-api) | ||||||
install(TARGETS sherpa-onnx-wasm-kws-main DESTINATION bin/wasm) | ||||||
|
||||||
install( | ||||||
FILES | ||||||
"sherpa-onnx-kws.js" | ||||||
"app.js" | ||||||
"index.html" | ||||||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-kws-main>/sherpa-onnx-wasm-kws-main.js" | ||||||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-kws-main>/sherpa-onnx-wasm-kws-main.wasm" | ||||||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-kws-main>/sherpa-onnx-wasm-kws-main.data" | ||||||
DESTINATION | ||||||
bin/wasm | ||||||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you pass a keyword file from wasm?
We have been doing this for model files, such as
tokens.txt
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but it needs to be recompiled when the keywords is modified, which is very inconvenient. Because token.txt and keywords.txt are both packaged into the sherpa-onnx-wasm-kws-main.data file, they cannot be modified and can only be recompiled to generate. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Then please keep using your current approach.