Kaldi 入门使用教程

发布时间:2023-11-06 18:00

文章目录

  • 下载Kaldi
  • 编译安装
  • 运行TIMIT项目(失败)
    • 准备数据
    • 修改脚本
      • Error1
      • Error2
    • 对齐数据
    • 修改配置
      • Error1
  • aishell项目
  • 参考文献

下载Kaldi

git clone https://github.com/kaldi-asr/kaldi.git

需要安装大约120MB

编译安装

检查依赖,根据提示安装依赖库

cd kaldi/tools
extras/check_dependencies.sh

在这里插入图片描述
接着进行编译,这一步需要较长时间

make -j 8

make

cd ../src
./configure
make -j 8

运行yesno项目验证是否安装成功

cd ../egs/yesno/s5
./run.sh

validate

运行TIMIT项目(失败)

准备数据

下载TIMIT数据集,并放到kaldi\egs\timit\s5目录下。将其解压后生成data文件夹

unzip TIMIT.zip

修改脚本

修改cmd.sh的运行模式。我是在本地运行,所以修改为run.pl运行

# cmd.run

# export train_cmd="queue.pl --mem 4G"
# export decode_cmd="queue.pl --mem 4G"
# # the use of cuda_cmd is deprecated, used only in 'nnet1',
# export cuda_cmd="queue.pl --gpu 1"

export train_cmd="run.pl --max-jobs-run 10"
export decode_cmd="run.pl --max-jobs-run 10"
export cuda_cmd="run.pl --max-jobs-run 2"
export mkgraph_cmd="run.pl --max-jobs-run 10"

修改run.sh中数据集的目录以及cpu参数

# run.sh
feats_nj=10
train_nj=20
decode_nj=5
# timit=/mnt/matylda2/data/TIMIT/timit # @BUT
timit=<your workspace>/kaldi/egs/timit/s5/data/lisa/data/timit/raw/TIMIT # @BUT

Error1

运行过程中出现以下错误
Kaldi 入门使用教程_第1张图片
针对"Error: the IRSTLM is not available or compiled"解决方案如下:
到kaldi/tools/目录

cd ../../../tools/
extras/install_irstlm.sh

irstlm

Error2

重新./run.sh之后又出现以下错误:
Cannot find scoring program at //kaldi/egs/timit/s5/…/…/…/tools/sctk/bin/hubhubscr.pl
error2
tools目录下没有sctk,所以应该是需要重新编译sctk,但是解压自带的sctk-20159b5.tar.gz出错
Kaldi 入门使用教程_第2张图片
可能是由于最开始make的时候网速差没下全,压缩包不完整。因此重新下载该压缩包

cd ../../../tools
wget https://github.com/usnistgov/SCTK/archive/20159b5.tar.gz
mv 20159b5.tar.gz sctk-20159b5.tar.gz
tar -zxvf sctk-20159b5.tar.gz

重新编译一次

make clean
make -j 8
# Warning: IRSTLM is not installed by default anymore. If you need IRSTLM
# Warning: use the script extras/install_irstlm.sh
# All done OK.
extras/install_irstlm.sh
cd ../src
./configure
make -j 8

之后就运行成功了。但是如果把exit 0注释掉,继续运行下面的训练过程,就会报错!!ubm的问题
Kaldi 入门使用教程_第3张图片

Kaldi 入门使用教程_第4张图片

对齐数据

steps/nnet/align.sh --nj 4 data-fmllr-tri3/train data/lang exp/dnn4_pretrain-dbn_dnn exp/dnn4_pretrain-dbn_dnn_ali
steps/nnet/align.sh --nj 4 data-fmllr-tri3/dev data/lang exp/dnn4_pretrain-dbn_dnn exp/dnn4_pretrain-dbn_dnn_ali_dev
steps/nnet/align.sh --nj 4 data-fmllr-tri3/test data/lang exp/dnn4_pretrain-dbn_dnn exp/dnn4_pretrain-dbn_dnn_ali_test

Kaldi 入门使用教程_第5张图片

修改配置

修改pytorch-kaldi/cfg/TIMIT_baselines中的TIMIT_MLP_mfcc_basic.cfg路径。将kaldi路径修改为自己环境下kaldi的工作路径(记住用绝对路径)

[dataset1]
data_name = TIMIT_tr
fea = fea_name=mfcc
	fea_lst=/home/mirco/kaldi-trunk/egs/timit/s5/data/train/feats.scp
	# fea_opts=apply-cmvn --utt2spk=ark:/home/mirco/kaldi-trunk/egs/timit/s5/data/train/utt2spk  ark:/home/mirco/kaldi-trunk/egs/timit/s5/mfcc/cmvn_train.ark ark:- ark:- | add-deltas --delta-order=2 ark:- ark:- |
	fea_lst=/<your workspace>/kaldi/egs/timit/s5/data/train/feats.scp
	fea_opts=apply-cmvn --utt2spk=ark:/<your workspace>/kaldi/egs/timit/s5/data/train  ark:/<your workspace>/kaldi/egs/timit/s5/mfcc/cmvn_train.ark ark:- ark:- | add-deltas --delta-order=2 ark:- ark:- |
	cw_left=5
	cw_right=5
	

lab = lab_name=lab_cd
	# lab_folder=/home/mirco/kaldi-trunk/egs/timit/s5/exp/dnn4_pretrain-dbn_dnn_ali
	lab_folder=/<your workspace>/kaldi/egs/timit/s5/exp/dnn4_pretrain-dbn_dnn_ali
	lab_opts=ali-to-pdf
	lab_count_file=auto
	# lab_data_folder=/home/mirco/kaldi-trunk/egs/timit/s5/data/train/
	# lab_graph=/home/mirco/kaldi-trunk/egs/timit/s5/exp/tri3/graph
	lab_data_folder=/<your workspace>/kaldi/egs/timit/s5/exp/timit/s5/data/train/
	lab_graph=/<your workspace>/kaldi/egs/timit/s5/exp/timit/s5/exp/tri3/graph
	

n_chunks = 5

[dataset2]
data_name = TIMIT_dev
fea = fea_name=mfcc
	# fea_lst=/home/mirco/kaldi-trunk/egs/timit/s5/data/dev/feats.scp
	# fea_opts=apply-cmvn --utt2spk=ark:/home/mirco/kaldi-trunk/egs/timit/s5/data/dev/utt2spk  ark:/home/mirco/kaldi-trunk/egs/timit/s5/mfcc/cmvn_dev.ark ark:- ark:- | add-deltas --delta-order=2 ark:- ark:- |
	fea_lst=/<your workspace>/kaldi/egs/timit/s5/data/dev/feats.scp
	fea_opts=apply-cmvn --utt2spk=ark:/<your workspace>/kaldi/egs/timit/s5/data/dev/utt2spk  ark:/<your workspace>/kaldi/egs/timit/s5/mfcc/cmvn_dev.ark ark:- ark:- | add-deltas --delta-order=2 ark:- ark:- |
	cw_left=5
	cw_right=5
	

lab = lab_name=lab_cd
	# lab_folder=/home/mirco/kaldi-trunk/egs/timit/s5/exp/dnn4_pretrain-dbn_dnn_ali_dev
	lab_folder=/<your workspace>/kaldi/egs/timit/s5/exp/dnn4_pretrain-dbn_dnn_ali_dev
	lab_opts=ali-to-pdf
	lab_count_file=auto
	# lab_data_folder=/home/mirco/kaldi-trunk/egs/timit/s5/data/dev/
	# lab_graph=/home/mirco/kaldi-trunk/egs/timit/s5/exp/tri3/graph
	lab_data_folder=/<your workspace>/kaldi/egs/timit/s5/data/dev/
	lab_graph=/<your workspace>/kaldi/egs/timit/s5/exp/tri3/graph
	

n_chunks = 1

[dataset3]
data_name = TIMIT_test
fea = fea_name=mfcc
	# fea_lst=/home/mirco/kaldi-trunk/egs/timit/s5/data/test/feats.scp
	# fea_opts=apply-cmvn --utt2spk=ark:/home/mirco/kaldi-trunk/egs/timit/s5/data/test/utt2spk  ark:/home/mirco/kaldi-trunk/egs/timit/s5/mfcc/cmvn_test.ark ark:- ark:- | add-deltas --delta-order=2 ark:- ark:- |
	fea_lst=/<your workspace>/kaldi/egs/timit/s5/data/test/feats.scp
	fea_opts=apply-cmvn --utt2spk=ark:/<your workspace>/kaldi/egs/timit/s5/data/test/utt2spk  ark:/<your workspace>/kaldi/egs/timit/s5/mfcc/cmvn_test.ark ark:- ark:- | add-deltas --delta-order=2 ark:- ark:- |
	cw_left=5
	cw_right=5
	

lab = lab_name=lab_cd
	# lab_folder=/home/mirco/kaldi-trunk/egs/timit/s5/exp/dnn4_pretrain-dbn_dnn_ali_test
	lab_folder=/<your workspace>/kaldi/egs/timit/s5/exp/dnn4_pretrain-dbn_dnn_ali_test
	lab_opts=ali-to-pdf
	lab_count_file=auto
	# lab_data_folder=/home/mirco/kaldi-trunk/egs/timit/s5/data/test/
	# lab_graph=/home/mirco/kaldi-trunk/egs/timit/s5/exp/tri3/graph
	lab_data_folder=/<your workspace>/kaldi/egs/timit/s5/data/test/
	lab_graph=/<your workspace>/kaldi/egs/timit/s5/exp/tri3/graph

运行run_exp.py

python3 run_exp.py cfg/TIMIT_baselines/TIMIT_MLP_mfcc_basic.cfg

Error1

...
File "/mnt/ssddata2t1/yejianbin/asr/pytorch-kaldi/data_io.py", line 149, in _sort_chunks_by_length    
    fea_conc, lab_conc = zip(*fea_sorted)
 ValueError: not enough values to unpack (expected 2, got 0)
...
File "/mnt/ssddata2t1/yejianbin/asr/pytorch-kaldi/core.py", line 496, in run_nn
    data_name = shared_list[0]
IndexError: list index out of rangev

卡住!!!

aishell项目

建立数据保存的文件夹

mkdir export
mkdir export/a05
mkdir export/a05/xna
mkdir export/a05/xna/data

新建download下载数据的脚本

# download.sh
data=export/a05/xna/data
data_url=www.openslr.org/resources/33

. ./cmd.sh
. ./path.sh

set -e # exit on error

local/download_and_untar.sh $data $data_url data_aishell
local/download_and_untar.sh $data $data_url resource_aishell

参考文献

kaldi 笔记:运行 timit 例程脚本(部分)
语音识别之PyTorch-Kaldi详细教程

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号