Skip to content

Commit

Permalink
Rlease pre-built APK for English and French (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Aug 18, 2023
1 parent db4454f commit fc4d3bc
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-ncnn)

set(SHERPA_NCNN_VERSION "2.0.6")
set(SHERPA_NCNN_VERSION "2.0.7")

# Disable warning about
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ fun getDecoderConfig(method: String, numActivePaths: Int): DecoderConfig {
2 - https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13
This model supports both English and Chinese
3 - https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-en-2023-02-13
This model supports only English
4 - https://huggingface.co/shaojieli/sherpa-ncnn-streaming-zipformer-fr-2023-04-14
This model supports only French
Please follow
https://k2-fsa.github.io/sherpa/ncnn/pretrained_models/index.html
Expand Down Expand Up @@ -169,6 +174,36 @@ fun getModelConfig(type: Int, useGPU: Boolean): ModelConfig? {
useGPU = useGPU,
)
}

3 -> {
val modelDir = "sherpa-ncnn-streaming-zipformer-en-2023-02-13"
return ModelConfig(
encoderParam = "$modelDir/encoder_jit_trace-pnnx.ncnn.param",
encoderBin = "$modelDir/encoder_jit_trace-pnnx.ncnn.bin",
decoderParam = "$modelDir/decoder_jit_trace-pnnx.ncnn.param",
decoderBin = "$modelDir/decoder_jit_trace-pnnx.ncnn.bin",
joinerParam = "$modelDir/joiner_jit_trace-pnnx.ncnn.param",
joinerBin = "$modelDir/joiner_jit_trace-pnnx.ncnn.bin",
tokens = "$modelDir/tokens.txt",
numThreads = 1,
useGPU = useGPU,
)
}

4 -> {
val modelDir = "sherpa-ncnn-streaming-zipformer-fr-2023-04-14"
return ModelConfig(
encoderParam = "$modelDir/encoder_jit_trace-pnnx.ncnn.param",
encoderBin = "$modelDir/encoder_jit_trace-pnnx.ncnn.bin",
decoderParam = "$modelDir/decoder_jit_trace-pnnx.ncnn.param",
decoderBin = "$modelDir/decoder_jit_trace-pnnx.ncnn.bin",
joinerParam = "$modelDir/joiner_jit_trace-pnnx.ncnn.param",
joinerBin = "$modelDir/joiner_jit_trace-pnnx.ncnn.bin",
tokens = "$modelDir/tokens.txt",
numThreads = 1,
useGPU = useGPU,
)
}
}
return null
}
119 changes: 119 additions & 0 deletions build-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ log "====================x86===================="

mkdir -p apks

# type 2
log "https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-bilingual-zh-en-2023-02-13"

# Download the model
Expand Down Expand Up @@ -85,4 +86,122 @@ done

git checkout .

rm -rf ./android/SherpaNcnn/app/src/main/assets/$repo

# type 3
log "https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-en-2023-02-13"

# Download the model
# see https://k2-fsa.github.io/sherpa/ncnn/pretrained_models/zipformer-transucer-models.html#csukuangfj-sherpa-ncnn-streaming-zipformer-en-2023-02-13-english
repo_url=https://huggingface.co/csukuangfj/sherpa-ncnn-streaming-zipformer-en-2023-02-13
log "Start testing ${repo_url}"
repo=$(basename $repo_url)
log "Download pretrained model and test-data from $repo_url"
GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
pushd $repo
git lfs pull --include "*.bin"

# remove .git to save spaces
rm -rf .git
rm .gitattributes
rm -rfv test_wavs
rm -v README.md
rm -v export*.sh
ls -lh
popd

mv -v $repo ./android/SherpaNcnn/app/src/main/assets/
tree ./android/SherpaNcnn/app/src/main/assets/

pushd android/SherpaNcnn/app/src/main/java/com/k2fsa/sherpa/ncnn
sed -i.bak s/"type = 1"/"type = 3"/ ./MainActivity.kt
git diff
popd

for arch in arm64-v8a armeabi-v7a x86_64 x86; do
log "------------------------------------------------------------"
log "build 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/SherpaNcnn/app/src/main/jniLibs/$arch/

pushd ./android/SherpaNcnn
./gradlew build
popd

mv android/SherpaNcnn/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-ncnn-${SHERPA_NCNN_VERSION}-cpu-$arch-en.apk
ls -lh apks
rm -v ./android/SherpaNcnn/app/src/main/jniLibs/$arch/*.so
done

git checkout .

rm -rf ./android/SherpaNcnn/app/src/main/assets/$repo

# type 4
log "https://huggingface.co/shaojieli/sherpa-ncnn-streaming-zipformer-fr-2023-04-14"

# Download the model
# see https://k2-fsa.github.io/sherpa/ncnn/pretrained_models/zipformer-transucer-models.html#shaojieli-sherpa-ncnn-streaming-zipformer-fr-2023-04-14
repo_url=https://huggingface.co/shaojieli/sherpa-ncnn-streaming-zipformer-fr-2023-04-14
log "Start testing ${repo_url}"
repo=$(basename $repo_url)
log "Download pretrained model and test-data from $repo_url"
GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
pushd $repo
git lfs pull --include "*.bin"

# remove .git to save spaces
rm -rf .git
rm .gitattributes
rm -rfv test_wavs
rm -v README.md
rm -v export*.sh
ls -lh
popd

mv -v $repo ./android/SherpaNcnn/app/src/main/assets/
tree ./android/SherpaNcnn/app/src/main/assets/

pushd android/SherpaNcnn/app/src/main/java/com/k2fsa/sherpa/ncnn
sed -i.bak s/"type = 1"/"type = 4"/ ./MainActivity.kt
git diff
popd

for arch in arm64-v8a armeabi-v7a x86_64 x86; do
log "------------------------------------------------------------"
log "build 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/SherpaNcnn/app/src/main/jniLibs/$arch/

pushd ./android/SherpaNcnn
./gradlew build
popd

mv android/SherpaNcnn/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-ncnn-${SHERPA_NCNN_VERSION}-cpu-$arch-fr.apk
ls -lh apks
rm -v ./android/SherpaNcnn/app/src/main/jniLibs/$arch/*.so
done

git checkout .

rm -rf ./android/SherpaNcnn/app/src/main/assets/$repo

ls -lh apks/

0 comments on commit fc4d3bc

Please sign in to comment.