Fangjun Kuang
Committed by GitHub

Support piper-phonemize (#452)

@@ -19,10 +19,10 @@ log "------------------------------------------------------------" @@ -19,10 +19,10 @@ log "------------------------------------------------------------"
19 wenet_models=( 19 wenet_models=(
20 sherpa-onnx-zh-wenet-aishell 20 sherpa-onnx-zh-wenet-aishell
21 sherpa-onnx-zh-wenet-aishell2 21 sherpa-onnx-zh-wenet-aishell2
22 -sherpa-onnx-zh-wenet-wenetspeech 22 +# sherpa-onnx-zh-wenet-wenetspeech
23 sherpa-onnx-zh-wenet-multi-cn 23 sherpa-onnx-zh-wenet-multi-cn
24 sherpa-onnx-en-wenet-librispeech 24 sherpa-onnx-en-wenet-librispeech
25 -sherpa-onnx-en-wenet-gigaspeech 25 +# sherpa-onnx-en-wenet-gigaspeech
26 ) 26 )
27 for name in ${wenet_models[@]}; do 27 for name in ${wenet_models[@]}; do
28 repo_url=https://huggingface.co/csukuangfj/$name 28 repo_url=https://huggingface.co/csukuangfj/$name
@@ -168,6 +168,9 @@ jobs: @@ -168,6 +168,9 @@ jobs:
168 lib_type=${{ matrix.lib_type }} 168 lib_type=${{ matrix.lib_type }}
169 if [[ $lib_type == "shared" ]]; then 169 if [[ $lib_type == "shared" ]]; then
170 cp -a build-arm-linux-gnueabihf/install/lib $dst/ 170 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
171 fi 174 fi
172 175
173 tree $dst 176 tree $dst
  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/ccache-action@v1.2
  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
@@ -159,6 +159,8 @@ endif() @@ -159,6 +159,8 @@ endif()
159 include(kaldi-native-fbank) 159 include(kaldi-native-fbank)
160 include(kaldi-decoder) 160 include(kaldi-decoder)
161 include(onnxruntime) 161 include(onnxruntime)
  162 +set(ONNXRUNTIME_DIR ${onnxruntime_SOURCE_DIR})
  163 +message(STATUS "ONNXRUNTIME_DIR: ${ONNXRUNTIME_DIR}")
162 164
163 if(SHERPA_ONNX_ENABLE_PORTAUDIO) 165 if(SHERPA_ONNX_ENABLE_PORTAUDIO)
164 include(portaudio) 166 include(portaudio)
@@ -178,6 +180,11 @@ if(SHERPA_ONNX_ENABLE_WEBSOCKET) @@ -178,6 +180,11 @@ if(SHERPA_ONNX_ENABLE_WEBSOCKET)
178 include(asio) 180 include(asio)
179 endif() 181 endif()
180 182
  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 +
181 add_subdirectory(sherpa-onnx) 188 add_subdirectory(sherpa-onnx)
182 189
183 if(SHERPA_ONNX_ENABLE_C_API) 190 if(SHERPA_ONNX_ENABLE_C_API)
@@ -45,6 +45,10 @@ if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then @@ -45,6 +45,10 @@ if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then
45 fi 45 fi
46 46
47 cmake \ 47 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 \
48 -DCMAKE_INSTALL_PREFIX=./install \ 52 -DCMAKE_INSTALL_PREFIX=./install \
49 -DCMAKE_BUILD_TYPE=Release \ 53 -DCMAKE_BUILD_TYPE=Release \
50 -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \ 54 -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \
@@ -72,6 +72,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR" @@ -72,6 +72,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
72 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" 72 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
73 73
74 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 74 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 \
75 -DCMAKE_BUILD_TYPE=Release \ 79 -DCMAKE_BUILD_TYPE=Release \
76 -DBUILD_SHARED_LIBS=ON \ 80 -DBUILD_SHARED_LIBS=ON \
77 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ 81 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \
@@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR" @@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
73 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" 73 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
74 74
75 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 75 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 \
76 -DCMAKE_BUILD_TYPE=Release \ 80 -DCMAKE_BUILD_TYPE=Release \
77 -DBUILD_SHARED_LIBS=ON \ 81 -DBUILD_SHARED_LIBS=ON \
78 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ 82 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \
@@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR" @@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
73 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" 73 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
74 74
75 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 75 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 \
76 -DCMAKE_BUILD_TYPE=Release \ 80 -DCMAKE_BUILD_TYPE=Release \
77 -DBUILD_SHARED_LIBS=ON \ 81 -DBUILD_SHARED_LIBS=ON \
78 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ 82 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \
@@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR" @@ -73,6 +73,10 @@ echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
73 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" 73 echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
74 74
75 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 75 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 \
76 -DCMAKE_BUILD_TYPE=Release \ 80 -DCMAKE_BUILD_TYPE=Release \
77 -DBUILD_SHARED_LIBS=ON \ 81 -DBUILD_SHARED_LIBS=ON \
78 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ 82 -DSHERPA_ONNX_ENABLE_PYTHON=OFF \
@@ -40,6 +40,10 @@ if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then @@ -40,6 +40,10 @@ if [[ x"$BUILD_SHARED_LIBS" == x"" ]]; then
40 fi 40 fi
41 41
42 cmake \ 42 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 \
43 -DCMAKE_INSTALL_PREFIX=./install \ 47 -DCMAKE_INSTALL_PREFIX=./install \
44 -DCMAKE_BUILD_TYPE=Release \ 48 -DCMAKE_BUILD_TYPE=Release \
45 -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \ 49 -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \
@@ -51,6 +51,10 @@ echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" @@ -51,6 +51,10 @@ echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
51 # 51 #
52 52
53 cmake \ 53 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 \
54 -S .. \ 58 -S .. \
55 -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ 59 -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
56 -DPLATFORM=SIMULATOR64 \ 60 -DPLATFORM=SIMULATOR64 \
@@ -74,6 +78,10 @@ cmake --build build/simulator_x86_64 -j 4 --verbose @@ -74,6 +78,10 @@ cmake --build build/simulator_x86_64 -j 4 --verbose
74 echo "Building for simulator (arm64)" 78 echo "Building for simulator (arm64)"
75 79
76 cmake \ 80 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 \
77 -S .. \ 85 -S .. \
78 -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ 86 -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
79 -DPLATFORM=SIMULATORARM64 \ 87 -DPLATFORM=SIMULATORARM64 \
@@ -101,6 +109,10 @@ export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/i @@ -101,6 +109,10 @@ export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/i
101 109
102 110
103 cmake \ 111 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 \
104 -S .. \ 116 -S .. \
105 -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ 117 -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \
106 -DPLATFORM=OS64 \ 118 -DPLATFORM=OS64 \
  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()
@@ -47,6 +47,13 @@ function(download_kaldi_decoder) @@ -47,6 +47,13 @@ function(download_kaldi_decoder)
47 include_directories(${kaldi_decoder_SOURCE_DIR}) 47 include_directories(${kaldi_decoder_SOURCE_DIR})
48 add_subdirectory(${kaldi_decoder_SOURCE_DIR} ${kaldi_decoder_BINARY_DIR} EXCLUDE_FROM_ALL) 48 add_subdirectory(${kaldi_decoder_SOURCE_DIR} ${kaldi_decoder_BINARY_DIR} EXCLUDE_FROM_ALL)
49 49
  50 + if(WIN32 AND MSVC)
  51 + target_compile_options(kaldi-decoder-core PUBLIC
  52 + /wd4018
  53 + /wd4291
  54 + )
  55 + endif()
  56 +
50 target_include_directories(kaldi-decoder-core 57 target_include_directories(kaldi-decoder-core
51 INTERFACE 58 INTERFACE
52 ${kaldi-decoder_SOURCE_DIR}/ 59 ${kaldi-decoder_SOURCE_DIR}/
@@ -94,6 +94,7 @@ function(download_onnxruntime) @@ -94,6 +94,7 @@ function(download_onnxruntime)
94 message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") 94 message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
95 message(FATAL_ERROR "Only support Linux, macOS, and Windows at present. Will support other OSes later") 95 message(FATAL_ERROR "Only support Linux, macOS, and Windows at present. Will support other OSes later")
96 endif() 96 endif()
  97 + set(onnxruntime_SOURCE_DIR ${onnxruntime_SOURCE_DIR} PARENT_SCOPE)
97 endfunction() 98 endfunction()
98 99
99 # First, we try to locate the header and the lib if the use has already 100 # First, we try to locate the header and the lib if the use has already
  1 +function(download_piper_phonemize)
  2 + include(FetchContent)
  3 +
  4 + set(piper_phonemize_URL "https://github.com/csukuangfj/piper-phonemize/archive/6383e46b62e94c5cafc0c6a6212249ed8b9ed8d0.zip")
  5 + set(piper_phonemize_URL2 "")
  6 + set(piper_phonemize_HASH "SHA256=6fbacf540b03f00d1386bb372fb7090e3bb852bd019d74e615d3f161f728bc93")
  7 +
  8 + # If you don't have access to the Internet,
  9 + # please pre-download kaldi-decoder
  10 + set(possible_file_locations
  11 + $ENV{HOME}/Downloads/piper-phonemize-6383e46b62e94c5cafc0c6a6212249ed8b9ed8d0.zip
  12 + ${PROJECT_SOURCE_DIR}/piper-phonemize-6383e46b62e94c5cafc0c6a6212249ed8b9ed8d0.zip
  13 + ${PROJECT_BINARY_DIR}/piper-phonemize-6383e46b62e94c5cafc0c6a6212249ed8b9ed8d0.zip
  14 + /tmp/piper-phonemize-6383e46b62e94c5cafc0c6a6212249ed8b9ed8d0.zip
  15 + /star-fj/fangjun/download/github/piper-phonemize-6383e46b62e94c5cafc0c6a6212249ed8b9ed8d0.zip
  16 + )
  17 +
  18 + foreach(f IN LISTS possible_file_locations)
  19 + if(EXISTS ${f})
  20 + set(piper_phonemize_URL "${f}")
  21 + file(TO_CMAKE_PATH "${piper_phonemize_URL}" piper_phonemize_URL)
  22 + message(STATUS "Found local downloaded espeak-ng: ${piper_phonemize_URL}")
  23 + set(piper_phonemize_URL2 )
  24 + break()
  25 + endif()
  26 + endforeach()
  27 +
  28 + FetchContent_Declare(piper_phonemize
  29 + URL
  30 + ${piper_phonemize_URL}
  31 + ${piper_phonemize_URL2}
  32 + URL_HASH ${piper_phonemize_HASH}
  33 + )
  34 +
  35 + FetchContent_GetProperties(piper_phonemize)
  36 + if(NOT piper_phonemize_POPULATED)
  37 + message(STATUS "Downloading piper-phonemize from ${piper_phonemize_URL}")
  38 + FetchContent_Populate(piper_phonemize)
  39 + endif()
  40 + message(STATUS "piper-phonemize is downloaded to ${piper_phonemize_SOURCE_DIR}")
  41 + message(STATUS "piper-phonemize binary dir is ${piper_phonemize_BINARY_DIR}")
  42 +
  43 + add_subdirectory(${piper_phonemize_SOURCE_DIR} ${piper_phonemize_BINARY_DIR} EXCLUDE_FROM_ALL)
  44 +
  45 + if(WIN32 AND MSVC)
  46 + target_compile_options(piper_phonemize PUBLIC
  47 + /wd4309
  48 + )
  49 + endif()
  50 +
  51 + target_include_directories(piper_phonemize
  52 + INTERFACE
  53 + ${piper_phonemize_SOURCE_DIR}/src/include
  54 + )
  55 +
  56 + if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32)
  57 + install(TARGETS
  58 + piper_phonemize
  59 + DESTINATION ..)
  60 + else()
  61 + install(TARGETS
  62 + piper_phonemize
  63 + DESTINATION lib)
  64 + endif()
  65 +
  66 + if(WIN32 AND BUILD_SHARED_LIBS)
  67 + install(TARGETS
  68 + piper_phonemize
  69 + DESTINATION bin)
  70 + endif()
  71 +endfunction()
  72 +
  73 +download_piper_phonemize()
@@ -106,6 +106,11 @@ if(SHERPA_ONNX_ENABLE_CHECK) @@ -106,6 +106,11 @@ if(SHERPA_ONNX_ENABLE_CHECK)
106 list(APPEND sources log.cc) 106 list(APPEND sources log.cc)
107 endif() 107 endif()
108 add_library(sherpa-onnx-core ${sources}) 108 add_library(sherpa-onnx-core ${sources})
  109 +if(APPLE)
  110 + target_compile_options(sherpa-onnx-core PRIVATE
  111 + -Wno-deprecated-declarations
  112 + )
  113 +endif()
109 114
110 if(NOT WIN32) 115 if(NOT WIN32)
111 target_link_libraries(sherpa-onnx-core -pthread) 116 target_link_libraries(sherpa-onnx-core -pthread)
@@ -136,6 +141,8 @@ if(SHERPA_ONNX_ENABLE_GPU) @@ -136,6 +141,8 @@ if(SHERPA_ONNX_ENABLE_GPU)
136 ) 141 )
137 endif() 142 endif()
138 143
  144 +target_link_libraries(sherpa-onnx-core piper_phonemize)
  145 +
139 if(SHERPA_ONNX_ENABLE_CHECK) 146 if(SHERPA_ONNX_ENABLE_CHECK)
140 target_compile_definitions(sherpa-onnx-core PUBLIC SHERPA_ONNX_ENABLE_CHECK=1) 147 target_compile_definitions(sherpa-onnx-core PUBLIC SHERPA_ONNX_ENABLE_CHECK=1)
141 148
@@ -343,6 +350,7 @@ if(SHERPA_ONNX_ENABLE_TESTS) @@ -343,6 +350,7 @@ if(SHERPA_ONNX_ENABLE_TESTS)
343 context-graph-test.cc 350 context-graph-test.cc
344 packed-sequence-test.cc 351 packed-sequence-test.cc
345 pad-sequence-test.cc 352 pad-sequence-test.cc
  353 + piper-phonemize-test.cc
346 slice-test.cc 354 slice-test.cc
347 stack-test.cc 355 stack-test.cc
348 transpose-test.cc 356 transpose-test.cc
  1 +// sherpa-onnx/csrc/piper-phonemize-test.cc
  2 +//
  3 +// Copyright (c) 2023 Xiaomi Corporation
  4 +
  5 +#include "espeak-ng/speak_lib.h"
  6 +#include "gtest/gtest.h"
  7 +#include "phoneme_ids.hpp"
  8 +#include "phonemize.hpp"
  9 +#include "sherpa-onnx/csrc/file-utils.h"
  10 +#include "sherpa-onnx/csrc/macros.h"
  11 +
  12 +namespace sherpa_onnx {
  13 +
  14 +TEST(PiperPhonemize, Case1) {
  15 + std::string data_dir = "./install/share/espeak-ng-data";
  16 + if (!FileExists(data_dir + "/en_dict")) {
  17 + SHERPA_ONNX_LOGE("%s/en_dict does not exist. Skipping test",
  18 + data_dir.c_str());
  19 + return;
  20 + }
  21 +
  22 + if (!FileExists(data_dir + "/phontab")) {
  23 + SHERPA_ONNX_LOGE("%s/phontab does not exist. Skipping test",
  24 + data_dir.c_str());
  25 + return;
  26 + }
  27 +
  28 + if (!FileExists(data_dir + "/phonindex")) {
  29 + SHERPA_ONNX_LOGE("%s/phonindex does not exist. Skipping test",
  30 + data_dir.c_str());
  31 + return;
  32 + }
  33 +
  34 + if (!FileExists(data_dir + "/phondata")) {
  35 + SHERPA_ONNX_LOGE("%s/phondata does not exist. Skipping test",
  36 + data_dir.c_str());
  37 + return;
  38 + }
  39 +
  40 + if (!FileExists(data_dir + "/intonations")) {
  41 + SHERPA_ONNX_LOGE("%s/intonations does not exist. Skipping test",
  42 + data_dir.c_str());
  43 + return;
  44 + }
  45 + int32_t result =
  46 + espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, data_dir.c_str(), 0);
  47 + EXPECT_EQ(result, 22050);
  48 +
  49 + piper::eSpeakPhonemeConfig config;
  50 +
  51 + // ./bin/espeak-ng --path ./install/share/espeak-ng-data/ --voices
  52 + // to list available voices
  53 + config.voice = "en-us";
  54 +
  55 + std::vector<std::vector<piper::Phoneme>> phonemes;
  56 + std::string text = "how are you doing?";
  57 + piper::phonemize_eSpeak(text, config, phonemes);
  58 +
  59 + for (int32_t p : phonemes[0]) {
  60 + std::cout << p << " ";
  61 + }
  62 + std::cout << "\n";
  63 +
  64 + std::vector<piper::PhonemeId> phonemeIds;
  65 + std::map<piper::Phoneme, std::size_t> missingPhonemes;
  66 +
  67 + {
  68 + piper::PhonemeIdConfig config;
  69 + phonemes_to_ids(phonemes[0], config, phonemeIds, missingPhonemes);
  70 + }
  71 +
  72 + for (int32_t p : phonemeIds) {
  73 + std::cout << p << " ";
  74 + }
  75 + std::cout << "\n";
  76 +}
  77 +
  78 +} // namespace sherpa_onnx