语音识别工具Kaldi安卓库编译

 注意:整个配置都在同一个终端下执行!整个配置都在同一个终端下执行!整个配置都在同一个终端下执行!

1. Android NDK配置(本教程基于 ndk16rb)

         1) NDK下载:

      wget -q --output-document=android-ndk.zip https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip

               2) NDK配置:

           cd  / opt /android-ndk-r16b/build/tools

           python make_standalone_toolchain.py --arch arm --api 21 --stl=libc++ --install-dir /tmp/my-android-toolchain
           export PATH=/tmp/my-android-toolchain/bin:$PATH

 2. OPENBLAS(本教程基于0.2.20版本)

        通过ndk16b 和ndk19c 对openblas0.2.19和0.3.7版本进行arm7的编译都出现不同错误,通过arm8的可以编译,由于网上教  程都是基于arm7的,故先编译arm7的版本

     cd OpenBLAS

    export NDK_BUNDLE_DIR=/opt/android-ndk-r16b/

    export PATH=${NDK_BUNDLE_DIR}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:${NDK_BUNDLE_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH

    export CLANG_FLAGS="-target arm-linux-androideabi -marm -mfpu=vfp -mfloat-abi=softfp --sysroot /tmp/my-android-toolchain/sysroot -gcc-toolchain ${NDK_BUNDLE_DIR}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/"

    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

    make install NO_SHARED=1 PREFIX=`pwd`/install

3. CLAPACK

    git clone https://github.com/simonlynen/android_libs.git

    cd android_libs/lapack/

    修改Andorid.mk文件

        sed -i  's/LOCAL_MODULE:= testlapack/#LOCAL_MODULE:= testlapack/g' jni/Android.mk

        sed -i 's/LOCAL_SRC_FILES:= testclapack.cpp/#LOCAL_SRC_FILES:= testclapack.cpp/g' jni/Android.mk

        sed -i 's/LOCAL_STATIC_LIBRARIES := lapack/#LOCAL_STATIC_LIBRARIES := lapack/g' jni/Android.mk

        sed -i 's/include $(BUILD_SHARED_LIBRARY)/#include $(BUILD_SHARED_LIBRARY)/g' jni/Android.mk

    修改/lapack/jni/Application.mk文件:

         APP_STL:=gnustl_static, 把gnustl-static改为c++_static; APP_ABI:=armeabi armeabi-v7a ,把armeabi去掉
    执行 /opt/android-ndk-r16b/ndk-build

将生成的库拷贝到openblas下面

    cp -r obj/local/armeabi-v7a/* /opt/OpenBLAS/install/lib/

4. Kaldi编译

      git clone https://github.com/kaldi-asr/kaldi.git kaldi-android

1) openfst编译(本教程基于1.6.5)
                    export PATH=/tmp/my-android-toolchain/bin:$PATH

                     cd kaldi-android/tools

                     wget -T 10 -t 1 http://openfst.cs.nyu.edu/twiki/pub/FST/FstDownload/openfst-1.6.5.tar.gz

                     tar -zxvf openfst-1.6.5.tar.gz

                     cd openfst-1.6.5/

                     CXX=clang++ ./configure --prefix=`pwd` --enable-static --enable-shared --enable-far --enable-ngram-fsts --host=arm-linux-androideabi LIBS="-ldl"

                      make -j 4

                      make install
         2) cub编译(本教程基于1.8.0)

                      make cub

                      cd ..

      ln -s openfst-1.6.5 openfst

         3) 编译src

    cd ../src

 打开 matrix/Makefile 文件,将其中的测试文件注释掉。

      #TESTFILES = matrix-lib-test sparse-matrix-test #matrix-lib-speed-tes

 #Be sure android-toolchain is in your $PATH before the next stepCXX=clang++ ./configure --static --android-incdir=/tmp/my-android-toolchain/sysroot/usr/include/ --host=arm-linux-androideabi --openblas-root=/path/to/OpenBLAS/install –use-cuda=noYou may want to compile Kaldi without debugging symbols.#In this case, do:sed -i 's/-g # -O0 -DKALDI_PARANOID/-O3 -DNDEBUG/g' kaldi.mkmake clean -jmake depend -jmake -j 4

最终生成的库在src下面的各个模块的目录下

 

参考文档

http://jcsilva.github.io/2017/03/18/compile-kaldi-android/

https://www.jianshu.com/p/a896bc4c3c14

https://www.jianshu.com/p/905214cedf97

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值