Skip to content

Commit 3ac114f

Browse files
authored
Support piper-phonemize (k2-fsa#452)
1 parent bb5aa9a commit 3ac114f

17 files changed

+424
-2
lines changed

.github/scripts/test-offline-ctc.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ log "------------------------------------------------------------"
1919
wenet_models=(
2020
sherpa-onnx-zh-wenet-aishell
2121
sherpa-onnx-zh-wenet-aishell2
22-
sherpa-onnx-zh-wenet-wenetspeech
22+
# sherpa-onnx-zh-wenet-wenetspeech
2323
sherpa-onnx-zh-wenet-multi-cn
2424
sherpa-onnx-en-wenet-librispeech
25-
sherpa-onnx-en-wenet-gigaspeech
25+
# sherpa-onnx-en-wenet-gigaspeech
2626
)
2727
for name in ${wenet_models[@]}; do
2828
repo_url=https://huggingface.co/csukuangfj/$name

.github/workflows/arm-linux-gnueabihf.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ jobs:
168168
lib_type=${{ matrix.lib_type }}
169169
if [[ $lib_type == "shared" ]]; then
170170
cp -a build-arm-linux-gnueabihf/install/lib $dst/
171+
rm -v $dst/lib/libasound.so
172+
rm -v $dst/lib/libonnxruntime.so
173+
rm -v $dst/lib/libsherpa-onnx-fst.so
171174
fi
172175
173176
tree $dst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: test-piper-phonemize
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: test-piper-phonemize-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
14+
jobs:
15+
test_piper_phonemize:
16+
name: ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.shared_lib }}
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, macos-latest, windows-latest]
22+
build_type: [Release, Debug]
23+
shared_lib: [ON, OFF]
24+
exclude:
25+
- os: windows-latest
26+
build_type: Debug
27+
shared_lib: OFF
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: ccache
35+
uses: hendrikmuhs/[email protected]
36+
with:
37+
key: ${{ matrix.os }}-${{ matrix.build_type }}-shared-${{ matrix.shared_lib }}
38+
39+
- name: Configure CMake
40+
shell: bash
41+
run: |
42+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
43+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
44+
cmake --version
45+
46+
mkdir build
47+
cd build
48+
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -D SHERPA_ONNX_ENABLE_TESTS=ON -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D BUILD_SHARED_LIBS=${{ matrix.shared_lib }} -DCMAKE_INSTALL_PREFIX=./install ..
49+
50+
- name: Build
51+
shell: bash
52+
run: |
53+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
54+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
55+
cmake --version
56+
57+
cd build
58+
cmake --build . --target install --config ${{ matrix.build_type }}
59+
60+
- name: run test
61+
if: matrix.os != 'windows-latest'
62+
shell: bash
63+
run: |
64+
cd build
65+
66+
ls -lh install/
67+
ls -lh install/share
68+
ls -lh install/share/espeak-ng-data/
69+
70+
./bin/piper-phonemize-test
71+
72+
- name: run test
73+
if: matrix.os == 'windows-latest'
74+
shell: bash
75+
run: |
76+
cd build
77+
78+
ls -lh install/
79+
ls -lh install/share
80+
ls -lh install/share/espeak-ng-data/
81+
82+
./bin/${{ matrix.build_type }}/piper-phonemize-test

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ endif()
159159
include(kaldi-native-fbank)
160160
include(kaldi-decoder)
161161
include(onnxruntime)
162+
set(ONNXRUNTIME_DIR ${onnxruntime_SOURCE_DIR})
163+
message(STATUS "ONNXRUNTIME_DIR: ${ONNXRUNTIME_DIR}")
162164

163165
if(SHERPA_ONNX_ENABLE_PORTAUDIO)
164166
include(portaudio)
@@ -178,6 +180,11 @@ if(SHERPA_ONNX_ENABLE_WEBSOCKET)
178180
include(asio)
179181
endif()
180182

183+
include(espeak-ng-for-piper)
184+
set(ESPEAK_NG_DIR ${espeak_ng_SOURCE_DIR})
185+
message(STATUS "ESPEAK_NG_DIR: ${ESPEAK_NG_DIR}")
186+
include(piper-phonemize)
187+
181188
add_subdirectory(sherpa-onnx)
182189

183190
if(SHERPA_ONNX_ENABLE_C_API)

build-aarch64-linux-gnu.sh

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then
4545
fi
4646

4747
cmake \
48+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
49+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
50+
-DBUILD_ESPEAK_NG_EXE=OFF \
51+
-DBUILD_ESPEAK_NG_TESTS=OFF \
4852
-DCMAKE_INSTALL_PREFIX=./install \
4953
-DCMAKE_BUILD_TYPE=Release \
5054
-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \

build-android-arm64-v8a.sh

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
7272
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
7373

7474
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
75+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
76+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
77+
-DBUILD_ESPEAK_NG_EXE=OFF \
78+
-DBUILD_ESPEAK_NG_TESTS=OFF \
7579
-DCMAKE_BUILD_TYPE=Release \
7680
-DBUILD_SHARED_LIBS=ON \
7781
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \

build-android-armv7-eabi.sh

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
7373
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
7474

7575
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
76+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
77+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
78+
-DBUILD_ESPEAK_NG_EXE=OFF \
79+
-DBUILD_ESPEAK_NG_TESTS=OFF \
7680
-DCMAKE_BUILD_TYPE=Release \
7781
-DBUILD_SHARED_LIBS=ON \
7882
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \

build-android-x86-64.sh

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
7373
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
7474

7575
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
76+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
77+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
78+
-DBUILD_ESPEAK_NG_EXE=OFF \
79+
-DBUILD_ESPEAK_NG_TESTS=OFF \
7680
-DCMAKE_BUILD_TYPE=Release \
7781
-DBUILD_SHARED_LIBS=ON \
7882
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \

build-android-x86.sh

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
7373
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
7474

7575
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
76+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
77+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
78+
-DBUILD_ESPEAK_NG_EXE=OFF \
79+
-DBUILD_ESPEAK_NG_TESTS=OFF \
7680
-DCMAKE_BUILD_TYPE=Release \
7781
-DBUILD_SHARED_LIBS=ON \
7882
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \

build-arm-linux-gnueabihf.sh

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then
4040
fi
4141

4242
cmake \
43+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
44+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
45+
-DBUILD_ESPEAK_NG_EXE=OFF \
46+
-DBUILD_ESPEAK_NG_TESTS=OFF \
4347
-DCMAKE_INSTALL_PREFIX=./install \
4448
-DCMAKE_BUILD_TYPE=Release \
4549
-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \

build-ios.sh

+12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
5151
#
5252

5353
cmake \
54+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
55+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
56+
-DBUILD_ESPEAK_NG_EXE=OFF \
57+
-DBUILD_ESPEAK_NG_TESTS=OFF \
5458
-S .. \
5559
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
5660
-DPLATFORM=SIMULATOR64 \
@@ -74,6 +78,10 @@ cmake --build build/simulator_x86_64 -j 4 --verbose
7478
echo "Building for simulator (arm64)"
7579

7680
cmake \
81+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
82+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
83+
-DBUILD_ESPEAK_NG_EXE=OFF \
84+
-DBUILD_ESPEAK_NG_TESTS=OFF \
7785
-S .. \
7886
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
7987
-DPLATFORM=SIMULATORARM64 \
@@ -101,6 +109,10 @@ export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/i
101109

102110

103111
cmake \
112+
-DBUILD_PIPER_PHONMIZE_EXE=OFF \
113+
-DBUILD_PIPER_PHONMIZE_TESTS=OFF \
114+
-DBUILD_ESPEAK_NG_EXE=OFF \
115+
-DBUILD_ESPEAK_NG_TESTS=OFF \
104116
-S .. \
105117
-DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
106118
-DPLATFORM=OS64 \

cmake/espeak-ng-for-piper.cmake

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
function(download_espeak_ng_for_piper)
2+
include(FetchContent)
3+
4+
set(espeak_ng_URL "https://github.com/csukuangfj/espeak-ng/archive/c58d2a4a88e9a291ca448f046e15c6188cbd3b3a.zip")
5+
set(espeak_ng_URL2 "")
6+
set(espeak_ng_HASH "SHA256=8a48251e6926133dd91fcf6cb210c7c2e290a9b578d269446e2d32d710b0dfa0")
7+
8+
set(USE_ASYNC OFF CACHE BOOL "" FORCE)
9+
set(USE_MBROLA OFF CACHE BOOL "" FORCE)
10+
set(USE_LIBSONIC OFF CACHE BOOL "" FORCE)
11+
set(USE_LIBPCAUDIO OFF CACHE BOOL "" FORCE)
12+
set(USE_KLATT OFF CACHE BOOL "" FORCE)
13+
set(USE_SPEECHPLAYER OFF CACHE BOOL "" FORCE)
14+
set(EXTRA_cmn ON CACHE BOOL "" FORCE)
15+
set(EXTRA_ru ON CACHE BOOL "" FORCE)
16+
17+
# If you don't have access to the Internet,
18+
# please pre-download kaldi-decoder
19+
set(possible_file_locations
20+
$ENV{HOME}/Downloads/espeak-ng-c58d2a4a88e9a291ca448f046e15c6188cbd3b3a.zip
21+
${PROJECT_SOURCE_DIR}/espeak-ng-c58d2a4a88e9a291ca448f046e15c6188cbd3b3a.zip
22+
${PROJECT_BINARY_DIR}/espeak-ng-c58d2a4a88e9a291ca448f046e15c6188cbd3b3a.zip
23+
/tmp/espeak-ng-c58d2a4a88e9a291ca448f046e15c6188cbd3b3a.zip
24+
/star-fj/fangjun/download/github/espeak-ng-c58d2a4a88e9a291ca448f046e15c6188cbd3b3a.zip
25+
)
26+
27+
foreach(f IN LISTS possible_file_locations)
28+
if(EXISTS ${f})
29+
set(espeak_ng_URL "${f}")
30+
file(TO_CMAKE_PATH "${espeak_ng_URL}" espeak_ng_URL)
31+
message(STATUS "Found local downloaded espeak-ng: ${espeak_ng_URL}")
32+
set(espeak_ng_URL2 )
33+
break()
34+
endif()
35+
endforeach()
36+
37+
FetchContent_Declare(espeak_ng
38+
URL
39+
${espeak_ng_URL}
40+
${espeak_ng_URL2}
41+
URL_HASH ${espeak_ng_HASH}
42+
)
43+
44+
FetchContent_GetProperties(espeak_ng)
45+
if(NOT espeak_ng_POPULATED)
46+
message(STATUS "Downloading espeak-ng from ${espeak_ng_URL}")
47+
FetchContent_Populate(espeak_ng)
48+
endif()
49+
message(STATUS "espeak-ng is downloaded to ${espeak_ng_SOURCE_DIR}")
50+
message(STATUS "espeak-ng binary dir is ${espeak_ng_BINARY_DIR}")
51+
52+
add_subdirectory(${espeak_ng_SOURCE_DIR} ${espeak_ng_BINARY_DIR})
53+
set(espeak_ng_SOURCE_DIR ${espeak_ng_SOURCE_DIR} PARENT_SCOPE)
54+
55+
if(WIN32 AND MSVC)
56+
target_compile_options(ucd PUBLIC
57+
/wd4309
58+
)
59+
60+
target_compile_options(espeak-ng PUBLIC
61+
/wd4005
62+
/wd4018
63+
/wd4067
64+
/wd4068
65+
/wd4090
66+
/wd4101
67+
/wd4244
68+
/wd4267
69+
/wd4996
70+
)
71+
72+
if(TARGET espeak-ng-bin)
73+
target_compile_options(espeak-ng-bin PRIVATE
74+
/wd4244
75+
/wd4024
76+
/wd4047
77+
/wd4067
78+
/wd4267
79+
/wd4996
80+
)
81+
endif()
82+
endif()
83+
84+
if(UNIX AND NOT APPLE)
85+
target_compile_options(espeak-ng PRIVATE
86+
-Wno-unused-result
87+
-Wno-format-overflow
88+
-Wno-format-truncation
89+
-Wno-maybe-uninitialized
90+
-Wno-format
91+
)
92+
93+
if(TARGET espeak-ng-bin)
94+
target_compile_options(espeak-ng-bin PRIVATE
95+
-Wno-unused-result
96+
)
97+
endif()
98+
endif()
99+
100+
target_include_directories(espeak-ng
101+
INTERFACE
102+
${espeak_ng_SOURCE_DIR}/src/include
103+
${espeak_ng_SOURCE_DIR}/src/ucd-tools/src/include
104+
)
105+
106+
if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32)
107+
install(TARGETS
108+
espeak-ng
109+
DESTINATION ..)
110+
else()
111+
install(TARGETS
112+
espeak-ng
113+
DESTINATION lib)
114+
endif()
115+
116+
if(NOT BUILD_SHARED_LIBS)
117+
install(TARGETS ucd DESTINATION lib)
118+
endif()
119+
120+
if(WIN32 AND BUILD_SHARED_LIBS)
121+
install(TARGETS
122+
espeak-ng
123+
DESTINATION bin)
124+
endif()
125+
endfunction()
126+
127+
download_espeak_ng_for_piper()

cmake/kaldi-decoder.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ function(download_kaldi_decoder)
4747
include_directories(${kaldi_decoder_SOURCE_DIR})
4848
add_subdirectory(${kaldi_decoder_SOURCE_DIR} ${kaldi_decoder_BINARY_DIR} EXCLUDE_FROM_ALL)
4949

50+
if(WIN32 AND MSVC)
51+
target_compile_options(kaldi-decoder-core PUBLIC
52+
/wd4018
53+
/wd4291
54+
)
55+
endif()
56+
5057
target_include_directories(kaldi-decoder-core
5158
INTERFACE
5259
${kaldi-decoder_SOURCE_DIR}/

cmake/onnxruntime.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function(download_onnxruntime)
9494
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
9595
message(FATAL_ERROR "Only support Linux, macOS, and Windows at present. Will support other OSes later")
9696
endif()
97+
set(onnxruntime_SOURCE_DIR ${onnxruntime_SOURCE_DIR} PARENT_SCOPE)
9798
endfunction()
9899

99100
# First, we try to locate the header and the lib if the use has already

0 commit comments

Comments
 (0)