Steps to create one ASR System Manually:
This is a step by step tutorial for absolute beginners on how to create a simple ASR (Automatic Speech Recognition) system in Kaldi toolkit using your own set of data. I really would have liked to read something like this when I was starting to deal with Kaldi. This is all based on my experience as an amateur in case of speech recognition subject and script programming as well.
If you have ever delved through Kaldi tutorial on the official project site and felt a little bit lost, well, my piece of art might be the choice for you. You will learn how to install Kaldi, how to make it work and how to run an ASR system using your own audio data.
Rule number 1 — use Linux. Although it is possible to use Kaldi on Windows, most people I find trustworthy convinced me that Linux will do the job with the less amount of problems. When you finally have your Linux running properly, please open a terminal and install some necessary stuff (if you do not already have it):
Must be Installed on your System:
· atlas — automation and optimization of calculations in the field of linear algebra,
· autoconf — automatic software compilation on different operating systems,
· automake — creating portable makefile files,
· git — distributed revision control system,
· libtool — creating static and dynamic libraries,
· svn — revision control system (Subversion), necessary for Kaldi download and installation,
· wget — data transfer using HTTP, HTTPS and FTP protocols,
· zlib — data compression,
kaldi — main Kaldi directory which contains:
· egs — example scripts allowing you to quickly build ASR systems for over 30 popular speech corpora (documentation is attached for each project),
· misc — additional tools and supplies, not needed for proper Kaldi functionality,
· src — Kaldi source code,
· tools — useful components and external tools,
· windows — tools for running Kaldi using Windows.
The most important directory for you is obviously egs. Here you will create your own ASR system.
Conditions:
1.You must have set of Audio files like in .wav format or you can record yours own audio data by spell something (letters or words) and your audio file name is also in whatever you spoke in your audio (This is for clarification and make easy way to understand)clearly.
2.Must install above given things.
Development Procedures:
1. Create a folder “asrdev” in kaldi/egs/ directory. This is a place where you will put all the stuff related to your project.
2.Audio data must be in clear format like each file contains 3 spoken digits recorded in English language, one by one. Each of these audio files is named in a recognizable way (e.g. 1_5_6.wav, which in my pattern means that the spoken sentence is ‘one, five, six’) and placed in the recognizable folder representing particular speaker during a particular recording session.
3.Go to kaldi/egs/asrdev directory and create workinterfolder. In kaldi/egs/asrdev/workinter create two folders: train and test. Consider you have 60 audio files ,amoung the 60 audio files, 30 audio files belongs to one speaker/person voice and another 30 audio files belongs to another person’s voice. So in the test directory,first take all the audio files belongs to first person and make one newfolder named as the first audio file name of the first person directory and paste first 30 audio files into it.Then take another person’s voice audio files and make one newfolder named as first audio file name of second person directory and paste another 30 audio files into it.
4. In kaldi/egs/asrdev directory, create a folder data. Then create test and train subfolders inside. Create in each subfolder following files (so you have files named in the same way in test and train subfolders but they relate to two different datasets that you created before):
Inside both test and train directory , make the following files manually or by using Scripts.
a.) spk2gender
This file informs about speakers gender.
This file informs about speakers gender.
Pattern: <speakerID> <gender>
Example : arjunan m
aarthi f
b.) wav.scp
This file connects every utterance (sentence said by one person during particular recording session) with an audio file related to this utterance.
This file connects every utterance (sentence said by one person during particular recording session) with an audio file related to this utterance.
Pattern: <uterranceID> <full_path_to_audio_file>
Example : utteranceID means the name of the audio file and with full path of the audio file associated.
lakshmi_3_4_1/kaldidjango/kaldi/egs/asrdev/workinter/train/lakshmi/3_4_1.wav
c.) text
This file contains every utterance matched with its text transcription.
This file contains every utterance matched with its text transcription.
Pattern: <uterranceID> <text_transcription>
Example : lakshmi_3_4_1 three four one
d.) utt2spk
This file tells the ASR system which utterance belongs to particular speaker.
This file tells the ASR system which utterance belongs to particular speaker.
Pattern: <uterranceID> <speakerID>
Example : lakshmi_3_4_1 lakshmi
e.) corpus.txt
This file has a slightly different directory. In kaldi/egs/asrdev/data create another folder local. In kaldi/egs/asrdev/data/local create a file corpus.txt which should contain every single utterance transcription that can occur in your ASR system
This file has a slightly different directory. In kaldi/egs/asrdev/data create another folder local. In kaldi/egs/asrdev/data/local create a file corpus.txt which should contain every single utterance transcription that can occur in your ASR system
Pattern: <text_transcription>
Example : two five six
one like ten i.e., these are utterance of all audio files you have created and injected.
5.In kaldi/egs/asrdev/data/local directory, create a folder dict. In kaldi/egs/asrdev/data/local/dict create following files:
a.) lexicon.txt
This file contains every word from your dictionary with its ‘phone transcriptions’ .Phone transcription is simply says as Phonomes derived from acoustic data.
This file contains every word from your dictionary with its ‘phone transcriptions’ .Phone transcription is simply says as Phonomes derived from acoustic data.
Pattern: <word> <phone 1> <phone 2> …
!SIL sil
<UNK> spn
eight ey t
b.) nonsilence_phones.txt
This file lists nonsilence phones that are present in your project.
This file lists nonsilence phones that are present in your project.
Pattern: <phone>
ah,ao,ay,eh,ey,f,hh,ih etc.,
c.) silence_phones.txt
This file lists silence phones.
This file lists silence phones.
Pattern: <phone>
sil
spn
d.) optional_silence.txt
This file lists optional silence phones.
This file lists optional silence phones.
Pattern: <phone>
sil
6. From kaldi/egs/wsj/s5 copy two folders (with the whole content) — utils and steps — and put them in your kaldi/egs/asrdev directory. You can also create links to these directories.This script will help you to get decoding results.
You need to install below things for proper executions:
1.Insatall gawk package as sudo apt-get install gawk
2.Install SRILM
2.1 Simply running /tools/extras/install_srilm.sh cannot install srilm automatically.
The right procedure is as follows.
2.2 Download srilm package from http://www.speech.sri.com/projects/srilm/download.html.
2.3 Rename the package as “srilm.tgz”.
2.4 Copy the package to /tools.
2.5 Run /tools/extras/install_srilm.sh.
2.6 Source /tools/env.sh.
In kaldi/egs/asrdev create a folder conf. Inside kaldi/egs/asrdev/conf create two files (for some configuration modifications in decoding and mfcc feature extraction processes — taken from /egs/voxforge):
a.) decode.config
first_beam=10.0
beam=13.0
lattice_beam=6.0
b.) mfcc.conf
— use-energy=false
Copy the above code and make two configuration files like decode and mfcc. You can change the different Configurations you want.
7. Last but not Least.you need to create 3 script files for running your ASR system.This is coding part taken from official kaldi documentation.Changes in path and run script necessary if you going to develop new ASR System.
a.) cmd.sh
# Setting local system jobs (local CPU — no external clusters)
export train_cmd=run.pl
export decode_cmd=run.pl
b.) path.sh
# Defining Kaldi root directory
export KALDI_ROOT=`pwd`/../..
# Setting paths to useful tools
export PATH=$PWD/utils/:$KALDI_ROOT/src/bin:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/src/fstbin/:$KALDI_ROOT/src/gmmbin/:$KALDI_ROOT/src/featbin/:$KALDI_ROOT/src/lmbin/:$KALDI_ROOT/src/sgmm2bin/:$KALDI_ROOT/src/fgmmbin/:$KALDI_ROOT/src/latbin/:$PWD:$PATH
# Defining audio data directory (modify it for your installation directory!)
export DATA_ROOT=”/home/{user}/kaldi/egs/asrdev/workinter”
# Enable SRILM
. $KALDI_ROOT/tools/env.sh
# Variable needed for proper data sorting
export LC_ALL=C
c.) run.sh
#!/bin/bash
. ./path.sh || exit 1
. ./cmd.sh || exit 1
nj=1 # number of parallel jobs — 1 is perfect for such a small dataset
lm_order=1 # language model order (n-gram quantity) — 1 is enough for digits grammar
# Safety mechanism (possible running this script with modified arguments)
. utils/parse_options.sh || exit 1
[[ $# -ge 1 ]] && { echo “Wrong arguments!”; exit 1; }
# Removing previously created data (from last run.sh execution)
rm -rf exp mfcc data/train/spk2utt data/train/cmvn.scp data/train/feats.scp data/train/split1 data/test/spk2utt data/test/cmvn.scp data/test/feats.scp data/test/split1 data/local/lang data/lang data/local/tmp data/local/dict/lexiconp.txt
echo
echo “===== PREPARING ACOUSTIC DATA =====”
echo
# Needs to be prepared by hand (or using self written scripts):
#
# spk2gender [<speaker-id> <gender>]
# wav.scp [<uterranceID> <full_path_to_audio_file>]
# text [<uterranceID> <text_transcription>]
# utt2spk [<uterranceID> <speakerID>]
# corpus.txt [<text_transcription>]
# Making spk2utt files
utils/utt2spk_to_spk2utt.pl data/train/utt2spk > data/train/spk2utt
utils/utt2spk_to_spk2utt.pl data/test/utt2spk > data/test/spk2utt
echo
echo “===== FEATURES EXTRACTION =====”
echo
# Making feats.scp files
mfccdir=mfcc
# Uncomment and modify arguments in scripts below if you have any problems with data sorting
# utils/validate_data_dir.sh data/train # script for checking prepared data — here: for data/train directory
# utils/fix_data_dir.sh data/train # tool for data proper sorting if needed — here: for data/train directory
steps/make_mfcc.sh — nj $nj — cmd “$train_cmd” data/train exp/make_mfcc/train $mfccdir
steps/make_mfcc.sh — nj $nj — cmd “$train_cmd” data/test exp/make_mfcc/test $mfccdir
# Making cmvn.scp files
steps/compute_cmvn_stats.sh data/train exp/make_mfcc/train $mfccdir
steps/compute_cmvn_stats.sh data/test exp/make_mfcc/test $mfccdir
echo
echo “===== PREPARING LANGUAGE DATA =====”
echo
# Needs to be prepared by hand (or using self written scripts):
#
# lexicon.txt [<word> <phone 1> <phone 2> …]
# nonsilence_phones.txt [<phone>]
# silence_phones.txt [<phone>]
# optional_silence.txt [<phone>]
# Preparing language data
utils/prepare_lang.sh data/local/dict “<UNK>” data/local/lang data/lang
echo
echo “===== LANGUAGE MODEL CREATION =====”
echo “===== MAKING lm.arpa =====”
echo
loc=`which ngram-count`;
if [ -z $loc ]; then
if uname -a | grep 64 >/dev/null; then
sdir=$KALDI_ROOT/tools/srilm/bin/i686-m64
else
sdir=$KALDI_ROOT/tools/srilm/bin/i686
fi
if [ -f $sdir/ngram-count ]; then
echo “Using SRILM language modelling tool from $sdir”
export PATH=$PATH:$sdir
else
echo “SRILM toolkit is probably not installed.
Instructions: tools/install_srilm.sh”
exit 1
fi
fi
local=data/local
mkdir $local/tmp
ngram-count -order $lm_order -write-vocab $local/tmp/vocab-full.txt -wbdiscount -text $local/corpus.txt -lm $local/tmp/lm.arpa
echo
echo “===== MAKING G.fst =====”
echo
lang=data/lang
arpa2fst — disambig-symbol=#0 — read-symbol-table=$lang/words.txt $local/tmp/lm.arpa $lang/G.fst
echo
echo “===== MONO TRAINING =====”
echo
steps/train_mono.sh — nj $nj — cmd “$train_cmd” data/train data/lang exp/mono || exit 1
echo
echo “===== MONO DECODING =====”
echo
utils/mkgraph.sh — mono data/lang exp/mono exp/mono/graph || exit 1
steps/decode.sh — config conf/decode.config — nj $nj — cmd “$decode_cmd” exp/mono/graph data/test exp/mono/decode
echo
echo “===== MONO ALIGNMENT =====”
echo
steps/align_si.sh — nj $nj — cmd “$train_cmd” data/train data/lang exp/mono exp/mono_ali || exit 1
echo
echo “===== TRI1 (first triphone pass) TRAINING =====”
echo
steps/train_deltas.sh — cmd “$train_cmd” 2000 11000 data/train data/lang exp/mono_ali exp/tri1 || exit 1
echo
echo “===== TRI1 (first triphone pass) DECODING =====”
echo
utils/mkgraph.sh data/lang exp/tri1 exp/tri1/graph || exit 1
steps/decode.sh — config conf/decode.config — nj $nj — cmd “$decode_cmd” exp/tri1/graph data/test exp/tri1/decode
echo
echo “===== run.sh script is finished =====”
echo
After you running the run.sh file in command prompt,your’s ASR system has been created.
Check the those folder made in your directory like exp after your run the run.sh script.In this directory all the necessary data and files have been created and also in your data folder you notice that the lang directories and necessary files are created.
Thank You(நன்றி) for making ASR System with me!!
By P.LakshmiNarayanan B.Tech Information Technology.
Comments
Post a Comment