Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pkufool committed Jan 8, 2024
1 parent 28c5b0c commit 0d36d48
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,11 @@ to add your own. (It should be straightforward to add a new model
by following the code)
@param type
0 - sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 (Bilingual, Chinese + English)
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/zipformer-transducer-models.html#sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20-bilingual-chinese-english
0 - sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01 (Chinese)
https://www.modelscope.cn/models/pkufool/sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01/summary
1 - csukuangfj/sherpa-onnx-lstm-zh-2023-02-20 (Chinese)
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/lstm-transducer-models.html#csukuangfj-sherpa-onnx-lstm-zh-2023-02-20-chinese
2 - csukuangfj/sherpa-onnx-lstm-en-2023-02-17 (English)
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/lstm-transducer-models.html#csukuangfj-sherpa-onnx-lstm-en-2023-02-17-english
3,4 - pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615
https://huggingface.co/pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615
3 - int8 encoder
4 - float32 encoder
5 - csukuangfj/sherpa-onnx-streaming-paraformer-bilingual-zh-en
https://huggingface.co/csukuangfj/sherpa-onnx-streaming-paraformer-bilingual-zh-en
6 - sherpa-onnx-streaming-zipformer-en-2023-06-26
https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26
7 - shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14 (French)
https://huggingface.co/shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14
8 - csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 (Bilingual, Chinese + English)
https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
encoder int8, decoder/joiner float32
1 - sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01 (English)
https://www.modelscope.cn/models/pkufool/sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01/summary
*/
fun getModelConfig(type: Int): OnlineModelConfig? {
Expand All @@ -162,14 +140,14 @@ fun getModelConfig(type: Int): OnlineModelConfig? {
}

1 -> {
val modelDir = "icefall-asr-zipformer-streaming-wenetspeech-20230615"
val modelDir = "sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01"
return OnlineModelConfig(
transducer = OnlineTransducerModelConfig(
encoder = "$modelDir/exp/encoder-epoch-12-avg-4-chunk-16-left-128.onnx",
decoder = "$modelDir/exp/decoder-epoch-12-avg-4-chunk-16-left-128.onnx",
joiner = "$modelDir/exp/joiner-epoch-12-avg-4-chunk-16-left-128.onnx",
encoder = "$modelDir/encoder-epoch-12-avg-2-chunk-16-left-64.onnx",
decoder = "$modelDir/decoder-epoch-12-avg-2-chunk-16-left-64.onnx",
joiner = "$modelDir/joiner-epoch-12-avg-2-chunk-16-left-64.onnx",
),
tokens = "$modelDir/data/lang_char/tokens.txt",
tokens = "$modelDir/tokens.txt",
modelType = "zipformer2",
)
}
Expand Down
121 changes: 90 additions & 31 deletions build-kws-apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,103 @@ log "Building keyword spotting APK for sherpa-onnx v${SHERPA_ONNX_VERSION}"
log "====================arm64-v8a================="
./build-android-arm64-v8a.sh
log "====================armv7-eabi================"
#./build-android-armv7-eabi.sh
./build-android-armv7-eabi.sh
log "====================x86-64===================="
#./build-android-x86-64.sh
./build-android-x86-64.sh
log "====================x86===================="
#./build-android-x86.sh

./build-android-x86.sh

mkdir -p apks

log "https://www.modelscope.cn/pkufool/sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01.git"

# Download the model
repo_url=https://www.modelscope.cn/pkufool/sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01.git
#log "Start testing ${repo_url}"
##repo=$(basename $repo_url)
#repo=sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01
#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 "*.onnx"
#
## remove .git to save spaces
#rm -rf .git
#rm README.md
#rm -rfv test_wavs
#ls -lh
#popd
#
#mv -v $repo ./android/SherpaOnnxKws/app/src/main/assets/
repo=sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01

if [ ! -d $repo ]; then
repo_url=https://www.modelscope.cn/pkufool/sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01.git
log "Start testing ${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 "*.onnx"

# remove .git to save spaces
rm -rf .git
rm README.md configuration.json .gitattribute
rm -rfv test_wavs
ls -lh
popd

mv -v $repo ./android/SherpaOnnxKws/app/src/main/assets/
fi

pushd ./android/SherpaOnnxKws/app/src/main/assets/
cp $repo/keywords.txt .
popd

tree ./android/SherpaOnnxKws/app/src/main/assets/

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/SherpaOnnxKws/app/src/main/jniLibs/$arch/

pushd ./android/SherpaOnnxKws
./gradlew build
popd

mv android/SherpaOnnxKws/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-kws-${SHERPA_ONNX_VERSION}-$arch.apk
ls -lh apks
rm -v ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/*.so
done

git checkout .

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

# English model
repo=sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01

if [ ! -d $repo ]; then
repo_url=https://www.modelscope.cn/pkufool/sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01.git
log "Start testing ${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 "*.onnx"

# remove .git to save spaces
rm -rf .git
rm *.int8.onnx
rm README.md configuration.json .gitattribute
rm -rfv test_wavs
ls -lh
popd

mv -v $repo ./android/SherpaOnnxKws/app/src/main/assets/
fi

pushd ./android/SherpaOnnxKws/app/src/main/assets/
cp $repo/keywords.txt .
popd

tree ./android/SherpaOnnxKws/app/src/main/assets/

pushd android/SherpaOnnxKws/app/src/main/java/com/k2fsa/sherpa/onnx
#sed -i.bak s/"type = 0"/"type = 6"/ ./MainActivity.kt
#git diff
sed -i.bak s/"type = 0"/"type = 1"/ ./MainActivity.kt
git diff
popd

#for arch in arm64-v8a armeabi-v7a x86_64 x86; do
for arch in arm64-v8a; do
for arch in arm64-v8a armeabi-v7a x86_64 x86; do
log "------------------------------------------------------------"
log "build apk for $arch"
log "------------------------------------------------------------"
Expand All @@ -77,11 +136,11 @@ for arch in arm64-v8a; do
./gradlew build
popd

mv android/SherpaOnnxKws/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch.apk
mv android/SherpaOnnxKws/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-kws-${SHERPA_ONNX_VERSION}-$arch-en.apk
ls -lh apks
#rm -v ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/*.so
rm -v ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/*.so
done

#git checkout .
git checkout .

#rm -rf ./android/SherpaOnnxKws/app/src/main/assets/$repo
rm -rf ./android/SherpaOnnxKws/app/src/main/assets/$repo
7 changes: 7 additions & 0 deletions sherpa-onnx/csrc/keyword-spotter-transducer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ static KeywordResult Convert(const TransducerKeywordsResult &src,
r.tokens.reserve(src.tokens.size());
r.timestamps.reserve(src.tokens.size());
r.keyword = src.keyword;
bool from_tokens = src.keyword.size() == 0;

for (auto i : src.tokens) {
auto sym = sym_table[i];
if (from_tokens) {
r.keyword.append(sym);
}
r.tokens.push_back(std::move(sym));
}
if (from_tokens && r.keyword.size()) {
r.keyword = r.keyword.substr(1);
}

float frame_shift_s = frame_shift_ms / 1000. * subsampling_factor;
for (auto t : src.timestamps) {
Expand Down

0 comments on commit 0d36d48

Please sign in to comment.