From db28b0294b7f936d1c0edd2558532d45c5b05938 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Mon, 1 Sep 2025 11:33:00 +0800 Subject: [PATCH 1/2] Fix linking --- CMakeLists.txt | 3 ++- build-ios.sh | 4 +++- build-swift-macos.sh | 1 + c-api-examples/Makefile | 2 +- cmake/sherpa-onnx-static.pc.in | 2 +- .../NonStreamingSpeechRecognition/sherpa-onnx-deps.props | 1 + mfc-examples/NonStreamingTextToSpeech/sherpa-onnx-deps.props | 1 + .../StreamingSpeechRecognition/sherpa-onnx-deps.props | 1 + sherpa-onnx/csrc/CMakeLists.txt | 5 +++-- sherpa-onnx/pascal-api/sherpa_onnx.pas | 1 + 10 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e27f49023..3d1924ef35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -372,7 +372,6 @@ endif() include(kaldi-native-fbank) include(kaldi-decoder) include(onnxruntime) -include(cppinyin) include(simple-sentencepiece) set(ONNXRUNTIME_DIR ${onnxruntime_SOURCE_DIR}) message(STATUS "ONNXRUNTIME_DIR: ${ONNXRUNTIME_DIR}") @@ -398,6 +397,8 @@ if(SHERPA_ONNX_ENABLE_WEBSOCKET) endif() if(SHERPA_ONNX_ENABLE_TTS) + include(cppinyin) + include(espeak-ng-for-piper) set(ESPEAK_NG_DIR ${espeak_ng_SOURCE_DIR}) message(STATUS "ESPEAK_NG_DIR: ${ESPEAK_NG_DIR}") diff --git a/build-ios.sh b/build-ios.sh index 6beb99a1a0..fee6400963 100755 --- a/build-ios.sh +++ b/build-ios.sh @@ -127,7 +127,7 @@ cmake --build build/os64 --target install echo "Generate xcframework" mkdir -p "build/simulator/lib" -for f in libkaldi-native-fbank-core.a libkissfft-float.a libsherpa-onnx-c-api.a libsherpa-onnx-core.a \ +for f in libcppinyin_core.a libkaldi-native-fbank-core.a libkissfft-float.a libsherpa-onnx-c-api.a libsherpa-onnx-core.a \ libsherpa-onnx-fstfar.a libssentencepiece_core.a \ libsherpa-onnx-fst.a libsherpa-onnx-kaldifst-core.a libkaldi-decoder-core.a \ libucd.a libpiper_phonemize.a libespeak-ng.a; do @@ -139,6 +139,7 @@ done # Merge archive first, because the following xcodebuild create xcframework # cannot accept multi archive with the same architecture. libtool -static -o build/simulator/sherpa-onnx.a \ + build/simulator/lib/libcppinyin_core.a \ build/simulator/lib/libkaldi-native-fbank-core.a \ build/simulator/lib/libkissfft-float.a \ build/simulator/lib/libsherpa-onnx-c-api.a \ @@ -153,6 +154,7 @@ libtool -static -o build/simulator/sherpa-onnx.a \ build/simulator/lib/libssentencepiece_core.a libtool -static -o build/os64/sherpa-onnx.a \ + build/os64/lib/libcppinyin_core.a \ build/os64/lib/libkaldi-native-fbank-core.a \ build/os64/lib/libkissfft-float.a \ build/os64/lib/libsherpa-onnx-c-api.a \ diff --git a/build-swift-macos.sh b/build-swift-macos.sh index 1e1e8e9c07..8fef5da7e7 100755 --- a/build-swift-macos.sh +++ b/build-swift-macos.sh @@ -27,6 +27,7 @@ make install rm -fv ./install/include/cargs.h libtool -static -o ./install/lib/libsherpa-onnx.a \ + ./install/lib/libcppinyin_core.a \ ./install/lib/libsherpa-onnx-c-api.a \ ./install/lib/libsherpa-onnx-core.a \ ./install/lib/libkaldi-native-fbank-core.a \ diff --git a/c-api-examples/Makefile b/c-api-examples/Makefile index cbaaf63c05..6480e9851b 100644 --- a/c-api-examples/Makefile +++ b/c-api-examples/Makefile @@ -4,7 +4,7 @@ CUR_DIR :=$(shell pwd) CFLAGS := -I ../ -I ../build/_deps/cargs-src/include/ LDFLAGS := -L ../build/lib LDFLAGS += -L ../build/_deps/onnxruntime-src/lib -LDFLAGS += -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lpiper_phonemize -lespeak-ng -lucd -lcargs -lonnxruntime +LDFLAGS += -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lpiper_phonemize -lespeak-ng -lucd -lcargs -lonnxruntime -lcppinyin_core LDFLAGS += -framework Foundation LDFLAGS += -lc++ LDFLAGS += -Wl,-rpath,${CUR_DIR}/../build/lib diff --git a/cmake/sherpa-onnx-static.pc.in b/cmake/sherpa-onnx-static.pc.in index 42beb084ab..061905fce6 100644 --- a/cmake/sherpa-onnx-static.pc.in +++ b/cmake/sherpa-onnx-static.pc.in @@ -22,4 +22,4 @@ Cflags: -I"${includedir}" # Note: -lcargs is required only for the following file # https://github.com/k2-fsa/sherpa-onnx/blob/master/c-api-examples/decode-file-c-api.c # We add it here so that users don't need to specify -lcargs when compiling decode-file-c-api.c -Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@ +Libs: -L"${libdir}" -lsherpa-onnx-c-api -lsherpa-onnx-core -lkaldi-decoder-core -lsherpa-onnx-kaldifst-core -lsherpa-onnx-fstfar -lsherpa-onnx-fst -lkaldi-native-fbank-core -lkissfft-float -lpiper_phonemize -lespeak-ng -lucd -lonnxruntime -lssentencepiece_core -lcppinyin_core -Wl,-rpath,${libdir} @SHERPA_ONNX_PKG_WITH_CARGS@ @SHERPA_ONNX_PKG_CONFIG_EXTRA_LIBS@ diff --git a/mfc-examples/NonStreamingSpeechRecognition/sherpa-onnx-deps.props b/mfc-examples/NonStreamingSpeechRecognition/sherpa-onnx-deps.props index 9b35d475df..cc0aa01423 100644 --- a/mfc-examples/NonStreamingSpeechRecognition/sherpa-onnx-deps.props +++ b/mfc-examples/NonStreamingSpeechRecognition/sherpa-onnx-deps.props @@ -15,6 +15,7 @@ sherpa-onnx-fst.lib; kaldi-native-fbank-core.lib; kissfft-float.lib; + cppinyin_core.lib; onnxruntime.lib; piper_phonemize.lib; espeak-ng.lib; diff --git a/mfc-examples/NonStreamingTextToSpeech/sherpa-onnx-deps.props b/mfc-examples/NonStreamingTextToSpeech/sherpa-onnx-deps.props index 9b35d475df..cc0aa01423 100644 --- a/mfc-examples/NonStreamingTextToSpeech/sherpa-onnx-deps.props +++ b/mfc-examples/NonStreamingTextToSpeech/sherpa-onnx-deps.props @@ -15,6 +15,7 @@ sherpa-onnx-fst.lib; kaldi-native-fbank-core.lib; kissfft-float.lib; + cppinyin_core.lib; onnxruntime.lib; piper_phonemize.lib; espeak-ng.lib; diff --git a/mfc-examples/StreamingSpeechRecognition/sherpa-onnx-deps.props b/mfc-examples/StreamingSpeechRecognition/sherpa-onnx-deps.props index 9b35d475df..cc0aa01423 100644 --- a/mfc-examples/StreamingSpeechRecognition/sherpa-onnx-deps.props +++ b/mfc-examples/StreamingSpeechRecognition/sherpa-onnx-deps.props @@ -15,6 +15,7 @@ sherpa-onnx-fst.lib; kaldi-native-fbank-core.lib; kissfft-float.lib; + cppinyin_core.lib; onnxruntime.lib; piper_phonemize.lib; espeak-ng.lib; diff --git a/sherpa-onnx/csrc/CMakeLists.txt b/sherpa-onnx/csrc/CMakeLists.txt index ae451d7572..0d3cf0489a 100644 --- a/sherpa-onnx/csrc/CMakeLists.txt +++ b/sherpa-onnx/csrc/CMakeLists.txt @@ -268,7 +268,6 @@ if(ANDROID_NDK) endif() target_link_libraries(sherpa-onnx-core - cppinyin_core kaldi-native-fbank-core kaldi-decoder-core ssentencepiece_core @@ -311,7 +310,9 @@ endif() target_link_libraries(sherpa-onnx-core fstfar fst) if(SHERPA_ONNX_ENABLE_TTS) - target_link_libraries(sherpa-onnx-core piper_phonemize) + target_link_libraries(sherpa-onnx-core + cppinyin_core + piper_phonemize) endif() target_link_libraries(sherpa-onnx-core cppjieba) diff --git a/sherpa-onnx/pascal-api/sherpa_onnx.pas b/sherpa-onnx/pascal-api/sherpa_onnx.pas index fcec89ecda..0aca65b92e 100644 --- a/sherpa-onnx/pascal-api/sherpa_onnx.pas +++ b/sherpa-onnx/pascal-api/sherpa_onnx.pas @@ -663,6 +663,7 @@ implementation {$linklib sherpa-onnx-kaldifst-core} {$linklib sherpa-onnx-fstfar} {$linklib sherpa-onnx-fst} + {$linklib cppinyin_core} {$linklib kissfft-float} {$linklib kaldi-native-fbank-core} {$linklib piper_phonemize} From 3ec0f3f6fb4a0e77a69ce946189a45f6c0bde4ff Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Mon, 1 Sep 2025 11:47:29 +0800 Subject: [PATCH 2/2] small fixes --- sherpa-onnx/c-api/cxx-api.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sherpa-onnx/c-api/cxx-api.cc b/sherpa-onnx/c-api/cxx-api.cc index d334b953d6..44e59609c2 100644 --- a/sherpa-onnx/c-api/cxx-api.cc +++ b/sherpa-onnx/c-api/cxx-api.cc @@ -354,11 +354,11 @@ OfflineRecognizerResult OfflineRecognizer::GetResult( ans.lang = r->lang ? r->lang : ""; ans.emotion = r->emotion ? r->emotion : ""; ans.event = r->event ? r->event : ""; - } - if (r->durations) { - ans.durations.resize(r->count); - std::copy(r->durations, r->durations + r->count, ans.durations.data()); + if (r->durations) { + ans.durations.resize(r->count); + std::copy(r->durations, r->durations + r->count, ans.durations.data()); + } } SherpaOnnxDestroyOfflineRecognizerResult(r);