ASR项目实战-构建Kaldi
【摘要】 基于Kaldi源码构建软件的的方法。
准备工作
安装构建时依赖的基础软件
软件清单如下:
bzip2
python3
automake
libtool
cmake
gcc
g++
gfortran
git
subversion
不同平台安装软件的方式不同,比如可以使用yum
或者apt-get
等。
下载开源软件
软件清单如下:
按照一定的规则,将下载后的文件放在指定目录,如下是样例
opensrc glog glog-0.4.0.zip Libunwind libunwind-1.3.1-src.zip Kaldi kaldi-master.zip OpenFST openfst-1.6.7.tar.gz OpenBLAS OpenBLAS-0.3.6.tar.gzinstall usr local bin sbin include lib lib64 script build.sh
构建脚本
build.sh
的内容,如下为样例:
BUILD_CORE_NUM=8 SCRIPT_FILE=`readlink -f $0`SCRIPT_ROOT=`dir ${SCRIPT_FILE}`BUILD_ROOT=`dir ${SCRIPT_ROOT}`SOURCE_ROOT=${BUILD_ROOT}/opensrc INSTALL_ROOT=${BUILD_ROOT}/install/usr/localexport INSTALL_ROOT PATH=${INSTALL_ROOT}/bin:${INSTALL_ROOT}/sbin:${PATH}export PATH LD_LIBRARY_PATH=${INSTALL_ROOT}/lib:${INSTALL_ROOT}/lib64:${LD_LIBRARY_PATH}export LD_LIBRARY_PATH# LibunwindVERSION=1.3.1 BUILD_LOG=${SCRIPT_ROOT}/Libunwind.outrm -f ${BUILD_LOG}touch ${BUILD_LOG}cd ${SOURCE_ROOT}/Libunwindrm -rf libunwind-${VERSION}unzip -o libunwind-${VERSION}-src.ziptar vxfz libunwind-${VERSION}.tar.gzcd libunwind-${VERSION}./autogen.sh CFLAGS="-fPIC -I${INSTALL_ROOT}/include" \ ./configure \ >> ${BUILD_LOG} 2>&1make -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1make install prefix=${INSTALL_ROOT} >> ${BUILD_LOG} 2>&1# glogVERSION=0.4.0 BUILD_LOG=${SCRIPT_ROOT}/glog.outrm -f ${BUILD_LOG}touch ${BUILD_LOG}cd ${SOURCE_ROOT}/glogrm -rf glog-${VERSION}tar vxfz glog-${VERSION}.tar.gzcd glog-${VERSION}./autogen.sh CXXFLAGS="-fPIC -I${INSTALL_ROOT}/include" \ LDFLAGS="-L${INSTALL_ROOT}/lib -L${INSTALL_ROOT}/lib64" \ ./configure \ --prefix=${INSTALL_ROOT} \ >> ${BUILD_LOG} 2>&1make -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1make install >> ${BUILD_LOG} 2>&1# OpenBLASVERSION=0.3.6 BUILD_LOG=${SCRIPT_ROOT}/OpenBLAS.outrm -f ${BUILD_LOG}touch ${BUILD_LOG}cd ${SOURCE_ROOT}/OpenBLASrm -rf OpenBLAS-${VERSION}rm -f OpenBLAStar vxfz OpenBLAS-${VERSION}.tar.gzln -s OpenBLAS-${VERSION} OpenBLAScd OpenBLAS-${VERSION}make -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1make PREFIX=${INSTALL_ROOT} install >> ${BUILD_LOG} 2>&1# OpenFSTVERSION=1.6.7 BUILD_LOG=${SCRIPT_ROOT}/OpenFST.outrm -f ${BUILD_LOG}touch ${BUILD_LOG}cd ${SOURCE_ROOT}/OpenFSTrm -rf openfst-${VERSION}tar vxzf openfst-${VERSION}.tar.gzcd openfst-${VERSION}CXXFLAGS="-fPIC -I${INSTALL_ROOT}/include" \ CFLAGS="-fPIC -I${INSTALL_ROOT}/include" \ LDFLAGS="-L${INSTALL_ROOT}/lib -L${INSTALL_ROOT}/lib64" \ LIBS="${INSTALL_ROOT}/lib/libglog.a -pthread -lunwind" \ ./configure \ --enable-static \ --enable-shared \ --enable-far \ --enable-ngram-fsts \ --prefix=${INSTALL_ROOT} \ >> ${BUILD_LOG} 2>&1make -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1make install >> ${BUILD_LOG} 2>&1# KaldiVERSION=master BUILD_LOG=${SCRIPT_ROOT}/Kaldi.outrm -f ${BUILD_LOG}touch ${BUILD_LOG}cd ${SOURCE_ROOT}/Kaldirm -rf kaldi-${VERSION}.ziprm -f kaldiunzip kaldi-${VERSION}.zipcd kaldi-${VERSION}/src CXXFLAGS="-fPIC -I${INSTALL_ROOT}/include" \ ./configure \ --static \ --openblas-root=${INSTALL_ROOT} \ --static-math=yes \ --threaded-math=yes \ --static-fst=yes \ --fst-version=1.6.7 \ --fst-root=${INSTALL_ROOT} \ --use-cuda=no \ >> ${BUILD_LOG} 2>&1make clean -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1make depend -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1make -j${BUILD_CORE_NUM} >> ${BUILD_LOG} 2>&1
注意事项
OpenFST自身实现一套日志系统,与glog集成时会报符号冲突。当前有用户在官网上提出类似的问题,但没有官方的答复。为了完整利用glog的能力,需要对OpenFST的实现做一定的修改。
修改点主要涉及如下几个文件:
src/include/log.h
,删除代码中相关的类和变量的定义。#include <fst/types.h>#include <fst/lock.h>using std::string;// 删除中间出现的代码#define ATTRIBUTE_DEPRECATED __attribute__((deprecated))#endif
src/include/flags.h
,在头部引入glog的头文件,增加如下代码:#include <fst/types.h>#include <fst/lock.h>#include "glog/logging.h" // 引入glog的头文件using std::string;
src/lib/flags.cc
,删除同名的变量。// DEFINE_int32(v, 0, "verbosity level");
若非注明,均为原创,欢迎转载,转载请注明来源:ASR项目实战-构建Kaldi
链接地址:http://www.jackieathome.net/archives/958.html
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)