forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.bash
executable file
·344 lines (297 loc) · 9.3 KB
/
install.bash
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/env bash
#
# Install script for Linux based Speech Recognition System
#
# Arpit Aggarwal
# 2018 TU Eindhoven
# Usage Document
usage()
{
echo "-----------------------------------------------------------------------------"
echo -e "\e[35m\e[1m Kaldi Automatic Speech Recognition \e[0m"
echo "-----------------------------------------------------------------------------"
echo "Usage: sudo ./install.bash [options] <values>"
echo -e "Options:\n \
-h | --help\n \
--tue\n \
--install-kaldi\n \
--update-kaldi\n \
--gst-plugin\n \
--clean"
echo
echo "-----------------------------------------------------------------------------"
}
KALDI_REPO="https://github.com/kaldi-asr/kaldi.git"
KALDI="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ASR_LOG=$KALDI/log
# Create Log directory
if [ ! -d "$ASR_LOG" ]
then
mkdir $ASR_LOG
fi
# Install the required packages and dependencies
sudo apt-get update -qq > /dev/null 2>&1
# Kaldi install dependencies
_kaldi_install_dependencies()
{
# Install base packages
sudo apt-get install --assume-yes build-essential git python python-numpy sox swig zip -qq > /dev/null 2>&1
echo "Checking and installing dependencies..."
# Change exit to return to source check_dependencies and change back once done
sed -i "s|exit|return|g" $KALDI/tools/extras/check_dependencies.sh
source $KALDI/tools/extras/check_dependencies.sh > /dev/null
sed -i "s|return|exit|g" $KALDI/tools/extras/check_dependencies.sh
# Install dependencies
sudo apt-get install libatlas3-base $debian_packages -qq > /dev/null 2>&1
}
# Kaldi check dependencies
_kaldi_check_dependencies()
{
echo "Checking dependencies..."
$KALDI/tools/extras/check_dependencies.sh > /dev/null
}
# Kaldi Build (Common to Installation and Update)
_kaldi_build_tools()
{
# Build toolkit
echo "Building toolkit..."
# Build the tools directory
cd $KALDI/tools
make -j 8 &> $ASR_LOG/make_tools.log
make_tools_status=$( tail -n 1 $ASR_LOG/make_tools.log )
if [ "$make_tools_status" != "All done OK." ]
then
echo -e "\e[34m\e[1m Make kaldi/tools failed \e[0m"
return 1
fi
echo " - Built tools"
}
_kaldi_build_irstlm()
{
# Install IRSTLM
# Remove IRSTLM dir if it exists else the install script fails
cd $KALDI/tools
if [ -d "irstlm" ]
then
rm -rf irstlm
fi
extras/install_irstlm.sh &> $ASR_LOG/install_irstlm.log
install_irstlm_status=$(grep "Installation of IRSTLM finished successfully" $ASR_LOG/install_irstlm.log )
if [ -z "$install_irstlm_status" ]
then
echo -e "\e[34m\e[1m Install kaldi/tools/extras/install_irstlm.sh failed \e[0m"
return 1
fi
echo " - Built IRSTLM"
}
_kaldi_build_sequitur()
{
# Install Sequitur
cd $KALDI/tools
extras/install_sequitur.sh &> $ASR_LOG/install_sequitur.log
install_sequitur_status=$(grep "Installation of SEQUITUR finished successfully" $ASR_LOG/install_sequitur.log)
if [ -z "$install_sequitur_status" ]
then
echo -e "\e[34m\e[1m Install kaldi/tools/extras/install_sequitur.sh failed \e[0m"
return 1
fi
echo " - Built SEQUITUR"
}
_kaldi_build_srilm()
{
# Install SRILM
cd $KALDI/tools
# Download SRILM if .tgz does not exist
if [ ! -f "srilm.tgz" ]
then
wget -q https://github.com/tue-robotics/kaldi_srilm/blob/master/srilm.tgz?raw=true -O srilm.tgz
fi
extras/install_srilm.sh &> $ASR_LOG/install_srilm.log
install_srilm_status=$(grep "Installation of SRILM finished successfully" $ASR_LOG/install_srilm.log)
if [ -z "$install_srilm_status" ]
then
echo -e "\e[34m\e[1m Install kaldi/tools/extras/install_srilm.sh failed \e[0m"
return 1
fi
echo " - Built SRILM"
}
_kaldi_build_src_cmake()
{
# Build src using CMake
cd $KALDI
# Remove existing STATUS file from previous build
if [ -f STATUS ]
then
rm STATUS
fi
# Remove existing build directory
if [ -d build ]
then
rm -rf build
fi
mkdir build
cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=../dist -DKALDI_BUILD_EXE=OFF -DKALDI_BUILD_TEST=OFF -DBUILD_SHARED_LIBS=ON ..
cmake --build . --target install || { echo "CMake build failed" && return 1; }
# Create a STATUS file to monitor installation
cd $KALDI
echo "ALL OK" > STATUS
}
_kaldi_build_src_make()
{
# Build the src directory
cd $KALDI/src
./configure --shared &> $ASR_LOG/configure_src.log
configure_src_status=$( grep "SUCCESS" $ASR_LOG/configure_src.log )
if [ -z "$configure_src_status" ]
then
echo -e "\e[34m\e[1m Configure kaldi/src failed \e[0m"
return 1
fi
echo " - Configured src for build"
# Make Kaldi without checks (ensures faster compilation)
sed -i '/-g # -O0 -DKALDI_PARANOID/c\-O3 -DNDEBUG' kaldi.mk
make depend -j 8 > /dev/null
make -j 8 &> $ASR_LOG/make_src.log
make_src_status=$( grep "Done" $ASR_LOG/make_src.log )
if [ -z "$make_src_status" ]
then
echo -e "\e[34m\e[1m Make kaldi/src failed \e[0m"
return 1
fi
echo " - Built src"
}
_kaldi_build()
{
_kaldi_build_tools || return 1
_kaldi_build_irstlm || return 1
_kaldi_build_sequitur || return 1
_kaldi_build_srilm || return 1
_kaldi_build_src_make || return 1
# Create a STATUS file to monitor installation
cd $KALDI
echo "ALL OK" > STATUS
}
# Kaldi Gstreamer plugin with online decoder build
_kaldi_online_gst()
{
echo "Building online decoder and gstreamer plugin..."
# Install PortAudio
cd $KALDI/tools
extras/install_portaudio.sh &> $ASR_LOG/install_portaudio.log
install_portaudio_status=$(grep "PortAudio was successfully installed" $ASR_LOG/install_portaudio.log)
if [ -z "$install_portaudio_status" ]
then
echo -e "\e[34m\e[1m Install kaldi/tools/extras/install_portaudio.sh failed \e[0m"
return 1
fi
echo " - Installed PortAudio"
# Build online decoder
cd $KALDI/src/online
make -j 8 &> $ASR_LOG/make_online.log || { echo -e "\e[34m\e[1m Make kaldi/src/online failed \e[0m"; return 1; }
echo " - Built online decoder"
# Build Gstreamer plugin
cd $KALDI/src/gst-plugin
make depend -j 8 > /dev/null
make -j 8 &> $ASR_LOG/make_gst-plugin.log || { echo -e "\e[34m\e[1m Make kaldi/src/gst-plugin failed \e[0m"; return 1; }
echo " - Built gstreamer plugin"
# Test Gstreamer plugin
export GST_PLUGIN_PATH=$KALDI/src/gst-plugin${GST_PLUGIN_PATH:+:${GST_PLUGIN_PATH}}
gst-inspect-1.0 onlinegmmdecodefaster > /dev/null || { echo -e "\e[34m\e[1m gst-inspect of onlinegmmdecodefaster failed \e[0m"; return 1; }
echo " - Gstreamer Plugin Test Successful"
}
# Kaldi Installation
kaldi_install()
{
echo "Checking for an existing Kaldi-ASR installation in $KALDI"
if [ ! -d "$KALDI" ]
then
# Clone repository into $KALDI
echo -e "No existing installation found. Cloning from GitHub repository"
git clone $KALDI_REPO $KALDI
_kaldi_install_dependencies
_kaldi_build
else
# Read STATUS file. If not "ALL OK", remove directory $KALDI and re-install Kaldi
kaldi_install_status="$(cat $KALDI/STATUS)"
if [ "$kaldi_install_status" != "ALL OK" ]
then
sudo rm -rf $KALDI
kaldi_install
fi
fi
}
# Kaldi Update
kaldi_update()
{
if [ ! -d "$KALDI" ]
then
# Install Kaldi if directory $KALDI not present
kaldi_install
else
# Read STATUS file. If "ALL OK" then update else remove directory $KALDI
# and re-install Kaldi
kaldi_install_status="$(cat $KALDI/STATUS)"
if [ "$kaldi_install_status" = "ALL OK" ]
then
# Pull changes from the repository
echo "Updating repository from GitHub"
cd $KALDI
git pull
# Clean existing make
_kaldi_clean
# Build toolkit
_kaldi_install_dependencies
_kaldi_build
echo -e "\e[36m\e[1m Kaldi-ASR update complete \e[0m"
else
sudo rm -rf $KALDI
kaldi_install
fi
fi
}
# Clean the repository
_kaldi_clean()
{
# Clean existing make
echo -e "\e[36m\e[1m Cleaning existing make \e[0m"
cd $KALDI/tools
make distclean
cd $KALDI/src
make distclean
# Remove anyother file not a part of the repository
cd $KALDI
git clean -fdx
}
# Read Postional Parameters
if [ -z "$1" ]
then
usage
else
while [ "$1" != "" ]
do
case $1 in
--install-kaldi )
kaldi_install
echo -e "\e[36m\e[1m Kaldi installation complete \e[0m" ;;
--update-kaldi )
kaldi_update ;;
--clean )
_kaldi_clean ;;
--gst-plugin )
_kaldi_online_gst ;;
--tue )
_kaldi_check_dependencies || exit 1
_kaldi_build_tools || exit 1
_kaldi_build_src_cmake || exit 1
echo -e "\e[36m\e[1m Kaldi installation complete \e[0m" ;;
-h | --help )
usage
exit 1 ;;
* )
usage
exit 1 ;;
esac
shift
done
fi