嵌入式平台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目录结构如下:

嵌入式平台kaldi源码的交叉编译_第1张图片

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源码在嵌入式平台的移植已经完成,接下来在嵌入式平台运行相应的解码器。

你可能感兴趣的:(Linux,语音识别)