mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-11-10 13:04:05 +08:00
Fixes #3731 espeak-ng and piper-phonemize are no longer built into sherpa-onnx. Text frontends are now: - **lexicon** — built in, no extra dependency - **phonemize** — phonemize outside sherpa-onnx (e.g. [piper-phonemize](https://github.com/csukuangfj/piper-phonemize)) and pass the result in. That library is GPL, so it stays optional: sherpa-onnx is GPL-free after this PR. ## API - `SherpaOnnxGenerationConfig` gains `phoneme_codepoints` and `tokens` (mutually exclusive alternatives to `text`) - `data_dir` on the TTS model configs is deprecated and ignored; the ABI slot is kept - all bindings updated: C/C++, Python, Java, Kotlin, Go, Rust, C#, Swift, Pascal, Dart/Flutter, node-addon, WASM, HarmonyOS
196 lines
6.9 KiB
Bash
Executable File
196 lines
6.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -ex
|
|
|
|
# If BUILD_SHARED_LIBS is ON, we use libonnxruntime.so
|
|
# If BUILD_SHARED_LIBS is OFF, we use libonnxruntime.a
|
|
#
|
|
# In any case, we will have libsherpa-onnx-jni.so
|
|
#
|
|
# If BUILD_SHARED_LIBS is OFF, then libonnxruntime.a is linked into libsherpa-onnx-jni.so
|
|
# and you only need to copy libsherpa-onnx-jni.so to your Android projects.
|
|
#
|
|
# If BUILD_SHARED_LIBS is ON, then you need to copy both libsherpa-onnx-jni.so
|
|
# and libonnxruntime.so to your Android projects
|
|
#
|
|
if [ -z $BUILD_SHARED_LIBS ]; then
|
|
BUILD_SHARED_LIBS=ON
|
|
fi
|
|
|
|
if [ $BUILD_SHARED_LIBS == ON ]; then
|
|
dir=$PWD/build-android-x86-64
|
|
else
|
|
dir=$PWD/build-android-x86-64-static
|
|
fi
|
|
|
|
if [ -n "${SHERPA_ONNXRUNTIME_LIB_DIR:-}" ] && [ -n "${SHERPA_ONNXRUNTIME_INCLUDE_DIR:-}" ]; then
|
|
if [ ! -d "$SHERPA_ONNXRUNTIME_LIB_DIR" ]; then
|
|
echo "Error: SHERPA_ONNXRUNTIME_LIB_DIR does not exist: $SHERPA_ONNXRUNTIME_LIB_DIR"
|
|
exit 1
|
|
fi
|
|
if [ ! -d "$SHERPA_ONNXRUNTIME_INCLUDE_DIR" ]; then
|
|
echo "Error: SHERPA_ONNXRUNTIME_INCLUDE_DIR does not exist: $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
|
|
exit 1
|
|
fi
|
|
SHERPA_ONNXRUNTIME_LIB_DIR=$(cd "$SHERPA_ONNXRUNTIME_LIB_DIR" && pwd)
|
|
SHERPA_ONNXRUNTIME_INCLUDE_DIR=$(cd "$SHERPA_ONNXRUNTIME_INCLUDE_DIR" && pwd)
|
|
export SHERPA_ONNXRUNTIME_LIB_DIR
|
|
export SHERPA_ONNXRUNTIME_INCLUDE_DIR
|
|
elif [ -n "${SHERPA_ONNX_ONNXRUNTIME_ROOT:-}" ] && [ "$BUILD_SHARED_LIBS" == ON ]; then
|
|
if [ ! -d "$SHERPA_ONNX_ONNXRUNTIME_ROOT" ]; then
|
|
echo "Error: SHERPA_ONNX_ONNXRUNTIME_ROOT does not exist: $SHERPA_ONNX_ONNXRUNTIME_ROOT"
|
|
exit 1
|
|
fi
|
|
SHERPA_ONNX_ONNXRUNTIME_ROOT=$(cd "$SHERPA_ONNX_ONNXRUNTIME_ROOT" && pwd)
|
|
export SHERPA_ONNX_ONNXRUNTIME_ROOT
|
|
fi
|
|
|
|
mkdir -p $dir
|
|
cd $dir
|
|
|
|
# Note from https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-android
|
|
# (optional) remove the hardcoded debug flag in Android NDK android-ndk
|
|
# issue: https://github.com/android/ndk/issues/243
|
|
#
|
|
# open $ANDROID_NDK/build/cmake/android.toolchain.cmake for ndk < r23
|
|
# or $ANDROID_NDK/build/cmake/android-legacy.toolchain.cmake for ndk >= r23
|
|
#
|
|
# delete "-g" line
|
|
#
|
|
# list(APPEND ANDROID_COMPILER_FLAGS
|
|
# -g
|
|
# -DANDROID
|
|
|
|
if [ -z $ANDROID_NDK ]; then
|
|
ANDROID_NDK=/star-fj/fangjun/software/android-sdk/ndk/22.1.7171670
|
|
if [ $BUILD_SHARED_LIBS == OFF ]; then
|
|
ANDROID_NDK=/star-fj/fangjun/software/android-sdk/ndk/27.0.11718014
|
|
fi
|
|
# or use
|
|
# ANDROID_NDK=/star-fj/fangjun/software/android-ndk
|
|
#
|
|
# Inside the $ANDROID_NDK directory, you can find a binary ndk-build
|
|
# and some other files like the file "build/cmake/android.toolchain.cmake"
|
|
|
|
if [ ! -d $ANDROID_NDK ]; then
|
|
# For macOS, I have installed Android Studio, select the menu
|
|
# Tools -> SDK manager -> Android SDK
|
|
# and set "Android SDK location" to /Users/fangjun/software/my-android
|
|
ANDROID_NDK=/Users/fangjun/software/my-android/ndk/22.1.7171670
|
|
|
|
if [ $BUILD_SHARED_LIBS == OFF ]; then
|
|
ANDROID_NDK=/Users/fangjun/software/my-android/ndk/27.0.11718014
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ ! -d $ANDROID_NDK ]; then
|
|
echo Please set the environment variable ANDROID_NDK before you run this script
|
|
exit 1
|
|
fi
|
|
|
|
echo "ANDROID_NDK: $ANDROID_NDK"
|
|
sleep 1
|
|
|
|
onnxruntime_version=${SHERPA_ONNX_ONNXRUNTIME_VERSION:-1.28.2}
|
|
|
|
if [ -n "${SHERPA_ONNXRUNTIME_LIB_DIR:-}" ] && [ -n "${SHERPA_ONNXRUNTIME_INCLUDE_DIR:-}" ]; then
|
|
echo "Using externally provided ONNX Runtime"
|
|
elif [ -n "${SHERPA_ONNX_ONNXRUNTIME_ROOT:-}" ] && [ "$BUILD_SHARED_LIBS" == ON ]; then
|
|
export SHERPA_ONNXRUNTIME_LIB_DIR="$SHERPA_ONNX_ONNXRUNTIME_ROOT/jni/x86_64/"
|
|
export SHERPA_ONNXRUNTIME_INCLUDE_DIR="$SHERPA_ONNX_ONNXRUNTIME_ROOT/headers/"
|
|
elif [ "$BUILD_SHARED_LIBS" == ON ]; then
|
|
if [ ! -f $onnxruntime_version/jni/x86_64/libonnxruntime.so ]; then
|
|
mkdir -p $onnxruntime_version
|
|
pushd $onnxruntime_version
|
|
wget -c -q https://github.com/csukuangfj/onnxruntime-libs/releases/download/v${onnxruntime_version}/onnxruntime-android-${onnxruntime_version}.zip
|
|
unzip onnxruntime-android-${onnxruntime_version}.zip
|
|
rm onnxruntime-android-${onnxruntime_version}.zip
|
|
popd
|
|
fi
|
|
|
|
export SHERPA_ONNXRUNTIME_LIB_DIR=$dir/$onnxruntime_version/jni/x86_64/
|
|
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$dir/$onnxruntime_version/headers/
|
|
else
|
|
if [ ! -f ${onnxruntime_version}-static/lib/libonnxruntime.a ]; then
|
|
wget -c -q https://github.com/csukuangfj/onnxruntime-libs/releases/download/v${onnxruntime_version}/onnxruntime-android-x86_64-static_lib-${onnxruntime_version}.zip
|
|
unzip onnxruntime-android-x86_64-static_lib-${onnxruntime_version}.zip
|
|
rm onnxruntime-android-x86_64-static_lib-${onnxruntime_version}.zip
|
|
mv onnxruntime-android-x86_64-static_lib-${onnxruntime_version} ${onnxruntime_version}-static
|
|
fi
|
|
|
|
export SHERPA_ONNXRUNTIME_LIB_DIR=$dir/$onnxruntime_version-static/lib/
|
|
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$dir/$onnxruntime_version-static/include/
|
|
fi
|
|
|
|
echo "SHERPA_ONNXRUNTIME_LIB_DIR: $SHERPA_ONNXRUNTIME_LIB_DIR"
|
|
echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR"
|
|
|
|
if [ -z $SHERPA_ONNX_ENABLE_TTS ]; then
|
|
SHERPA_ONNX_ENABLE_TTS=ON
|
|
fi
|
|
|
|
if [ -z $SHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION ]; then
|
|
SHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION=ON
|
|
fi
|
|
|
|
if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
|
|
SHERPA_ONNX_ENABLE_BINARY=OFF
|
|
fi
|
|
|
|
if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
|
|
SHERPA_ONNX_ENABLE_C_API=OFF
|
|
fi
|
|
|
|
if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
|
|
SHERPA_ONNX_ENABLE_JNI=ON
|
|
fi
|
|
|
|
cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
|
|
-DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
|
|
-DSHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION=$SHERPA_ONNX_ENABLE_SPEAKER_DIARIZATION \
|
|
-DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \
|
|
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
|
|
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
|
|
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
|
|
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
|
|
-DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
|
|
-DSHERPA_ONNX_LINK_LIBSTDCPP_STATICALLY=OFF \
|
|
-DCMAKE_INSTALL_PREFIX=./install \
|
|
-DANDROID_ABI="x86_64" \
|
|
-DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
|
|
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
|
|
-DANDROID_PLATFORM=android-21 ..
|
|
|
|
# By default, it links to libc++_static.a
|
|
# -DANDROID_STL=c++_shared \
|
|
|
|
# make VERBOSE=1 -j4
|
|
make -j4
|
|
make install/strip
|
|
|
|
if [ "$BUILD_SHARED_LIBS" == ON ]; then
|
|
cp -fv "$SHERPA_ONNXRUNTIME_LIB_DIR/libonnxruntime.so" install/lib
|
|
fi
|
|
rm -rf install/share
|
|
rm -rf install/lib/pkgconfig
|
|
rm -rf install/lib/lib*.a
|
|
|
|
if [ -f install/lib/libsherpa-onnx-c-api.so ]; then
|
|
cat >install/lib/README.md <<EOF
|
|
# Introduction
|
|
|
|
Note that if you use Android Studio, then you only need to
|
|
copy libonnxruntime.so and libsherpa-onnx-jni.so
|
|
to your jniLibs, and you don't need libsherpa-onnx-c-api.so or
|
|
libsherpa-onnx-cxx-api.so.
|
|
|
|
libsherpa-onnx-c-api.so and libsherpa-onnx-cxx-api.so are for users
|
|
who don't use JNI. In that case, libsherpa-onnx-jni.so is not needed.
|
|
|
|
In any case, libonnxruntime.so is always needed.
|
|
EOF
|
|
ls -lh install/lib/README.md
|
|
fi
|