Skip to content

Commit

Permalink
Support including TTS conditionally. (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Mar 26, 2024
1 parent bd66f7a commit 4e040c5
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 77 deletions.
49 changes: 46 additions & 3 deletions .github/workflows/build-xcframework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,45 @@ concurrency:

jobs:
build_xcframework:
name: Build xcframework on ${{ matrix.os }}
name: tts-${{ matrix.with_tts }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest]
with_tts: [ON, OFF]

steps:
- uses: actions/checkout@v4

- name: Build iOS
if: matrix.with_tts == 'ON'
shell: bash
run: |
./build-ios.sh
- name: Build iOS (No tts)
if: matrix.with_tts == 'OFF'
shell: bash
run: |
./build-ios-no-tts.sh
- name: Display artifacts
if: matrix.with_tts == 'ON'
shell: bash
run: |
brew install tree
tree -L 2 ./build-ios
- name: Display artifacts
if: matrix.with_tts == 'OFF'
shell: bash
run: |
brew install tree
tree -L 2 ./build-ios-no-tts
- name: Package artifacts
if: matrix.with_tts == 'ON'
shell: bash
run: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
Expand All @@ -71,11 +88,37 @@ jobs:
ls -lh
- name: Package artifacts
if: matrix.with_tts == 'OFF'
shell: bash
run: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
echo "SHERPA_ONNX_VERSION=$SHERPA_ONNX_VERSION" >> "$GITHUB_ENV"
rm -rf build-ios-no-tts/build
rm -rf build-ios-no-tts/install
rm -rf build-ios-no-tts/ios-onnxruntime/.git
tree build-ios-no-tts
filename=sherpa-onnx-${SHERPA_ONNX_VERSION}-ios-no-tts.tar.bz2
tar cjvf $filename ./build-ios-no-tts
ls -lh
- uses: actions/upload-artifact@v4
if: matrix.with_tts == 'ON'
with:
name: sherpa-onnx-ios-libs
path: ./build-ios

- uses: actions/upload-artifact@v4
if: matrix.with_tts == 'OFF'
with:
name: sherpa-onnx-ios-libs-no-tts
path: ./build-ios-no-tts

# https://huggingface.co/docs/hub/spaces-github-actions
- name: Publish to huggingface
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
Expand All @@ -96,7 +139,7 @@ jobs:
cd huggingface
git lfs pull
cp -v ../sherpa-onnx-*-ios.tar.bz2 ./
cp -v ../sherpa-onnx-*.tar.bz2 ./
git status
git lfs track "*.bz2"
Expand All @@ -113,4 +156,4 @@ jobs:
with:
file_glob: true
overwrite: true
file: sherpa-onnx-*-ios.tar.bz2
file: sherpa-onnx-*.tar.bz2
16 changes: 11 additions & 5 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ concurrency:

jobs:
linux:
name: ${{ matrix.build_type }} ${{ matrix.shared_lib }}
name: ${{ matrix.build_type }} shared-${{ matrix.shared_lib }} tts-${{ matrix.with_tts }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
build_type: [Release, Debug]
shared_lib: [ON, OFF]
with_tts: [ON, OFF]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -93,7 +94,7 @@ jobs:
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
cmake -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
make -j2
make install
Expand All @@ -120,7 +121,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.build_type }}-${{ matrix.shared_lib }}
name: release-${{ matrix.build_type }}-with-shared-lib-${{ matrix.shared_lib }}-with-tts-${{ matrix.with_tts }}
path: build/bin/*

- name: Test spoken language identification (C API)
Expand Down Expand Up @@ -175,6 +176,7 @@ jobs:
.github/scripts/test-offline-ctc.sh
- name: Test offline TTS
if: matrix.with_tts == 'ON'
shell: bash
run: |
export PATH=$PWD/build/bin:$PATH
Expand Down Expand Up @@ -226,7 +228,11 @@ jobs:
suffix=static
fi
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-x64-$suffix
if [[ ${{ matrix.with_tts }} ]]; then
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-x64-$suffix
else
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-linux-x64-$suffix-no-tts
fi
mkdir $dst
cp -a build/install/bin $dst/
Expand Down Expand Up @@ -278,6 +284,6 @@ jobs:

- uses: actions/upload-artifact@v4
with:
name: tts-generated-test-files-${{ matrix.build_type }}-${{ matrix.shared_lib }}
name: tts-generated-test-files-${{ matrix.build_type }}-${{ matrix.shared_lib }}-with-tts-${{ matrix.with_tts }}
path: tts

14 changes: 10 additions & 4 deletions .github/workflows/macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ concurrency:
jobs:
macos:
runs-on: ${{ matrix.os }}
name: ${{ matrix.build_type }} ${{ matrix.lib_type }}
name: ${{ matrix.build_type }} ${{ matrix.lib_type }} tts-${{ matrix.with_tts }}
strategy:
fail-fast: false
matrix:
os: [macos-latest]
build_type: [Release, Debug]
lib_type: [static, shared]
with_tts: [ON, OFF]

steps:
- uses: actions/checkout@v4
Expand All @@ -61,7 +62,7 @@ jobs:
- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.lib_type }}
key: ${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.lib_type }}-tts-${{ matrix.with_tts }}

- name: Configure CMake
shell: bash
Expand All @@ -79,7 +80,7 @@ jobs:
BUILD_SHARED_LIBS=ON
fi
cmake -D BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DCMAKE_INSTALL_PREFIX=./install ..
cmake -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DCMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for macos
shell: bash
Expand Down Expand Up @@ -135,6 +136,7 @@ jobs:
.github/scripts/test-online-ctc.sh
- name: Test offline TTS
if: matrix.with_tts == 'ON'
shell: bash
run: |
export PATH=$PWD/build/bin:$PATH
Expand Down Expand Up @@ -196,7 +198,11 @@ jobs:
run: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-osx-universal2-${{ matrix.lib_type }}
if [[ ${{ matrix.with_tts }} ]]; then
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-osx-universal2-${{ matrix.lib_type }}
else
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-osx-universal2-${{ matrix.lib_type }}-no-tts
fi
mkdir $dst
cp -a build/install/bin $dst/
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/windows-x64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ concurrency:

jobs:
windows_x64:
name: ${{ matrix.shared_lib }}
name: shared-${{ matrix.shared_lib }} tts-${{ matrix.with_tts }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
shared_lib: [ON, OFF]
with_tts: [ON, OFF]

steps:
- uses: actions/checkout@v4
Expand All @@ -58,7 +59,8 @@ jobs:
run: |
mkdir build
cd build
cmake -A x64 -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
cmake -A x64 -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for windows
shell: bash
run: |
Expand Down Expand Up @@ -93,6 +95,7 @@ jobs:
.github/scripts/test-online-ctc.sh
- name: Test offline TTS
if: matrix.with_tts == 'ON'
shell: bash
run: |
export PATH=$PWD/build/bin/Release:$PATH
Expand Down Expand Up @@ -155,9 +158,15 @@ jobs:
shared_lib=${{ matrix.shared_lib }}
if [[ $shared_lib == "ON" ]]; then
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x64-shared
suffix=shared
else
suffix=static
fi
if [[ ${{ matrix.with_tts }} ]]; then
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x64-$suffix
else
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x64-static
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x64-$suffix-no-tts
fi
mkdir $dst
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/windows-x86.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ concurrency:

jobs:
windows_x86:
name: Windows x86
name: shared-${{ matrix.shared_lib }} tts-${{ matrix.with_tts }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
shared_lib: [ON, OFF]
with_tts: [ON, OFF]

steps:
- uses: actions/checkout@v4
Expand All @@ -58,7 +59,7 @@ jobs:
run: |
mkdir build
cd build
cmake -A Win32 -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -D CMAKE_INSTALL_PREFIX=./install ..
cmake -A Win32 -DSHERPA_ONNX_ENABLE_TTS=${{ matrix.with_tts }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -D CMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-onnx for windows
shell: bash
Expand Down Expand Up @@ -94,6 +95,7 @@ jobs:
.github/scripts/test-online-ctc.sh
- name: Test offline TTS
if: matrix.with_tts == 'ON'
shell: bash
run: |
export PATH=$PWD/build/bin/Release:$PATH
Expand Down Expand Up @@ -157,10 +159,17 @@ jobs:
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x86
shared_lib=${{ matrix.shared_lib }}
if [[ $shared_lib == "ON" ]]; then
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x86-shared
suffix=shared
else
suffix=static
fi
if [[ ${{ matrix.with_tts }} ]]; then
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x86-$suffix
else
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x86-static
dst=sherpa-onnx-${SHERPA_ONNX_VERSION}-win-x86-$suffix-no-tts
fi
mkdir $dst
Expand Down
34 changes: 29 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ option(SHERPA_ONNX_ENABLE_WASM_ASR "Whether to enable WASM for ASR" OFF)
option(SHERPA_ONNX_ENABLE_WASM_KWS "Whether to enable WASM for KWS" OFF)
option(SHERPA_ONNX_ENABLE_WASM_NODEJS "Whether to enable WASM for NodeJS" OFF)
option(SHERPA_ONNX_ENABLE_BINARY "Whether to build binaries" ON)
option(SHERPA_ONNX_ENABLE_TTS "Whether to build TTS related code" ON)
option(SHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY "True to link libstdc++ statically. Used only when BUILD_SHARED_LIBS is OFF on Linux" ON)
option(SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE "True to use pre-installed onnxruntime if available" ON)

Expand Down Expand Up @@ -111,10 +112,26 @@ message(STATUS "SHERPA_ONNX_ENABLE_GPU ${SHERPA_ONNX_ENABLE_GPU}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM ${SHERPA_ONNX_ENABLE_WASM}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_TTS ${SHERPA_ONNX_ENABLE_WASM_TTS}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_ASR ${SHERPA_ONNX_ENABLE_WASM_ASR}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_KWS ${SHERPA_ONNX_ENABLE_WASM_KWS}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_NODEJS ${SHERPA_ONNX_ENABLE_WASM_NODEJS}")
message(STATUS "SHERPA_ONNX_ENABLE_BINARY ${SHERPA_ONNX_ENABLE_BINARY}")
message(STATUS "SHERPA_ONNX_ENABLE_TTS ${SHERPA_ONNX_ENABLE_TTS}")
message(STATUS "SHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY ${SHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY}")
message(STATUS "SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE ${SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE}")

if(SHERPA_ONNX_ENABLE_TTS)
message(STATUS "TTS is enabled")
add_definitions(-DSHERPA_ONNX_ENABLE_TTS=1)
else()
message(WARNING "TTS is disabled")
add_definitions(-DSHERPA_ONNX_ENABLE_TTS=0)
endif()

if(SHERPA_ONNX_ENABLE_WASM_TTS)
if(NOT SHERPA_ONNX_ENABLE_TTS)
message(FATAL_ERROR "Please set SHERPA_ONNX_ENABLE_TTS to ON if you want to build wasm TTS")
endif()

if(NOT SHERPA_ONNX_ENABLE_WASM)
message(FATAL_ERROR "Please set SHERPA_ONNX_ENABLE_WASM to ON if you enable WASM for TTS")
endif()
Expand Down Expand Up @@ -238,10 +255,12 @@ if(SHERPA_ONNX_ENABLE_WEBSOCKET)
include(asio)
endif()

include(espeak-ng-for-piper)
set(ESPEAK_NG_DIR ${espeak_ng_SOURCE_DIR})
message(STATUS "ESPEAK_NG_DIR: ${ESPEAK_NG_DIR}")
include(piper-phonemize)
if(SHERPA_ONNX_ENABLE_TTS)
include(espeak-ng-for-piper)
set(ESPEAK_NG_DIR ${espeak_ng_SOURCE_DIR})
message(STATUS "ESPEAK_NG_DIR: ${ESPEAK_NG_DIR}")
include(piper-phonemize)
endif()

add_subdirectory(sherpa-onnx)

Expand All @@ -266,7 +285,12 @@ if(NOT BUILD_SHARED_LIBS)
endif()

# See https://people.freedesktop.org/~dbn/pkg-config-guide.html
configure_file(cmake/sherpa-onnx.pc.in ${PROJECT_BINARY_DIR}/sherpa-onnx.pc @ONLY)
if(SHERPA_ONNX_ENABLE_TTS)
configure_file(cmake/sherpa-onnx.pc.in ${PROJECT_BINARY_DIR}/sherpa-onnx.pc @ONLY)
else()
configure_file(cmake/sherpa-onnx-no-tts.pc.in ${PROJECT_BINARY_DIR}/sherpa-onnx.pc @ONLY)
endif()

install(
FILES
${PROJECT_BINARY_DIR}/sherpa-onnx.pc
Expand Down
Loading

0 comments on commit 4e040c5

Please sign in to comment.