-
Notifications
You must be signed in to change notification settings - Fork 6
/
install_kaldi.sh
executable file
·105 lines (92 loc) · 4.05 KB
/
install_kaldi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
#
# Copyright 2016 Thomas Schatz, Xuan-Nga Cao, Mathieu Bernard
#
# This file is part of abkhazia: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Abkhazia is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with abkahzia. If not, see <http://www.gnu.org/licenses/>.
# equivalent to $(readlink -f $1) but in pure bash (compatible with
# mac OS)
function realpath {
pushd `dirname $1` > /dev/null
echo $(pwd -P)
popd > /dev/null
}
# called on kaldi building errors
function failure { [ ! -z "$1" ] && echo $1; exit 1; }
# number of CPU cores on the machine, to do parallel compilation
if [ $(uname) == 'Darwin' ]; then
ncores=$(sysctl -a | grep machdep.cpu.core_count | cut -d: -f2 | tr -d ' ')
else
ncores=$(grep -c ^processor /proc/cpuinfo)
fi
# absolute path to the kaldi directory (where it is/will be downloaded
# and compiled)
kaldi=${1:-./kaldi}
# if the directory don't exist, clone our abkhazia kaldi fork in it,
# else fetch any new update.
if [ ! -d $kaldi ]
then
git clone --branch abkhazia --single-branch \
https://github.com/bootphon/kaldi.git $kaldi \
|| failure "failed to download kaldi from github"
else
cd $kaldi
git pull origin abkhazia || failure "failed to pull abkhazia branch"
git checkout abkhazia || failure "failed to checkout to abkhazia branch"
fi
kaldi=$(realpath $kaldi/src)
# From $kaldi/tools/extras/check_dependencies.sh. Debian systems
# generally link /bin/sh to dash, which doesn't work with some scripts
# as it doesn't expand x.{1,2}.y to x.1.y x.2.y
[[ $(realpath /bin/sh) == *"dash"* ]] && \
failure "failed because /bin/sh is linked to dash, and currently \
some of the scripts will not run properly. We recommend to run: \
sudo ln -s -f bash /bin/sh"
# make sure gfortran and clang++ are installed
[ -z $(which gfortran) ] && failure "error: gfortran not installed, please install it"
[ -z $(which clang++) ] && failure "error: clang++ not installed, please install it"
[ -z $(which gawk) ] && failure "error: gawk not installed, please install it"
# compile kaldi tools
cd $kaldi/tools
./extras/check_dependencies.sh || failure "failed to check kaldi dependencies"
# use clang instead of gcc, and openfst-1.4.1 instead of 1.3.4
sed -i "s/CXX = g++/# CXX = g++/" Makefile
sed -i "s/# CXX = clang++/CXX = clang++/" Makefile
sed -i "s/OPENFST_VERSION = 1.3.4/# OPENFST_VERSION = 1.3.4/" Makefile
sed -i "s/# OPENFST_VERSION = 1.4.1/OPENFST_VERSION = 1.4.1/" Makefile
make -j $ncores || failure "failed to build kaldi tools"
./extras/install_openblas.sh || failure "failed to install openblas"
# compile kaldi src
cd $kaldi/src
./configure --use-cuda=no --openblas-root=../tools/OpenBLAS/install \
|| failure "failed to configure kaldi"
# compile with optimizations and without debug symbols.
sed -i "s/\-g # -O0 -DKALDI_PARANOID.*$/-O3 -DNDEBUG/" kaldi.mk
# use clang instead of gcc
sed -i "s/ -rdynamic//g" kaldi.mk
sed -i "s/g++/clang++/" kaldi.mk
make depend -j $ncores || failure "failed to setup kaldi dependencies"
make -j $ncores || failure "failed to build kaldi"
# compile irstlm
cd $kaldi/tools/extras
rm -f install_irstlm.sh
wget https://raw.githubusercontent.com/kaldi-asr/kaldi/master/tools/extras/install_irstlm.sh
chmod +x install_irstlm.sh
wget https://raw.githubusercontent.com/kaldi-asr/kaldi/master/tools/extras/irstlm.patch
cd $kaldi/tools
./extras/install_irstlm.sh || failure "failed to install IRSTLM"
# compile srilm
wget https://github.com/denizyuret/nlpcourse/raw/master/download/srilm-1.7.0.tgz -O srilm.tgz
./extras/install_srilm.sh || failure "failed to install SRILM"
# forward the path to Kaldi to the configure script
export KALDI_PATH=$kaldi