├── Dockerfile ├── README.rst └── compile-kaldi.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | RUN mkdir -p /opt/android-sdk-linux && mkdir -p ~/.android && touch ~/.android/repositories.cfg 4 | 5 | ENV WORKING_DIR /opt 6 | 7 | ENV ANDROID_NDK_HOME ${WORKING_DIR}/android-ndk-linux 8 | ENV ANDROID_TOOLCHAIN_PATH /tmp/my-android-toolchain 9 | ENV PATH ${ANDROID_TOOLCHAIN_PATH}/bin:${PATH} 10 | ENV CLANG_FLAGS "-target arm-linux-androideabi -marm -mfpu=vfp -mfloat-abi=softfp --sysroot ${ANDROID_TOOLCHAIN_PATH}/sysroot -gcc-toolchain ${ANDROID_TOOLCHAIN_PATH}" 11 | 12 | RUN apt-get update && apt-get install -y --no-install-recommends \ 13 | build-essential \ 14 | ca-certificates \ 15 | clang \ 16 | file \ 17 | gfortran \ 18 | git \ 19 | python \ 20 | unzip \ 21 | wget && \ 22 | apt-get clean autoclean && \ 23 | apt-get autoremove -y 24 | 25 | ##### Install Android toolchain 26 | RUN cd ${WORKING_DIR} && \ 27 | wget -q --output-document=android-ndk.zip https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip && \ 28 | unzip android-ndk.zip && \ 29 | rm -f android-ndk.zip && \ 30 | mv android-ndk-r16b ${ANDROID_NDK_HOME} 31 | 32 | RUN ${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py --arch arm --api 21 --stl=libc++ --install-dir ${ANDROID_TOOLCHAIN_PATH} 33 | 34 | ##### Download, compile and install OpenBlas 35 | RUN cd ${WORKING_DIR} && \ 36 | git clone https://github.com/xianyi/OpenBLAS && \ 37 | cd OpenBLAS && \ 38 | make TARGET=ARMV7 ONLY_CBLAS=1 AR=ar CC="clang ${CLANG_FLAGS}" HOSTCC=gcc ARM_SOFTFP_ABI=1 USE_THREAD=0 NUM_THREADS=32 -j4 && \ 39 | make install NO_SHARED=1 PREFIX=`pwd`/install 40 | 41 | 42 | ##### Download, compile and install CLAPACK 43 | RUN cd ${WORKING_DIR} && \ 44 | git clone https://github.com/simonlynen/android_libs && \ 45 | cd android_libs/lapack && \ 46 | sed -i 's/LOCAL_MODULE:= testlapack/#LOCAL_MODULE:= testlapack/g' jni/Android.mk && \ 47 | sed -i 's/LOCAL_SRC_FILES:= testclapack.cpp/#LOCAL_SRC_FILES:= testclapack.cpp/g' jni/Android.mk && \ 48 | sed -i 's/LOCAL_STATIC_LIBRARIES := lapack/#LOCAL_STATIC_LIBRARIES := lapack/g' jni/Android.mk && \ 49 | sed -i 's/include $(BUILD_SHARED_LIBRARY)/#include $(BUILD_SHARED_LIBRARY)/g' jni/Android.mk && \ 50 | ${ANDROID_NDK_HOME}/ndk-build && \ 51 | cp obj/local/armeabi-v7a/*.a ${WORKING_DIR}/OpenBLAS/install/lib 52 | 53 | ##### Compile kaldi 54 | # Using "/opt" because of a bug in Docker: 55 | # https://github.com/docker/docker/issues/25925 56 | COPY ./compile-kaldi.sh /opt 57 | 58 | RUN chmod +x /opt/compile-kaldi.sh 59 | 60 | ENTRYPOINT ["./opt/compile-kaldi.sh"] 61 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | docker-kaldi-android 2 | #################### 3 | 4 | Dockerfile for compiling Kaldi for Android. Based on instructions published at 5 | http://jcsilva.github.io/2017/03/18/compile-kaldi-android/. 6 | 7 | 8 | Install docker 9 | ============== 10 | 11 | Please, refer to https://docs.docker.com/engine/installation/. 12 | 13 | 14 | Get the image 15 | ============= 16 | 17 | * Pull the image from Docker Hub: 18 | 19 | .. code-block:: bash 20 | 21 | $ docker pull jcsilva/docker-kaldi-android 22 | 23 | * Or build your own image (requires git): 24 | 25 | .. code-block:: bash 26 | 27 | $ git clone https://github.com/jcsilva/docker-kaldi-android 28 | $ cd docker-kaldi-android 29 | $ docker build -t jcsilva/docker-kaldi-android:latest . 30 | 31 | 32 | How to use 33 | ========== 34 | 35 | First of all, clone Kaldi repository to somewhere in your machine. 36 | 37 | .. code-block:: bash 38 | 39 | $ git clone https://github.com/kaldi-asr/kaldi 40 | 41 | 42 | Run a container, mounting the Kaldi repository you just cloned to /opt/kaldi: 43 | 44 | .. code-block:: bash 45 | 46 | $ docker run -v /home/test/kaldi:/opt/kaldi jcsilva/docker-kaldi-android:latest 47 | 48 | In the above example, it was assumed the Kaldi repository was cloned to 49 | ``/home/test/kaldi``. If you cloned it to somewhere else, you must change it 50 | accordingly. 51 | 52 | When ``docker run`` finishes, all the compiled Android binaries will be located 53 | in ``/home/test/kaldi/src`` subdirectories. 54 | -------------------------------------------------------------------------------- /compile-kaldi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd ${WORKING_DIR}/kaldi/tools 4 | 5 | # tools directory --> we'll only compile OpenFST 6 | OPENFST_VERSION=$(grep -oP "OPENFST_VERSION *\?= *\K(.*)$" ${WORKING_DIR}/kaldi/tools/Makefile) 7 | wget -T 10 -t 1 http://openfst.cs.nyu.edu/twiki/pub/FST/FstDownload/openfst-${OPENFST_VERSION}.tar.gz 8 | tar -zxvf openfst-${OPENFST_VERSION}.tar.gz 9 | cd openfst-${OPENFST_VERSION}/ 10 | CXX=clang++ ./configure --prefix=`pwd` --enable-static --enable-shared --enable-far --enable-ngram-fsts --host=arm-linux-androideabi LIBS="-ldl" 11 | make -j 4 12 | make install 13 | 14 | # source directory 15 | cd .. 16 | ln -s openfst-${OPENFST_VERSION} openfst 17 | cd ../src 18 | CXX=clang++ ./configure --static --android-incdir=${ANDROID_TOOLCHAIN_PATH}/sysroot/usr/include/ --host=arm-linux-androideabi --openblas-root=${WORKING_DIR}/OpenBLAS/install 19 | sed -i 's/-g # -O0 -DKALDI_PARANOID/-O3 -DNDEBUG/g' kaldi.mk 20 | make clean -j 21 | make depend -j 22 | make -j 4 23 | --------------------------------------------------------------------------------