forked from k2-fsa/sherpa-onnx
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor WebAssembly build script. (k2-fsa#598)
Make it easier to build WebAssembly for ASR.
- Loading branch information
1 parent
25079b5
commit 7c4b599
Showing
12 changed files
with
189 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
name: wasm-simd-hf-space-de-tts | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: wasm-simd-hf-space-de-tts-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
wasm-simd-hf-space-de-tts: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install emsdk | ||
uses: mymindstorm/setup-emsdk@v14 | ||
|
||
- name: View emsdk version | ||
shell: bash | ||
run: | | ||
emcc -v | ||
echo "--------------------" | ||
emcc --check | ||
- name: Download model files | ||
shell: bash | ||
run: | | ||
cd wasm/tts/assets | ||
ls -lh | ||
echo "----------" | ||
wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-de_DE-thorsten_emotional-medium.tar.bz2 | ||
tar xf vits-piper-de_DE-thorsten_emotional-medium.tar.bz2 | ||
rm vits-piper-de_DE-thorsten_emotional-medium.tar.bz2 | ||
mv -v vits-piper-de_DE-thorsten_emotional-medium/de_DE-thorsten_emotional-medium.onnx ./model.onnx | ||
mv -v vits-piper-de_DE-thorsten_emotional-medium/tokens.txt ./ | ||
mv vits-piper-de_DE-thorsten_emotional-medium/espeak-ng-data ./ | ||
rm -rf vits-piper-de_DE-thorsten_emotional-medium | ||
ls -lh | ||
- name: Build sherpa-onnx for WebAssembly | ||
shell: bash | ||
run: | | ||
./build-wasm-simd-tts.sh | ||
- name: collect files | ||
shell: bash | ||
run: | | ||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
mv build-wasm-simd-tts/install/bin/wasm sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-de-tts | ||
ls -lh sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-de-tts | ||
tar cjfv sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-de-tts.tar.bz2 ./sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-de-tts | ||
- name: Upload wasm files | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: sherpa-onnx-wasm-simd-de-tts | ||
path: ./sherpa-onnx-wasm-simd-*.tar.bz2 | ||
|
||
- name: Publish to huggingface | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
uses: nick-fields/retry@v2 | ||
with: | ||
max_attempts: 20 | ||
timeout_seconds: 200 | ||
shell: bash | ||
command: | | ||
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
rm -rf huggingface | ||
export GIT_LFS_SKIP_SMUDGE=1 | ||
git clone https://huggingface.co/spaces/k2-fsa/web-assembly-tts-sherpa-onnx-de huggingface | ||
cd huggingface | ||
git fetch | ||
git pull | ||
git merge -m "merge remote" --ff origin main | ||
cp -v ../sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-de-tts/* . | ||
git status | ||
git lfs track "*.data" | ||
git lfs track "*.wasm" | ||
ls -lh | ||
git add . | ||
git commit -m "update model" | ||
git push https://csukuangfj:[email protected]/spaces/k2-fsa/web-assembly-tts-sherpa-onnx-de main |
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 |
---|---|---|
@@ -1,59 +1,3 @@ | ||
if(NOT $ENV{SHERPA_ONNX_IS_USING_BUILD_WASM_SH}) | ||
message(FATAL_ERROR "Please use ./build-wasm.sh to build for wasm") | ||
if(SHERPA_ONNX_ENABLE_WASM_TTS) | ||
add_subdirectory(tts) | ||
endif() | ||
|
||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder_jit_trace-pnnx.ncnn.bin") | ||
message(WARNING "${CMAKE_CURRENT_SOURCE_DIR}/assets/decoder_jit_trace-pnnx.ncnn.bin does not exist") | ||
# message(FATAL_ERROR "Please read ${CMAKE_CURRENT_SOURCE_DIR}/assets/README.md before you continue") | ||
endif() | ||
|
||
set(exported_functions | ||
MyPrint | ||
SherpaOnnxCreateOfflineTts | ||
SherpaOnnxDestroyOfflineTts | ||
SherpaOnnxDestroyOfflineTtsGeneratedAudio | ||
SherpaOnnxOfflineTtsGenerate | ||
SherpaOnnxOfflineTtsGenerateWithCallback | ||
SherpaOnnxOfflineTtsNumSpeakers | ||
SherpaOnnxOfflineTtsSampleRate | ||
SherpaOnnxWriteWave | ||
) | ||
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 ") # 10MB | ||
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'] ") | ||
|
||
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}") | ||
|
||
if (NOT CMAKE_EXECUTABLE_SUFFIX STREQUAL ".js") | ||
message(FATAL_ERROR "The default suffix for building executables should be .js!") | ||
endif() | ||
# set(CMAKE_EXECUTABLE_SUFFIX ".html") | ||
|
||
add_executable(sherpa-onnx-wasm-main sherpa-onnx-wasm-main.cc) | ||
target_link_libraries(sherpa-onnx-wasm-main sherpa-onnx-c-api) | ||
install(TARGETS sherpa-onnx-wasm-main DESTINATION bin/wasm) | ||
|
||
install( | ||
FILES | ||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.js" | ||
"index.html" | ||
"sherpa-onnx.js" | ||
"app.js" | ||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.wasm" | ||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.data" | ||
# "$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.html" | ||
DESTINATION | ||
bin/wasm | ||
) |
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,58 @@ | ||
if(NOT $ENV{SHERPA_ONNX_IS_USING_BUILD_WASM_SH}) | ||
message(FATAL_ERROR "Please use ./build-wasm-simd-tts.sh to build for wasm TTS") | ||
endif() | ||
|
||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/assets/model.onnx") | ||
message(FATAL_ERROR "Please read ${CMAKE_CURRENT_SOURCE_DIR}/assets/README.md before you continue") | ||
endif() | ||
|
||
set(exported_functions | ||
MyPrint | ||
SherpaOnnxCreateOfflineTts | ||
SherpaOnnxDestroyOfflineTts | ||
SherpaOnnxDestroyOfflineTtsGeneratedAudio | ||
SherpaOnnxOfflineTtsGenerate | ||
SherpaOnnxOfflineTtsGenerateWithCallback | ||
SherpaOnnxOfflineTtsNumSpeakers | ||
SherpaOnnxOfflineTtsSampleRate | ||
SherpaOnnxWriteWave | ||
) | ||
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 ") # 10MB | ||
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'] ") | ||
|
||
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}") | ||
|
||
if (NOT CMAKE_EXECUTABLE_SUFFIX STREQUAL ".js") | ||
message(FATAL_ERROR "The default suffix for building executables should be .js!") | ||
endif() | ||
# set(CMAKE_EXECUTABLE_SUFFIX ".html") | ||
|
||
add_executable(sherpa-onnx-wasm-main sherpa-onnx-wasm-main.cc) | ||
target_link_libraries(sherpa-onnx-wasm-main sherpa-onnx-c-api) | ||
install(TARGETS sherpa-onnx-wasm-main DESTINATION bin/wasm) | ||
|
||
install( | ||
FILES | ||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.js" | ||
"index.html" | ||
"sherpa-onnx.js" | ||
"app.js" | ||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.wasm" | ||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.data" | ||
# "$<TARGET_FILE_DIR:sherpa-onnx-wasm-main>/sherpa-onnx-wasm-main.html" | ||
DESTINATION | ||
bin/wasm | ||
) |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.