-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support WebAssembly for text-to-speech (#577)
- Loading branch information
1 parent
324a265
commit d771762
Showing
20 changed files
with
888 additions
and
69 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,107 @@ | ||
name: wasm-simd-hf-space-en | ||
|
||
on: | ||
push: | ||
branches: | ||
- wasm-2 | ||
release: | ||
types: | ||
- published | ||
|
||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: wasm-simd-hf-space-en-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
wasm-simd-hf-space-en: | ||
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/assets | ||
ls -lh | ||
echo "----------" | ||
wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-en_US-libritts_r-medium.tar.bz2 | ||
tar xf vits-piper-en_US-libritts_r-medium.tar.bz2 | ||
rm vits-piper-en_US-libritts_r-medium.tar.bz2 | ||
mv vits-piper-en_US-libritts_r-medium/en_US-libritts_r-medium.onnx ./model.onnx | ||
mv vits-piper-en_US-libritts_r-medium/tokens.txt ./ | ||
mv vits-piper-en_US-libritts_r-medium/espeak-ng-data ./ | ||
rm -rf vits-piper-en_US-libritts_r-medium | ||
ls -lh | ||
- name: Build sherpa-onnx for WebAssembly | ||
shell: bash | ||
run: | | ||
./build-wasm-simd.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/install/bin/wasm sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-en | ||
ls -lh sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-en | ||
tar cjfv sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-en.tar.bz2 ./sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-en | ||
- name: Upload wasm files | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: sherpa-onnx-wasm-simd-en | ||
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-en huggingface | ||
cd huggingface | ||
git fetch | ||
git pull | ||
git merge -m "merge remote" --ff origin main | ||
cp -v ../sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-en/* . | ||
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-en 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bash | ||
# Copyright (c) 2024 Xiaomi Corporation | ||
# | ||
# This script is to build sherpa-onnx for WebAssembly | ||
|
||
set -ex | ||
|
||
if [ x"$EMSCRIPTEN" == x"" ]; then | ||
if ! command -v emcc &> /dev/null; then | ||
echo "Please install emscripten first" | ||
echo "" | ||
echo "You can use the following commands to install it:" | ||
echo "" | ||
echo "git clone https://github.com/emscripten-core/emsdk.git" | ||
echo "cd emsdk" | ||
echo "git pull" | ||
echo "./emsdk install latest" | ||
echo "./emsdk activate latest" | ||
echo "source ./emsdk_env.sh" | ||
exit 1 | ||
else | ||
EMSCRIPTEN=$(dirname $(realpath $(which emcc))) | ||
fi | ||
fi | ||
|
||
export EMSCRIPTEN=$EMSCRIPTEN | ||
echo "EMSCRIPTEN: $EMSCRIPTEN" | ||
if [ ! -f $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake ]; then | ||
echo "Cannot find $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake" | ||
echo "Please make sure you have installed emsdk correctly" | ||
exit 1 | ||
fi | ||
|
||
mkdir -p build-wasm-simd | ||
pushd build-wasm-simd | ||
|
||
export SHERPA_ONNX_IS_USING_BUILD_WASM_SH=ON | ||
|
||
cmake \ | ||
-DCMAKE_INSTALL_PREFIX=./install \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \ | ||
\ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DBUILD_SHARED_LIBS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
-DSHERPA_ONNX_ENABLE_JNI=OFF \ | ||
-DSHERPA_ONNX_ENABLE_C_API=ON \ | ||
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ | ||
-DSHERPA_ONNX_ENABLE_GPU=OFF \ | ||
-DSHERPA_ONNX_ENABLE_WASM=ON \ | ||
-DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
-DSHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY=OFF \ | ||
.. | ||
make -j2 | ||
make install |
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,60 @@ | ||
# Copyright (c) 2022-2024 Xiaomi Corporation | ||
message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") | ||
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") | ||
|
||
if(NOT SHERPA_ONNX_ENABLE_WASM) | ||
message(FATAL_ERROR "This file is for WebAssembly.") | ||
endif() | ||
|
||
if(BUILD_SHARED_LIBS) | ||
message(FATAL_ERROR "BUILD_SHARED_LIBS should be OFF for WebAssembly") | ||
endif() | ||
|
||
set(onnxruntime_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.0/onnxruntime-wasm-static_lib-simd-1.17.0.zip") | ||
set(onnxruntime_URL2 "https://hub.nuaa.cf/csukuangfj/onnxruntime-libs/releases/download/v1.17.0/onnxruntime-wasm-static_lib-simd-1.17.0.zip") | ||
set(onnxruntime_HASH "SHA256=0ee6120d2ade093eff731af792fd137ac2db580eb2dc5b8bf39e0897b0d7afd9") | ||
|
||
# If you don't have access to the Internet, | ||
# please download onnxruntime to one of the following locations. | ||
# You can add more if you want. | ||
set(possible_file_locations | ||
$ENV{HOME}/Downloads/onnxruntime-wasm-static_lib-simd-1.17.0.zip | ||
${CMAKE_SOURCE_DIR}/onnxruntime-wasm-static_lib-simd-1.17.0.zip | ||
${CMAKE_BINARY_DIR}/onnxruntime-wasm-static_lib-simd-1.17.0.zip | ||
/tmp/onnxruntime-wasm-static_lib-simd-1.17.0.zip | ||
/star-fj/fangjun/download/github/onnxruntime-wasm-static_lib-simd-1.17.0.zip | ||
) | ||
|
||
foreach(f IN LISTS possible_file_locations) | ||
if(EXISTS ${f}) | ||
set(onnxruntime_URL "${f}") | ||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL) | ||
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}") | ||
set(onnxruntime_URL2) | ||
break() | ||
endif() | ||
endforeach() | ||
|
||
FetchContent_Declare(onnxruntime | ||
URL | ||
${onnxruntime_URL} | ||
${onnxruntime_URL2} | ||
URL_HASH ${onnxruntime_HASH} | ||
) | ||
|
||
FetchContent_GetProperties(onnxruntime) | ||
if(NOT onnxruntime_POPULATED) | ||
message(STATUS "Downloading onnxruntime from ${onnxruntime_URL}") | ||
FetchContent_Populate(onnxruntime) | ||
endif() | ||
message(STATUS "onnxruntime is downloaded to ${onnxruntime_SOURCE_DIR}") | ||
|
||
# for static libraries, we use onnxruntime_lib_files directly below | ||
include_directories(${onnxruntime_SOURCE_DIR}/include) | ||
|
||
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/lib*.a") | ||
|
||
set(onnxruntime_lib_files ${onnxruntime_lib_files} PARENT_SCOPE) | ||
|
||
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}") | ||
install(FILES ${onnxruntime_lib_files} DESTINATION lib) |
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
Oops, something went wrong.