Pocketsphinx语音识别-----语言模型训练和声学模型的适应过程

来源:互联网 发布:mac 怎么设置无线鼠标 编辑:程序博客网 时间:2024/04/30 23:55

更新一下,之前对于txt, transcription, fileid文件的对应关系一直有疑惑。今天通过实验证明,transcription和fileid直接行行对应即可。这样就可以添加多个人录音,对应相同一句话的问题了。!!!

训练语言模型:

两种方法

1.对于小文本量&&英文,直接采用登录网站方式来生成语言模型lm和字典dic

利用在线工具LMTool建立语言模型,具体网址:http://www.speech.cs.cmu.edu/tools/lmtool-new.html

2.其他情况,比如大数据量的或中文,需要采用如下方法来生成语言模型。

输入:语料文本

输出: arpa或dmp文件。可相互转换。

另外,字典需要自己制造。就是dic文件,规则类似与拼音,但还不完全一样,后面在研究这个。


如何生成语言模型

准备工作,自己造一个语料库,即robot.txt文本文件。格式为:<s> 语料内容 </s> 注意<s>之后和</s>之前均应当有空格。

中间过程文件:$name.vocab  $name.idngram  $name.arpa文件,用完可删除。使用脚本./lm.sh robot.txt即可一次性生成输出文件。

输出有用文件: $name.lm.DMP

1. text2wfreq < robot.txt | wfreq2vocab > robot.vocab   生成arctic20.vocab文件

2. text2idngram -vocab robot.vocab -idngram robot.idngram < robot.txt  生成robot.idngram文件

3. idngram2lm -vocab_type 0 -idngram robot.idngram -vocab robot.vocab -arpa robot.arpa  依据第1,2步的输出,生成arpa文件

4.sphinx_lm_convert -i robot.arpa -o robot.lm.DMP   根据需要,将arpa文件转成dmp文件,对于pocketsphinx可省略。两种格式都认识。

对于第四步,如果需要转换的话,举例说明互转换的方法:

sphinx_lm_convert -i model.lm -o model.dmpsphinx_lm_convert -i model.dmp -ifmt dmp -o model.lm -ofmt arpa适应声学模型(Adapting the default acoustic model)在升学模型基础上适应特殊人的升学特征,而不是重新训练一种新的声学模型。输入文件:语料文件,字典文件,路径文件,转换文件

1. 首先我们需要先拷贝现有的默认的声学模型到当前目录下

#cp -a /usr/local/share/pocketsphinx/model/hmm/zh/tdt_sc_8k/ .

这个是pocketsphinx自带的中文声学模型

2. 生成声学特征文件(由wav生成mfc文件)#sphinx_fe -argfile tdt_sc_8k/feat.params -samprate 16000 -c arctic20.fileids -di . -do . -ei wav -eo mfc -mswav yes3. 转化sendumpmdef文件从sendump生成mixture_weight或从pocketsphinx-extra中拷贝出一份转换mdef到mdef.txt4.累加观察序列 overall> stats 5619 (-0) -6.602351e+01 -3.709861e+05 0.010x 1.376eWARNING: "accum.c", line 617: Over 500 senones never occur in the input data. This is normal for context-dependent untied senone training or for adaptation, but could indicate a serious problem otherwise.INFO: s3mixw_io.c(232): Wrote ./mixw_counts [5210x3x256 array]INFO: s3tmat_io.c(174): Wrote ./tmat_counts [70x3x4 array]INFO: s3gau_io.c(478): Wrote ./gauden_counts with means with vars [1x3x256 vector arrays]INFO: main.c(1014): Counts saved to .最终结果,生成了三个数组文件到当前目录,后面用于生成适应声学模型。通过MAP更新声学模型&重新创建适应的sendump文件注意这里要先拷贝一份adap文件夹,然后才能生成适应声学模型的文件。#./map_adapt -meanfn tdt_sc_8k/means -varfn tdt_sc_8k/variances -mixwfn tdt_sc_8k/mixture_weights -tmatfn tdt_sc_8k/transition_matrices -accumdir . -mapmeanfn tdt_sc_8kadapt/means -mapvarfn tdt_sc_8kadapt/variances -mapmixwfn tdt_sc_8kadapt/mixture_weights -maptmatfn tdt_sc_8kadapt/transition_matrices输入文件:INFO: s3gau_io.c(166): Read tdt_sc_8k/means [1x3x256 array]INFO: s3gau_io.c(166): Read tdt_sc_8k/variances [1x3x256 array]INFO: s3mixw_io.c(116): Read tdt_sc_8k/mixture_weights [5210x3x256 array]INFO: s3tmat_io.c(115): Read tdt_sc_8k/transition_matrices [70x3x4 array]INFO: main.c(425): Reading and accumulating observation counts from .INFO: s3gau_io.c(379): Read ./gauden_counts with means with vars [1x3x256 vector arrays]INFO: s3mixw_io.c(116): Read ./mixw_counts [5210x3x256 array]INFO: s3tmat_io.c(115): Read ./tmat_counts [70x3x4 array]INFO: main.c(77): Estimating tau hyperparameter from variances and observationsINFO: main.c(139): Re-estimating mixture weights using MAPINFO: main.c(194): Re-estimating transition probabilities using MAPINFO: main.c(496): Re-estimating means using Bayesian interpolationINFO: main.c(500): Interpolating tau hyperparameter for semi-continuous modelsINFO: main.c(502): Re-estimating variances using MAP
输出文件
INFO: s3gau_io.c(226): Wrote tdt_sc_8kadapt/means [1x3x256 array]
INFO: s3gau_io.c(226): Wrote tdt_sc_8kadapt/variances [1x3x256 array]
INFO: s3mixw_io.c(232): Wrote tdt_sc_8kadapt/mixture_weights [5210x3x256 array]
INFO: s3tmat_io.c(174): Wrote tdt_sc_8kadapt/transition_matrices [70x3x4 array]
然后再创建适应声学模型的sendump文件
#./mk_s2sendump -pocketsphinx yes -moddeffn tdt_sc_8kadapt/mdef.txt -mixwfn tdt_sc_8kadapt/mixture_weights -sendumpfn tdt_sc_8kadapt/sendump
INFO: senone.c(210): Reading senone mixture weights: tdt_sc_8kadapt/mixture_weights
INFO: senone.c(330): Read mixture weights for 5210 senones: 3 features x 256 codewords
INFO: mk_s2sendump.c(207): Writing PocketSphinx format sendump file: tdt_sc_8kadapt/sendump

至此,适应后的声学模型已经生成。

INFO: ngram_model_arpa.c(77): No \data\ mark in LM file
INFO: ngram_model_dmp.c(142): Will use memory-mapped I/O for LM file
INFO: ngram_model_dmp.c(196): ngrams 1=12, 2=10, 3=10
INFO: ngram_model_dmp.c(242):       12 = LM.unigrams(+trailer) read
INFO: ngram_model_dmp.c(288):       10 = LM.bigrams(+trailer) read
INFO: ngram_model_dmp.c(314):       10 = LM.trigrams read
INFO: ngram_model_dmp.c(339):        2 = LM.prob2 entries read
INFO: ngram_model_dmp.c(359):        3 = LM.bo_wt2 entries read
INFO: ngram_model_dmp.c(379):        2 = LM.prob3 entries read
INFO: ngram_model_dmp.c(407):        1 = LM.tseg_base entries read
INFO: ngram_model_dmp.c(463):       12 = ascii word strings read
ERROR: "ngram_search.c", line 221: Language model/set does not contain </s>, recognition will fail
可能是transcription(影响观察数据统计及后面的内容或fileids(影响声学特征提取及后续内容)文件中,有空行\n出现导致。
还需要更新lm.dmp文件。

 遇到的错误:1. 提示arpa文件无<s>:
ERROR: "ngram_search.c", line 221: Language model/set does not contain </s>, recognition will fail
原因:竟然是语料文件txt写的有问题。每一个语料前后,没有使用<s> </s>括起来。解决办法:括起来。
2. "ngram_search.c", line 221: Language model/set does not contain </s>, recognition will fail 原因:txt文件中<s>和正式的文本之间 没有预留空格。</s>之前无空格会存在相同的报错。



0 0
原创粉丝点击