Skip to content

Commit 6b7072b

Browse files
authored
Pack all sources into a single tar for embedded systems (#96)
* Pack all sources into a single tar for embedded systems * Update to v1.4.1
1 parent d6fcb96 commit 6b7072b

12 files changed

+141
-3
lines changed

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
22
project(sherpa-ncnn)
33

4-
set(SHERPA_NCNN_VERSION "1.4.0")
4+
set(SHERPA_NCNN_VERSION "1.4.1")
55

66
# Disable warning about
77
#
@@ -36,6 +36,7 @@ option(SHERPA_NCNN_ENABLE_JNI "Whether to build JNI internface" OFF)
3636
option(SHERPA_NCNN_ENABLE_BINARY "Whether to build the binary sherpa-ncnn" ON)
3737
option(SHERPA_NCNN_ENABLE_TEST "Whether to build tests" OFF)
3838
option(SHERPA_NCNN_ENABLE_C_API "Whether to build C API" ON)
39+
option(SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE "Whether to generate-int8-scale-table" ON)
3940

4041
if(DEFINED ANDROID_ABI)
4142
message(STATUS "Set SHERPA_NCNN_ENABLE_JNI to ON for Android")
@@ -49,6 +50,7 @@ message(STATUS "SHERPA_NCNN_ENABLE_JNI ${SHERPA_NCNN_ENABLE_JNI}")
4950
message(STATUS "SHERPA_NCNN_ENABLE_BINARY ${SHERPA_NCNN_ENABLE_BINARY}")
5051
message(STATUS "SHERPA_NCNN_ENABLE_TEST ${SHERPA_NCNN_ENABLE_TEST}")
5152
message(STATUS "SHERPA_NCNN_ENABLE_C_API ${SHERPA_NCNN_ENABLE_C_API}")
53+
message(STATUS "SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE ${SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE}")
5254

5355
if(NOT CMAKE_BUILD_TYPE)
5456
message(STATUS "No CMAKE_BUILD_TYPE given, default to Release")

build-android-arm64-v8a-with-vulkan.sh

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
113113
-DNCNN_SYSTEM_GLSLANG=ON \
114114
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
115115
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
116+
-DSHERPA_NCNN_ENABLE_TEST=OFF \
117+
-DSHERPA_NCNN_ENABLE_C_API=OFF \
118+
-DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
116119
-DCMAKE_INSTALL_PREFIX=./install \
117120
-DANDROID_ABI="arm64-v8a" \
118121
-DNCNN_VULKAN=ON \

build-android-arm64-v8a.sh

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
4949
-DBUILD_SHARED_LIBS=ON \
5050
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
5151
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
52+
-DSHERPA_NCNN_ENABLE_TEST=OFF \
53+
-DSHERPA_NCNN_ENABLE_C_API=OFF \
54+
-DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
5255
-DCMAKE_INSTALL_PREFIX=./install \
5356
-DANDROID_ABI="arm64-v8a" \
5457
-DANDROID_PLATFORM=android-21 ..

build-android-armv7-eabi.sh

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
4848
-DBUILD_SHARED_LIBS=ON \
4949
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
5050
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
51+
-DSHERPA_NCNN_ENABLE_TEST=OFF \
52+
-DSHERPA_NCNN_ENABLE_C_API=OFF \
53+
-DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
5154
-DCMAKE_INSTALL_PREFIX=./install \
5255
-DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON \
5356
-DANDROID_PLATFORM=android-21 ..

build-android-x86-64.sh

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
5050
-DBUILD_SHARED_LIBS=ON \
5151
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
5252
-DSHERPA_NCNN_ENABLE_BINARY=OFF \
53+
-DSHERPA_NCNN_ENABLE_TEST=OFF \
54+
-DSHERPA_NCNN_ENABLE_C_API=OFF \
55+
-DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
5356
-DCMAKE_INSTALL_PREFIX=./install \
5457
-DANDROID_ABI="x86_64" \
5558
-DANDROID_PLATFORM=android-21 ..

build-m3axpi.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
# This script is exclusively for building sherpa-ncnn
4+
# on MAIX-III AXera-Pi
5+
# (https://wiki.sipeed.com/hardware/en/maixIII/ax-pi/axpi.html)
6+
#
7+
# It is not for cross-compiling.
8+
#
9+
# Before running this script, please make sure you have the following
10+
# files:
11+
#
12+
# root@AXERA:~/asr# pwd
13+
# /root/asr
14+
#
15+
# root@AXERA:~/asr# ls -lh
16+
# total 25M
17+
# -rw-r--r-- 1 501 staff 59K Feb 2 17:01 kaldi-native-fbank-1.11.tar.gz
18+
# -rw-r--r-- 1 501 staff 12M Feb 2 17:01 ncnn-sherpa-0.8.tar.gz
19+
# drwxr-xr-x 15 501 staff 4.0K Feb 2 21:04 sherpa-ncnn-1.4.0
20+
#
21+
#
22+
# Note: It is OK if the versions of the above files are different.
23+
# The two `.tar.gz` files must be placed in $HOME/asr
24+
25+
mkdir -p build
26+
cd build
27+
28+
cmake \
29+
-DCMAKE_BUILD_TYPE=Release \
30+
-DCMAKE_INSTALL_PREFIX=./install \
31+
-DBUILD_SHARED_LIBS=OFF \
32+
-DSHERPA_NCNN_ENABLE_PYTHON=OFF \
33+
-DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
34+
-DSHERPA_NCNN_ENABLE_JNI=OFF \
35+
-DSHERPA_NCNN_ENABLE_BINARY=ON \
36+
-DSHERPA_NCNN_ENABLE_TEST=OFF \
37+
-DSHERPA_NCNN_ENABLE_C_API=OFF \
38+
-DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
39+
..
40+
41+
make -j 4
42+
cd ..
43+
44+
echo
45+
echo "ls -lh ./build/bin"
46+
# You will find two statically-linked executables in ./build/bin
47+
ls -lh ./build/bin
48+
49+
echo
50+
echo "Please refer to"
51+
echo "https://k2-fsa.github.io/sherpa/ncnn/pretrained_models/index.html"
52+
echo "to download pre-trained models"

cmake/kaldi-native-fbank.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function(download_kaldi_native_fbank)
22
include(FetchContent)
33

4+
# Please also change ../pack-for-embedded-systems.sh
45
set(kaldi_native_fbank_URL "https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.11.tar.gz")
56
set(kaldi_native_fbank_HASH "SHA256=e69ae25ef6f30566ef31ca949dd1b0b8ec3a827caeba93a61d82bb848dac5d69")
67

@@ -12,6 +13,8 @@ function(download_kaldi_native_fbank)
1213
set(kaldi_native_fbank_URL "file:///Users/fangjun/Downloads/kaldi-native-fbank-1.11.tar.gz")
1314
elseif(EXISTS "/tmp/kaldi-native-fbank-1.11.tar.gz")
1415
set(kaldi_native_fbank_URL "file:///tmp/kaldi-native-fbank-1.11.tar.gz")
16+
elseif(EXISTS "$ENV{HOME}/asr/kaldi-native-fbank-1.11.tar.gz")
17+
set(kaldi_native_fbank_URL "file://$ENV{HOME}/asr/kaldi-native-fbank-1.11.tar.gz")
1518
endif()
1619

1720
set(KALDI_NATIVE_FBANK_BUILD_TESTS OFF CACHE BOOL "" FORCE)

cmake/ncnn.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function(download_ncnn)
55
# The changed code is in
66
# https://github.com/csukuangfj/ncnn/pull/7
77

8+
# Please also change ../pack-for-embedded-systems.sh
89
set(ncnn_URL "https://github.com/csukuangfj/ncnn/archive/refs/tags/sherpa-0.8.tar.gz")
910
set(ncnn_HASH "SHA256=f605c48986406800615d00cf14b955e95f73286eadacedb6c3371542540e1df0")
1011

@@ -16,6 +17,8 @@ function(download_ncnn)
1617
set(ncnn_URL "file:///Users/fangjun/Downloads/ncnn-sherpa-0.8.tar.gz")
1718
elseif(EXISTS "/tmp/ncnn-sherpa-0.8.tar.gz")
1819
set(ncnn_URL "file:///tmp/ncnn-sherpa-0.8.tar.gz")
20+
elseif(EXISTS "$ENV{HOME}/asr/ncnn-sherpa-0.8.tar.gz")
21+
set(ncnn_URL "file://$ENV{HOME}/asr/ncnn-sherpa-0.8.tar.gz")
1922
endif()
2023

2124
FetchContent_Declare(ncnn

cmake/portaudio.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function(download_portaudio)
1212
set(portaudio_URL "file:///Users/fangjun/Downloads/pa_stable_v190700_20210406.tgz")
1313
elseif(EXISTS "/tmp/pa_stable_v190700_20210406.tgz")
1414
set(portaudio_URL "file:///tmp/pa_stable_v190700_20210406.tgz")
15+
elseif(EXISTS "$ENV{HOME}/asr/pa_stable_v190700_20210406.tgz")
16+
set(portaudio_URL "file://$ENV{HOME}/asr/pa_stable_v190700_20210406.tgz")
1517
endif()
1618

1719
if(BUILD_SHARED_LIBS)

cmake/pybind11.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function(download_pybind11)
1212
set(pybind11_URL "file:///Users/fangjun/Downloads/pybind11-2.10.2.tar.gz")
1313
elseif(EXISTS "/tmp/pybind11-2.10.2.tar.gz")
1414
set(pybind11_URL "file:///tmp/pybind11-2.10.2.tar.gz")
15+
elseif(EXISTS "$ENV{HOME}/asr/pybind11-2.10.2.tar.gz")
16+
set(pybind11_URL "file://$ENV{HOME}/asr/pybind11-2.10.2.tar.gz")
1517
endif()
1618

1719
FetchContent_Declare(pybind11

pack-for-embedded-systems.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
3+
# This script pack all source code into a single zip file
4+
# so that you can build it locally without accessing Internet
5+
# on your board.
6+
7+
set -e
8+
9+
SHERPA_NCNN_VERSION=$(grep "SHERPA_NCNN_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
10+
echo "SHERPA_NCNN_VERSION: ${SHERPA_NCNN_VERSION}"
11+
12+
dir=sherpa-ncnn-all-in-one-for-embedded-systems-${SHERPA_NCNN_VERSION}
13+
14+
# rm -rf $dir
15+
mkdir -p $dir
16+
17+
pushd $dir
18+
19+
wget \
20+
-O sherpa-ncnn-${SHERPA_NCNN_VERSION}.tar.gz \
21+
https://github.com/k2-fsa/sherpa-ncnn/archive/refs/tags/v${SHERPA_NCNN_VERSION}.tar.gz
22+
23+
tar xf sherpa-ncnn-${SHERPA_NCNN_VERSION}.tar.gz
24+
rm -v sherpa-ncnn-${SHERPA_NCNN_VERSION}.tar.gz
25+
26+
# Please also change ./build-m3axpi.sh
27+
wget \
28+
-O kaldi-native-fbank-1.11.tar.gz \
29+
https://github.com/csukuangfj/kaldi-native-fbank/archive/refs/tags/v1.11.tar.gz
30+
31+
wget \
32+
-O ncnn-sherpa-0.8.tar.gz \
33+
https://github.com/csukuangfj/ncnn/archive/refs/tags/sherpa-0.8.tar.gz
34+
35+
cat >README.md <<EOF
36+
Please put files from this folder to the directory \$HOME/asr/
37+
38+
rm -rf \$HOME/asr
39+
mkdir -p \$HOME/asr
40+
41+
tar xvf sherpa-ncnn-all-in-one-for-embedded-systems-${SHERPA_NCNN_VERSION}.tar.bz2 --strip-components 1 -C \$HOME/asr
42+
rm sherpa-ncnn-all-in-one-for-embedded-systems-${SHERPA_NCNN_VERSION}.tar.bz2 # to save space
43+
44+
ls -lh \$HOME/asr
45+
46+
It should print something like below:
47+
48+
ls -lh \$HOME/asr
49+
total 24368
50+
-rw-r--r-- 1 fangjun staff 59K Feb 2 17:01 kaldi-native-fbank-1.11.tar.gz
51+
-rw-r--r-- 1 fangjun staff 12M Feb 2 17:01 sherpa-0.8.tar.gz
52+
drwxr-xr-x 29 fangjun staff 928B Feb 2 16:05 sherpa-ncnn-${SHERPA_NCNN_VERSION}
53+
54+
# Note: It is OK if the versions of the above files are different.
55+
# The two .tar.gz files must be placed in \$HOME/asr
56+
EOF
57+
58+
popd
59+
60+
tar cjf ${dir}.tar.bz2 $dir

sherpa-ncnn/csrc/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ if(NOT SHERPA_NCNN_ENABLE_PYTHON)
6666
DESTINATION include/sherpa-ncnn/csrc
6767
)
6868

69-
add_executable(generate-int8-scale-table generate-int8-scale-table.cc)
70-
target_link_libraries(generate-int8-scale-table sherpa-ncnn-core)
69+
if(SHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE)
70+
add_executable(generate-int8-scale-table generate-int8-scale-table.cc)
71+
target_link_libraries(generate-int8-scale-table sherpa-ncnn-core)
72+
endif()
7173
endif()
7274
endif()
7375

0 commit comments

Comments
 (0)