嵌入式平臺kaldi源碼的交叉編譯

該博文屬於系列文章,其他文章參考總覽: kaldi嵌入式平臺的移植及實現

 

前言:

在編譯kaldi源碼時,請先參照 https://www.jianshu.com/p/05e1bbe0ca3a 這篇文章在x86平臺能夠編譯後,再進行以下操作。

Kaldi交叉編譯:

1. 確保openfst已經編譯完成(見openFst的交叉編譯 ),並且存放路徑爲:kaldi/tools/openfst/include/   kaldi/tools/openfst/lib/ 

2. 確保openBlas和Clapack編譯完成,並且拷貝Clapack編譯生成的lib庫(見數學庫OpenBlas及Clapack的交叉編譯):libblas.a libclapack.a libf2c.a至OpenBLAS/install/lib下

3. 切換到kaldi/src目錄,執行

CXX=mips-linux-gnu-g++ AR=mips-linux-gnu-ar AS=mips-linux-gnu-as RANLIB=mips-linux-gnu-ranlib ./configure --static --use-cuda=no --openblas-root=/home/xxx/OpenBLAS-master/install --clapack-root=/home/xxx/OpenBLAS-master/install

以上參數 /home/xxx/OpenBLAS-master/install 是我openBlas編譯完成後存放的路徑,install目錄結構如下:

4. 執行完步驟3的命令後,出現如下信息:

Configuring KALDI to use CLAPACK
Configuring KALDI to use OPENBLAS
Configuring ...
Checking compiler mips-linux-gnu-g++ ...
Checking OpenFst library in /home/chenjiang/work/kaldi/tools/openfst ...
Doing OS specific configurations ...
On Linux: Checking for linear algebra header files ...
Your math library seems to be OpenBLAS from /home/chenjiang/OpenBLAS-master/install.  Configuring appropriately.
Configuring static OpenBlas since --static-math=yes
Successfully configured for Linux with OpenBLAS from /home/chenjiang/OpenBLAS-master/install
Info: configuring Kaldi not to link with Speex (don't worry, it's only needed if you
intend to use 'compress-uncompress-speex', which is very unlikely)
mips-linux-gnu-g++: error: unrecognized command line option '-msse'
mips-linux-gnu-g++: error: unrecognized command line option '-msse2'

make: *** [exp-test] Error 1
./configure: 行 206: ./exp-test: 沒有那個文件或目錄
SUCCESS
To compile: make clean -j; make depend -j; make -j
 ... or e.g. -j 10, instead of -j, to use a specified number of CPUs

修改kaldi.mk文件,修正紅色錯誤及添加libblas.a libclapack.a libf2c.a的鏈接庫

a. 添加藍色部分內容

OPENBLASINC = /home/xxx/OpenBLAS-master/install/include
OPENBLASLIBS = /home/xxx/OpenBLAS-master/install/lib/libopenblas.a -lgfortran
OPENBLASLIBS += /home/xxx/OpenBLAS-master/install/lib/libclapack.a 
OPENBLASLIBS += /home/xxx/OpenBLAS-master/install/lib/libblas.a
OPENBLASLIBS += /home/xxx/OpenBLAS-master/install/lib/libf2c.a

b. 刪除 -msse -msse2 參數

5. make depend -j4

6 make -j4

若無錯誤,則編譯完成。

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

onlinebin解碼器交叉編譯

    kaldi默認情況下是不編譯onlinebin下面的解碼器,因爲onlinebin下面的解碼器支持在線識別(online-gmm-decode-faster)功能,online-wav-gmm-decode-faster支持音頻文件來解碼結果,若需要用音頻文件來解碼,建議採用online2bin下面的解碼器,因爲online2bin的解碼器在更新中,而onlinebin解碼器已不再更新,編譯此解碼器的原因:感受下在線識別的效果,爲後面online2bin wav解碼改在線解碼作鋪墊。

1. 進入onlinebin文件夾, 修改Makefile文件

I) Makefile中加入portaudio庫(見音頻框架portaudio的交叉編譯

EXTRA_CXXFLAGS += -Wno-sign-compare -I/home/xxx/portaudio/include

# The PA_RingBuffer interface is internal and is not exported in the .so libray
# so we have to link against the static one

ifneq "$(wildcard ../../tools/portaudio/lib/libportaudio.a)" ""
    EXTRA_LDLIBS = /home/xxx/portaudio/lib/libportaudio.a
else
    EXTRA_LDLIBS = /home/xxx/portaudio/lib/libportaudio.a
endif

II) Makefile中加入Alsa庫(見音頻接口Alsa的交叉編譯

UNAME=$(shell uname)
ifeq ($(UNAME), Linux)
  ifneq ($(wildcard ../../tools/portaudio/install/include/pa_linux_alsa.h),)
    EXTRA_LDLIBS += /home/xxx/alsa/lib/libasound.so -lrt
  else
    EXTRA_LDLIBS += -lrt
  endif
endif

2. 進入online目錄,修改Makefile文件,加入portaudio庫

EXTRA_CXXFLAGS += -Wno-sign-compare -I/home/xxx/portaudio/include

將所有的 ../../tools/portaudio/lib/libportaudio.a 修改爲 /home/xxx/portaudio/lib/libportaudio.a

3. 進入onlinebin目錄,執行make

如果沒有問題的話,應該會生成可執行文件 online-gmm-decode-faster 和 online-wav-gmm-decode-faster,利用file查看可執行文件屬性,如下:

file online-gmm-decode-faster
online-gmm-decode-faster: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 2.6.32, stripped

 

以上kaldi源碼在嵌入式平臺的移植已經完成,接下來在嵌入式平臺運行相應的解碼器。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章