pocketSpinix 训练自己的声学模型(一)

来源:互联网 发布:淘宝的推广方式 编辑:程序博客网 时间:2024/05/19 19:41
 训练自己的声学模型
Jiangdg_VIP
http://blog.csdn.net/u012637501
   译自: http://cmusphinx.sourceforge.net/wiki/tutorialam
     声学模型主要用于计算语音特征和每个发音模板之间的似然度。目的是为每个声学单元建立一套模型参数(通过不断地学习和改进得到最优的,也就是概率最大的一组HMM模型参数)。我们知道CMUSphinx工具包里已经自带了几个性能较高的声学模型,比如有适用于麦克风或者新闻广播语音输入的美式英语声学模型,你也可以基于大量音频数据的法语或者中文声学模型。这些模型都能够获得很好的语音识别性能,并且大部分命令控制应用都可以直接使用他们,其中包括大词汇量识别系统。除了上述模型,CMUSphinx工具包也提供了一种改进声学模型的方法,这种方法对于大部分情况来说能使系统获取更高的识别率。当我们录音的环境不同(比如近距离录音、离麦克风较远以及电话语音)、出现不同的口音(比如英式英语、印度英语)或者另外一种语言时,这个对现有声学模型的改进是非常有效的。此外,如果我们需要快捷的为系统通过使用字典文件实现声学模型音素到目标音素的映射来添加对其他一些新的语言的支持,也可以利用改进现有声学模型的这种方法。
    然而,对于一些应用程序来说当前的这些模型却不能正常工作,如手写识别或听写对另一种语言的支持。所以,在这些特殊的情况下,我们需要训练自己的模型。本文主要介绍如何在CMUSphinx语音识别工程中训练自己的声学模型。在开始训练之前,我们需要确定自己是否已经熟悉相关的概念、准备训练好的语言模型以及好相关的训练工具。
1.什么情况下需要训练自己的声学模型?
(1)假如你需要为一门新的语言或者方言训练一个声学模型;
(2)或者你需要为你的小词汇量识别系统训练一个专门的声学模型;
(3)假如你有足够的数据(应该是指语料库)来训练,比如说:
    a.1人录音--1个小时的命令和控制音频文件-用于特定人识别
    b.200人录音--5个小时的音频文件-用于非特定人识别
    c.10 hours of recordings for single speaker dictation
    d.50 hours of recordings of 200 speakers for many speakers dictation
(4)假如你对语言的语音结构非常熟悉;
(5)假如你有足够的时间来训练模型和优化参数。
2.什么情况下无需训练声学模型?
(1)需要提高精确度-可以通过改进现有的声学模型来实现
(2)没有足够的数据来训练,即语料库比较小-也可以通过改进现有的声学模型来实现
(3)没有足有的时间训练模型和优化参数;
(4)没有足够的经验。
    总之,需要注意的是如果希望训练自己的声学模型,就必须需要大量的训练数据(大语料库)。如果你的数据比较少,会导致训练出来的声学模型质量很差,从而降低系统的识别率。
一、如何训练?
     SphinxTrain是CMU大学开发的开源声学模型训练器。此工具可以训练适应于PocketSphinx的半连续HMM声学模型,也可以训练应用于Sphinx3的连续HMM声学模型。训练工具通过使用一组语音信号样本的声音单元来获取模型的参数,我们可以将这个识别单元称之为训练的数据库,这个数据库主要为以声学模型的形式从语音信号中提取出来的统计数据。当然,我们在训练声学模型时也可以选择使用已经训练好的数据库。
    The trainer needs to be told which sound units you want it to learn the parameters of, and at least the sequence in which they occur in every speech signal in your training database. This information is provided to the trainer through a file called the transcript file, in which the sequence of words and non-speech sounds are written exactly as they occurred in a speech signal, followed by a tag which can be used to associate this sequence with the corresponding speech signal.然后,训练工具将会查看反映单词到声音单元序列的映射的字典文件,从而找到与声音单元相关的对应的语言信号。除了语音信号,我们还需要给出数据库的transcripts序列(在一个文件中)和两个字典文件,一是实现符合规则的单词到声音单元序列的映射;二是实现无声声音片段到相应无声或者近似有声的声音单元。我们在训练的过程中主要使用前者作为系统的语言字典文件,以及后者作为过补充。训练完后,我们强制性地运行解码器来检验训练的结果。解码器先获取一个声学模型,然后测试一部分训练数据和参考模型,最后估计出训练的模型质量。

博主笔记:训练自己的声学模型,首先我们需要设计一个用于训练的语音数据库(或者下载现有的),你的语音数据库应该能够比较好地代表你所要识别的语音,而且最好是多个人的录音数据,而且包含多种录音情况,还有所有可能的语言学句子。
    语音数据库包含两个部分:训练集和测试集,一般来说,测试集占全部数据库的1/10,但最好不要超过4个小时的录音时长。另外,我们也可以使用新闻广播录音来弥补代替录音数量的不足,也可以往训练的声音数据库添加需要的噪声
获得一个语音数据库的一个比较好的方式是:
1)对现有的你需要识别的语音的录音材料进行切割,例如新闻或者电台播音等;
2)把你身边的人,例如家人,朋友或者同事的语音录下来;
3)在voxforge上面收集

二、准备训练数据
   在进行训练之前先通过SphinxTrain中的wave2feat文件对音频文件进行特征提取,得到的MFCC特征参数文件,并把它们作为声学模型训练的输入。在进行训练之前,需要建立如下准备文件: 
    分别创建两个目录etc和wav,然后在两个目录下面制作一些数据文件,方便后面训练时使用。待会需要的目录及文件如下所示:
  • etc
    • your_db.dic - Phonetic dictionary
    • your_db.phone - Phoneset file
    • your_db.lm.DMP - Language model
    • your_db.filler - List of fillers
    • your_db_train.fileids - List of files for training
    • your_db_train.transcription - Transcription for training
    • your_db_test.fileids - List of files for testing
    • your_db_test.transcription - Transcription for testing
  • wav
    • speaker_1
      • file_1.wav - Recording of speech utterance
    • speaker_2
      • file_2.wav
下面对以上的文件作用做些说明:
1.your_db.dic - Phonetic dictionary
    主字典文件:该文件中包含要训练的所有词语以及与它们相对应的音素集(记录的是字到语音单元的映射)。如果某个词有两个以上的发音要分别列出。在训练之前,要指明如何将每一个数字的拼音拆解成声学模型。这里我们将数字的每一个音节看成一个声学模型,存放在字典文件中。文件的加载内容为:例如:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. 三SAN  
  2. 四SI  
  3. 五WU  
  4. 一YAO  
  5. 一(2) YI  
如果是英文的话,例如:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. HELLO HH AH L OW  
  2. WORLD W AO R L D  
另外,对于特殊字符,我们需要对其进行修改,此处不说了。
注意:
1.字典文件中每个单词为一行。Sphinxtrain不支持"*"和"/"特殊字符,但支持"+"、"-"、":",。
2.your_db.phone – Phone set file
    音素文件:表示声学模型训练单元,由于数字识别系统只包含10个词的小词汇量识别系统,所以我们的训练单元以这是个词的音节为训练基本单元即可。音素排列以26个字母顺序排列。在数字识别中主要选择音节作为识别单元,故音素文件中包括十二个单元:BA、ER、JIU、LING、LIU、QI、SAN、SI、SIL、WU、YAO、YI。其中SIL表示句子的停顿或静音,或者是录音环境的背景噪声。YAO和YI代表了数字1的两个发音。
例如,如果声学单元是音素的话,就是每个音素一行,最后加上SIL这个静音单元:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. AH  
  2. AX  
  3. DH  
  4. IX  
3.your_db.lm.DMP - Language model
语言模型文件:你在训练得到的语言模型,为ARPA格式或者DMP格式。
4.your_db.filler - List of fillers
    补充字典文件:该文件主要列举了非语音单词,它可以包括静音,背景噪声,或者mm,um或者呼吸,笑等等多音字的情况必须全部列出,除此文件外我们还要建立一个补充字典来说明语音中的停顿,当然这种静音(或停顿)可以理解为背景噪声。每个补充字典文件至少包含以下三项:
<s> SIL
</s> SIL
<sil> SIL
文件中的<s>代表句首的停顿,</s>代表句末的停顿,<sil>代表句中词间的停顿
    这些静音词汇共同对应音素SIL。
5.your_db_train.fileids - List of files for training
    控制文件:指明了包含所有训练语音文件的路径。需要注意的是,对于桌面应用程序则语音文件格式应为采样率为16KHZ、16位、单声道的wav格式文件;对于手机应用则采样率为8HZ、16位、单声道的wav格式。另外,语音音频文件录制的事件不应该太长也不应该太短,尽量使单个语音文件录制时间保持在5到30秒之间,并且静音片段出现在语音开始和结束不能超过0.2秒。
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. wav/train/name1/1.WAV  
  2. wav/train/name2/2.WAV  
注意:语音音频文件的格式不匹配一直是训练时出现的常见问题, Sphinxtrain训练工具支持多种采样率但是其默认的是16KHZ、16位wav格式。如果你需要训练采样率为8kHZ声学模型,你就需要在进行特征提取的时候配置正确。
6.your_db_train.transcription - Transcription for training
脚本文件: 存放每个控制文件(用于训练的)路径的内容(告诉训练器你需要训练哪些语音单元)。文件内容是与控制文件的路径一一对应的语句内容。包括句中的停顿也要用文本列举出来。例如:1.WAV录下的就是hello world这个句子的音,那文件的内容就是:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <s> hello world </s> (1)  
  2. <s> foo bar </s> (2)  
主要注意的是,每个行都需要以<s>开始和以 </s>结束,而且()括号内的语音文件只包含文件名,不包含文件路径。
7.your_db_test.fileids - List of files for testing
控制文件:指明了包含所有测试语音文件的路径
8.your_db_test.transcription - Transcription for testing
    脚本文件: 存放每个控制文件(用于测试的)路径的内容。

在准备这些文件的时候必须注意以下几点:
1)主字典和补充字典必须与音素文件相对应,即字典文件中不允许有音素文件中不存在的音素;
2)确保字典文件中没有重复的单词,不包括多音字的列举;
3)确保脚本文件和控制文件行数相同,并且一一对应;
4)确保脚本文件中的词都存在与字典文件中;
5)确保脚本文件中所有音素都存在于音素文件中,并且音素在训练的脚本文件中出现一次。
以上五点,如有一点不满足条件,训练将自动终止。
 
三、准备etc下的数据文件
[cpp] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # mkdir train  
  2. # cd train  
  3. # mkdir etc wav  
  4. # cd etc  
1、声音文件我是直接放在wav文件夹下的,命名如下(因为这样方便我用脚本去控制录音):
[cpp] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # vi my_db_train.fileids  
voice_0001
voice_0002
voice_0003
voice_0004
voice_0005
voice_0006
voice_0007
voice_0008
voice_0009
voice_0010
voice_0011
voice_0012
voice_0013
voice_0014
voice_0015
voice_0016
voice_0017
2、测试数据和语音数据一样,因为我并没有测试这个步骤,所以把简单的copy了一下:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # cp my_db_train.fileids my_db_test.fileids  
3、我的库主要是包含了17个控制的指令,如下:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #vi my_db_train.transcription  
<s> 确定 </s> (voice_0001)
<s> 取消 </s> (voice_0002)
<s> 关闭 </s> (voice_0003)
<s> 退出 </s> (voice_0004)
<s> 返回 </s> (voice_0005)
<s> 放大 </s> (voice_0006)
<s> 缩小 </s> (voice_0007)
<s> 音乐 </s> (voice_0008)
<s> 图片 </s> (voice_0009)
<s> 视频 </s> (voice_0010)
<s> 天气 </s> (voice_0011)
<s> 设置 </s> (voice_0012)
<s> 菜单 </s> (voice_0013)
<s> 向左 </s> (voice_0014)
<s> 向右 </s> (voice_0015)
<s> 向上 </s> (voice_0016)
<s> 向下 </s> (voice_0017)
4、
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #cp my_db_train.transcription my_db_test.transcription  
5、
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # vi my_db.dic  
确定 Q UE D ING
取消 Q U X IAO
关闭 G UAN B I
退出 T UI CH U
返回 F AN H UI
放大 F ANG D A
缩小 S UO X IAO
音乐 Y IN Y UE
图片 T U P IAN
视频 SH I P IN
天气 T IAN Q I
设置 SH E ZH IB
菜单 C AI D AN
向左 X IANG Z UO
向右 X IANG Y OU
向上 X IANG SH ANG
向下 X IANG X IA
6、
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #vi my_db.filler  
<s> SIL
</s> SIL
<sil> SIL
7、生成my_db.phone
[cpp] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #cp ../../sourcecode/sphinxtrain-1.0.7/scripts_pl/make_phoneset.pl .  
  2. #./make_phoneset.pl my_db.dic my_db.filler > my_db.phone  
  3. # vi my_db.phone //看下有没有多余的  
A
AI
AN
ANG
B
C
CH
D
E
F
G
H
I
IA
IAN
IANG
IAO
IB
IN
ING
OU
P
Q
S
SH
SIL
T
U
UAN
UI
UO
UX
UXE
X
Y
Z
ZH
      以上若有多余字母,可手工删除。
8、把之前的my_db.lm.DMP也拷贝到etc下。
    至此,etc下的数据文件已准备完毕。
注意:以上所有的文件在输入结尾不可留下“/n”。
 
四、准备wav下的音频文件
    为每一个控制词录制一个语音文件,录音文件的命名需要和my_db_train.transcription与my_db_train.fileids的一致。
注意:此处音频文件采样率16KHz,16bit单声道录音,而且是wav格式
我在Linux下写了一个处理脚本来实现上面这17个词的录音:rec_wav.sh,内容如下:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #cd ../wav  
  2. #vi rec_wav.sh  
for i in `seq 1 17`; do
       fn=`printf voice_%04d $i`;
       read sent; echo $sent;
       rec -r 16000 -e signed-integer -b 16 -c 1 $fn.wav 2>/dev/null;
done < ../etc/my_db.dic
在这里我们需要用到rec这个录音命令,这个命令是由Linux下一个很有名的音频转换程序sox携带的,所以我们需要先安装sox:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #apt-get install sox  
然后改变rec_wav.sh的运行属性:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #chmod 777 rec_wav.sh  
  2. #./rec_wav.sh  
这个脚本会显示一个词,然后进入录音,我们把这个词读出来,然后按ctrl+c显示下一个词,然后录音,如此循环到全部的词的语音数据拿到。这样在当前文件夹下面就会显示如下文件:
voice_0001.wav
voice_0002.wav
.....
voice_0017.wav
然后,我们需要测试下每个音频文件是否正常:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. for i in *.wav; do play $i; done  
他会依次的播放我们录下的这些音频文件;如果不对的话,就得重录,我的就没有什么问题。
五、an4与sphinxtrain搭建语音训练系统
an4是一个CMU在1991年录的音频数据库。具体见:
http://www.speech.cs.cmu.edu/databases/an4/
需要的包有: sphinxbase、SphinxTrain、pocketsphinx、perl和python,这两个是额外的需要安装的包,如果在windows下的话,建议使用ActivePerl。
1.配置训练脚本:
注意下面的sphinxtrain-0.8和pocketsphinx-0.8是我们当时下载解压的相应的源码目录。
[cpp] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #mkdir /host/xtrain  
  2. #cd /host/xtrain  
  3. # ../sourcecode/sphinxtrain-0.8/scripts_pl/setup_SphinxTrain.pl -task an4  
  4. # ../sourcecode/pocketsphinx-0.8/scripts/setup_sphinx.pl -task an4  
在当前目录下面会产生如下目录:
  bin
  bwaccumdir
  etc
  feat
  logdir
  model_parameters
  model_architecture
  scripts_pl
  wav
2.把(三)、(四)中etc、wav下面的文件相应的拷贝到刚生成的wav与etc中。
这时候xtrain目录的文件如下:
.
├── bin
│ ├── agg_seg
│ ├── batch.c
……
│ └── tiestate
├── bwaccumdir
├── etc
│ ├── feat.params
│ ├── make_phoneset.pl
│ ├── my_db.dic
│ ├── my_db.filler
│ ├── my_db.phone
│ ├── my_db_test.fileids
│ ├── my_db_test.transcription
│ ├── my_db.tmp.vocab
│ ├── my_db_train.fileids
│ ├── my_db_train.transcription
│ ├── sphinx_decode.cfg
│ └── sphinx_train.cfg
├── feat
├── logdir
├── model_architecture
├── model_parameters
├── scripts_pl
│ ├── 00.verify
│ │ └── verify_all.pl
│ ├── 01.lda_train
│ │ ├── baum_welch.pl
│ │ ├── lda_train.pl
│ │ ├── norm_and_launchbw.pl
│ │ ├── norm.pl
│ │ └── slave_lda.pl
……
│ ├── 90.deleted_interpolation
│ │ └── deleted_interpolation.pl
│ ├── bin
│ ├── bwaccumdir
│ ├── copy_setup.pl
│ ├── decode
│ │ ├── psdecode.pl
│ │ ├── setup_sphinx.pl
│ │ ├── setup_tutorial.pl
│ │ ├── slave.pl
│ │ ├── verify_dec.pl
│ │ └── word_align.pl
│ ├── etc
│ ├── feat
│ ├── lib
│ │ ├── Queue
│ │ │ ├── Job.pm
│ │ │ ├── PBS.pm
│ │ │ └── POSIX.pm
│ │ ├── Queue.pm
│ │ ├── SimpleConfig.pm
│ │ ├── SphinxTrain
│ │ │ ├── Config.pm
│ │ │ └── Util.pm
│ │ └── test_SimpleConfig.pl
│ ├── logdir
│ ├── make_feats.pl
│ ├── make_phoneset.pl
│ ├── maketopology.pl
│ ├── model_architecture
│ ├── model_parameters
│ ├── new_experiment.pl
│ ├── RunAll.pl
│ ├── setup_SphinxTrain.pl
│ ├── setup_tutorial.pl
│ ├── texFormat.pl
│ ├── tune_senones.pl
│ └── wav
├── setup_SphinxTrain.pl
└── wav
    ├── rec_wav.sh
    ├── test_wav.sh
    ├── voice_0001.wav
    ├── voice_0002.wav
……
    ├── voice_0016.wav
└── voice_0017.wav
 
3.需要修改etc文件夹下面的配置文件,还要修改很多变量;
修改etc/sphinx_train.cfg配置 
1)配置那些文件的路径
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # These are filled in at configuration time  
  2. $CFG_DB_NAME = "an4";  
  3. 改为  
  4. $CFG_DB_NAME = "my_db";  

修改环境变量(需root权限)
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
当然,如果你不想将上述库安装到系统路径,你也可以将其安装到用户目录,然后在修改环境变量。
在autogen.sh脚本或configure脚本添加内容:
--prefix=/home/user/local
注意:如果出现打开libsphinx.so.0失败或者提示没有该文件或目录,则说明你的环境变量配置不正确。

2)修改语音数据库的音频文件的格式
我们录制的是MSWav格式,所以修改sph为 wav ,修改nist为mswav。
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # Audio waveform and feature file information  
  2. $CFG_WAVFILES_DIR = "$CFG_BASE_DIR/wav";  
  3. $CFG_WAVFILE_EXTENSION = 'sph';  
  4. $CFG_WAVFILE_TYPE = 'nist'; # one of nist, mswav, raw  
  5. 改为  
  6. # Audio waveform and feature file information  
  7. $CFG_WAVFILES_DIR = "$CFG_BASE_DIR/wav";  
  8. $CFG_WAVFILE_EXTENSION = 'wav';  
  9. $CFG_WAVFILE_TYPE = 'mswav'; # one of nist, mswav, raw  
3)文件命名
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #*******variables used in main training of models*******  
  2. $CFG_DICTIONARY = "$CFG_LIST_DIR/$CFG_DB_NAME.dic";  
  3. $CFG_RAWPHONEFILE = "$CFG_LIST_DIR/$CFG_DB_NAME.phone";  
  4. $CFG_FILLERDICT = "$CFG_LIST_DIR/$CFG_DB_NAME.filler";  
  5. $CFG_LISTOFFILES = "$CFG_LIST_DIR/${CFG_DB_NAME}_train.fileids";  
  6. $CFG_TRANSCRIPTFILE = "$CFG_LIST_DIR/${CFG_DB_NAME}_train.transcription";  
  7. $CFG_FEATPARAMS = "$CFG_LIST_DIR/feat.params"  
确定etc下面的文件是以这种方式命名的。
$CFG_LIST_DIR变量是工程中/etc目录绝对路径、$CFG_DB_NAME为文件名;

博主笔记:$CFG_FINAL_NUM_DENSITIES = 8;
注意:如果你训练的连续声学模型是大词汇量并且训练的时间超过100小时,则设置为32.当然,这里还可以设置2、4、6、8、16、32、64几个等级。
# Number of tied states (senones) to create in decision-tree clustering
$CFG_N_TIED_STATES = 1000;
这条语句主要是用来设置在模型训练中sneones的数量,senones模型数量越多,更能准确的区分声音。但方面,过多的senones会导致模型不能很好的识别未定义的语音且会出现错误提示,为此对语音库的训练不能过度,否则会出现很多未定义senones。

4)配置模型类型与模型参数
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #*******variables used in characterizing models*******  
  2. $CFG_HMM_TYPE = '.cont.'; # Sphinx 4, Pocketsphinx  
  3. #$CFG_HMM_TYPE = '.semi.'; # PocketSphinx  
  4. #$CFG_HMM_TYPE = '.ptm.'; # PocketSphinx (larger data sets)  
 cont表示的是连续模型,semi表示半连续模型,是什么类型,就把前面的注销符号#去掉就行了,pocketsphinx和Sphinx III一样,都是.cont。
5)配置声音特征参数
这里的操作为采样率为8KHz的情况,若采样率为16KHz,则可以直接略过此步操作。
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. vi feat.params  
添加修改如下:
-samprate 8000.0
-nfilt 31
-lowerf 200.00
-upperf 3500.00
-dither yes

博主笔记:方法二-如果语音音频文件使用的是8KHZ采样率(电话语音),则需要修改etc/sphinx_train.cfg相关内容
# Feature extraction parameters
$CFG_WAVFILE_SRATE = 8000.0;
$CFG_NUM_FILT = 31; # For wideband speech it's 40, for telephone 8khz reasonable value is 31
$CFG_LO_FILT = 200; # For telephone 8kHz speech value is 200
$CFG_HI_FILT = 3500; # For telephone 8kHz speech value is 3500

6)配置解码参数etc/sphinx_decode.cfg
1)路径
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # These are filled in at configuration time  
  2. $DEC_CFG_DB_NAME = 'an4';  
  3. 改为  
  4. $DEC_CFG_DB_NAME = 'my_db';  
2)语言模型名称
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. # This variables, used by the decoder, have to be user defined, and  
  2. # may affect the decoder output  
  3. $DEC_CFG_LANGUAGEMODEL_DIR = "$DEC_CFG_BASE_DIR/etc";  
  4. $DEC_CFG_LANGUAGEMODEL = "$DEC_CFG_LANGUAGEMODEL_DIR/an4.lm.DMP";  
  5. 改为  
  6. # This variables, used by the decoder, have to be user defined, and  
  7. # may affect the decoder output  
  8. $DEC_CFG_LANGUAGEMODEL_DIR = "$DEC_CFG_BASE_DIR/etc";  
  9. $DEC_CFG_LANGUAGEMODEL = "$DEC_CFG_LANGUAGEMODEL_DIR/my_db.lm.DMP";  
4.开始训练
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #cd /host/xtrain  
  2. #./scripts_pl/make_feats.pl -ctl etc/my_db_train.fileids  
  3. #./scripts_pl/make_feats.pl -ctl etc/my_db_test.fileids  
  4. #./scripts_pl/RunAll.pl  
这需要几分钟的训练时间,但如果数据库很大的话,可能需要一个月的训练时间。整一个训练过程最重要的阶段是第一阶段,主要是检查所有的配置是否正确,还有输入的数据是够具有一致性。
新的声学模型在目录model_parameters中生成:
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. root@ubuntu:/host/xtrain/model_parameters# ls  
my_db.cd_cont_1000 my_db.cd_cont_1000_2 my_db.cd_cont_1000_8 my_db.cd_cont_untied my_db.ci_cont_flatinitial
my_db.cd_cont_1000_1 my_db.cd_cont_1000_4 my_db.cd_cont_initial my_db.ci_cont
命名规则是:
model_parameters/<your_db_name>.cd_cont_<number_of senones>
或者
model_parameters/<your_db_name>.cd_semi_<number_of senones>
每个模型目录的文件如下:
mdef
feat.params
mixture_weights
means
noisedict
transition_matrices
variances
5.测试使用
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. #cd /host/xtrain  
  2. # pocketsphinx_continuous -hmm model_parameters/my_db.cd_cont_1000 -lm etc/my_db.lm.DMP -dict etc/my_db.dic  
六、可能出现的问题
1.WARNING: this phone (something) appears in the dictionary (dictionary file name), but not in the phone list (phone file name). 
解决:Your dictionary either contains a mistake, or you have left out a phone symbol in the phone file. You may have to delete comment lines from your dictionary file.
2.WARNING: This word (word) has duplicate entries in (dictionary file name). Check for duplicates.
解决:You may have to sort your dictionary file lines to find them. Perhaps a word is defined in both upper and lower case forms.
3.WARNING: This word: word was in the transcript file, but is not in the dictionary (transcript line) Do cases match? 
解决:Make sure that all the words in the transcript are in the dictionary, and that they match case when they appear. Also, words in the transcript may be misspelled, run together or be a number or symbol not in the dictionary. If the dictionary file is not perfectly sorted, some entries might be skipped in looking for words. If you have hand-edited the dictionary file, be sure that each entry is in the proper format.
You may have specified phones in the phone list that are not represented in the words in the transcript. The trainer expects to find examples of each phone at least once. 
4.WARNING: CTL file, audio file name.mfc, does not exist, or is empty. 
解决:The .mfc files are the feature files converted from the input audio files on stage 000.comp_feats. Did you skip this step? Did you add new audio files without converting them? The training process expects a feature file to be there, and it isn't.
Very low recognition accuracy.
This might happen if there is a mismatch in the audio files and the parameters of training, or between the training and the testing.
5.ERROR: "backward.c", line 430: Failed to align audio to transcript: final state of the search is not reached.
解决:Sometimes audio in your database doesn't match the transcription properly. For example transcription file has the line “Hello world” but in audio actually “Hello hello world” is pronounced. Training process usually detects that and emits this message in the logs. If there are too many such errors it most likely mean you misconfigured something, for example you had a mismatch between audio and the text caused by transcription reordering. If there are few errors, you can ignore them. You might want to edit the transcription file to put there exact word which were pronounced, in the case above you need to edit the transcription file and put “Hello hello world” on corresponding line. You might want to filter such prompts because they affect acoustic model quality. In that case you need to enable forced alignment stage in training. To do that edit sphinx_train.cfg line
$CFG_FORCEDALIGN = 'yes';
and run training again. It will execute stages 10 and 11 and will filter your database.
6.Can't open */*-1-1.match word_align.pl failed with error code 65280
解决:This error occurs because the decoder did not run properly after training. First check if the correct executable (psdecode_batch if the decoding script being used is psdecode.pl as set by $DEC_CFG_SCRIPT variable in sphinx_train.cfg) is present in PATH. On Linux run 
which pocketsphinx_batch
and see if it is located. If it is not, you need to set the PATH variable properly. Similarly on Windows, run
where pocketsphinx_batch*
If the path to decoding executable is set properly, read the log files at logdir/decode/ to find out other reasons behind the error.

参考:http://blog.csdn.net/zouxy09/article/details/7962382
0 0
原创粉丝点击