-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build text-to-speech engine APKs (#509)
- Loading branch information
1 parent
d7e10bb
commit 581eceb
Showing
7 changed files
with
331 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
name: apk-tts-engine | ||
|
||
on: | ||
push: | ||
branches: | ||
- apk-tts | ||
tags: | ||
- '*' | ||
|
||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: apk-tts-engine-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
apk_tts_engine: | ||
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' | ||
runs-on: ${{ matrix.os }} | ||
name: apk for tts engine ${{ matrix.index }}/${{ matrix.total }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest] | ||
total: ["40"] | ||
index: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# https://github.com/actions/setup-java | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' # See 'Supported distributions' for available options | ||
java-version: '21' | ||
|
||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
key: ${{ matrix.os }}-android | ||
|
||
- name: Display NDK HOME | ||
shell: bash | ||
run: | | ||
echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" | ||
ls -lh ${ANDROID_NDK_LATEST_HOME} | ||
- name: Install Python dependencies | ||
shell: bash | ||
run: | | ||
python3 -m pip install --upgrade pip jinja2 iso639-lang | ||
- name: Generate build script | ||
shell: bash | ||
run: | | ||
cd scripts/apk | ||
total=${{ matrix.total }} | ||
index=${{ matrix.index }} | ||
./generate-tts-apk-script.py --total $total --index $index | ||
chmod +x build-apk-tts-engine.sh | ||
mv -v ./build-apk-tts-engine.sh ../.. | ||
- name: build APK for TTS engine | ||
shell: bash | ||
run: | | ||
export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
cmake --version | ||
export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | ||
./build-apk-tts-engine.sh | ||
- name: Display APK for TTS engine | ||
shell: bash | ||
run: | | ||
ls -lh ./apks/ | ||
du -h -d1 . | ||
- uses: actions/upload-artifact@v3 | ||
if: false | ||
with: | ||
name: tts-engine-apk | ||
path: ./apks/*.apk | ||
|
||
- name: Publish to huggingface | ||
if: true | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
uses: nick-fields/retry@v2 | ||
with: | ||
max_attempts: 20 | ||
timeout_seconds: 200 | ||
shell: bash | ||
command: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
rm -rf huggingface | ||
export GIT_LFS_SKIP_SMUDGE=1 | ||
git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface | ||
cd huggingface | ||
git fetch | ||
git pull | ||
git merge -m "merge remote" --ff origin main | ||
mkdir -p tts | ||
cp -v ../apks/*.apk ./tts-engine/ | ||
git status | ||
git lfs track "*.apk" | ||
git add . | ||
git commit -m "add more tts engine apks" | ||
git push https://csukuangfj:[email protected]/csukuangfj/sherpa-onnx-apk main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Auto generated! Please DO NOT EDIT! | ||
|
||
# Please set the environment variable ANDROID_NDK | ||
# before running this script | ||
|
||
# Inside the $ANDROID_NDK directory, you can find a binary ndk-build | ||
# and some other files like the file "build/cmake/android.toolchain.cmake" | ||
|
||
set -ex | ||
|
||
log() { | ||
# This function is from espnet | ||
local fname=${BASH_SOURCE[1]##*/} | ||
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" | ||
} | ||
|
||
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
|
||
log "Building TTS engine APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" | ||
|
||
log "====================arm64-v8a=================" | ||
./build-android-arm64-v8a.sh | ||
log "====================armv7-eabi================" | ||
./build-android-armv7-eabi.sh | ||
log "====================x86-64====================" | ||
./build-android-x86-64.sh | ||
log "====================x86====================" | ||
./build-android-x86.sh | ||
|
||
mkdir -p apks | ||
|
||
{% for tts_model in tts_model_list %} | ||
pushd ./android/SherpaOnnxTtsEngine/app/src/main/assets/ | ||
model_dir={{ tts_model.model_dir }} | ||
model_name={{ tts_model.model_name }} | ||
lang={{ tts_model.lang }} | ||
lang_iso_639_3={{ tts_model.lang_iso_639_3 }} | ||
|
||
wget -qq https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/$model_dir.tar.bz2 | ||
tar xf $model_dir.tar.bz2 | ||
rm $model_dir.tar.bz2 | ||
|
||
popd | ||
# Now we are at the project root directory | ||
|
||
git checkout . | ||
pushd android/SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/engine | ||
sed -i.bak s/"modelDir = null"/"modelDir = \"$model_dir\""/ ./TtsEngine.kt | ||
sed -i.bak s/"modelName = null"/"modelName = \"$model_name\""/ ./TtsEngine.kt | ||
sed -i.bak s/"lang = null"/"lang = \"$lang_iso_639_3\""/ ./TtsEngine.kt | ||
|
||
{% if tts_model.rule_fsts %} | ||
rule_fsts={{ tts_model.rule_fsts }} | ||
sed -i.bak s%"ruleFsts = null"%"ruleFsts = \"$rule_fsts\""% ./TtsEngine.kt | ||
{% endif %} | ||
|
||
{% if tts_model.data_dir %} | ||
data_dir={{ tts_model.data_dir }} | ||
sed -i.bak s%"dataDir = null"%"dataDir = \"$data_dir\""% ./TtsEngine.kt | ||
{% else %} | ||
sed -i.bak s/"lexicon = null"/"lexicon = \"lexicon.txt\""/ ./TtsEngine.kt | ||
{% endif %} | ||
|
||
git diff | ||
popd | ||
|
||
for arch in arm64-v8a armeabi-v7a x86_64 x86; do | ||
log "------------------------------------------------------------" | ||
log "build tts apk for $arch" | ||
log "------------------------------------------------------------" | ||
src_arch=$arch | ||
if [ $arch == "armeabi-v7a" ]; then | ||
src_arch=armv7-eabi | ||
elif [ $arch == "x86_64" ]; then | ||
src_arch=x86-64 | ||
fi | ||
|
||
ls -lh ./build-android-$src_arch/install/lib/*.so | ||
|
||
cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxTtsEngine/app/src/main/jniLibs/$arch/ | ||
|
||
pushd ./android/SherpaOnnxTtsEngine | ||
./gradlew build | ||
popd | ||
|
||
mv android/SherpaOnnxTtsEngine/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-$lang-tts-engine-$model_dir.apk | ||
ls -lh apks | ||
rm -v ./android/SherpaOnnxTtsEngine/app/src/main/jniLibs/$arch/*.so | ||
done | ||
|
||
rm -rf ./android/SherpaOnnxTtsEngine/app/src/main/assets/$model_dir | ||
{% endfor %} | ||
|
||
git checkout . | ||
|
||
ls -lh apks/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.