当前位置: 代码迷 >> Android >> Android本土语音识别引擎PocketSphinx-语言建模
  详细解决方案

Android本土语音识别引擎PocketSphinx-语言建模

热度:36   发布时间:2016-05-01 19:55:30.0
Android本地语音识别引擎PocketSphinx-语言建模
text2wfreq < weather.txt | wfreq2vocab > weather.tmp.vocab
?

最近研究Android上的语音识别,在此记录下遇到的问题。

先引用一篇博文,http://leiwuluan.iteye.com/blog/1287305。根据这篇博文的内容,要是没遇到问题的话,应该可以生成一个apk,在手机上可以运行,能进行识别,但是效率很低,识别率也不咋地。现在我们需要自己来构建识别的库。

根据代码

c.setString("-dict",				"/sdcard/Android/data/edu/edu.cmu.pocketsphinx/lm/zh_CN/mandarin_notone.dic");		c.setString("-lm",				"/sdcard/Android/data/edu/edu.cmu.pocketsphinx/lm/zh_CN/gigatdt.5000.DMP");

?程序会引用到两个文件,第一个是字典文件,第二个是声音模型文件,程序先将输入的声音和声音模型文件对比,生成音节编码,再将音节编码在字典中查找,返回最后的字符结果。Sphinx是个很完善的引擎,除了开源之外,官方还提供了各种工具供开发者构建自己的声音对比模型,字典,记忆语言模型。本文参考http://cmusphinx.sourceforge.net/wiki/tutoriallm,用CMUCLMTK构建自己的语言模型。

1.首先,假设你已经根据本文开头的那篇博文成功编译了PocketSphinx并且成功在手机上运行。

2.下载CMUCLMTK,http://sourceforge.net/projects/cmusphinx/files/cmuclmtk/0.7/cmuclmtk-0.7.tar.gz/download

3.将下载的文件解压到Sphinx根目录,参见开篇引用博文。

4.命令行下进入到CMUCLMTK目录,我的为

/workspace/VoiceRecognition/cmuclmtk-0.7# 

我的电脑系统是linux,如果是windows需要用cgwin

5. ./configure

6.make install

7.cd src

8.make install

9.在4的目录下,新建weather.txt,输入

<s> generally cloudy today with scattered outbreaks of rain and drizzle persistent and heavy at times </s><s> some dry intervals also with hazy sunshine especially in eastern parts in the morning </s><s> highest temperatures nine to thirteen Celsius in a light or moderate mainly east south east breeze </s><s> cloudy damp and misty today with spells of rain and drizzle in most places much of this rain will be light and patchy but heavier rain may develop in the west later </s>

?10.命令行下输入,

text2wfreq < weather.txt | wfreq2vocab > weather.tmp.vocab

?这时报错,如下

text2wfreq: error while loading shared libraries: libcmuclmtk.so.0: cannot open shared object file: No such file or directory

?参考error while loading shared libraries解决。

11.输入

text2idngram -vocab weather.tmp.vocab -idngram weather.idngram < weather.txt
?

12.输入

idngram2lm -vocab_type 0 -idngram weather.idngram -vocab weather.tmp.vocab -arpa weather.arpa

?如果无误,在目录下会生成weather.tmp.DMP文件。

官网说在http://www.speech.cs.cmu.edu/tools/lmtool.html也可以在线提交txt文件,在服务器生成DMP文件,但是我在试的时候,发现访问不了,可能是太多人用了,CMU把这个服务给关了?

?

哈哈,在查资料的时候,又发现有这方面的博文,再引用一下,http://www.cnblogs.com/huanghuang/archive/2011/07/14/2106579.html,http://archive.cnblogs.com/a/2111834/,http://www.cnblogs.com/huanghuang/archive/2011/07/18/2109101.html,这三篇应该讲的很全面了。

1 楼 cs3230524 2012-04-17  
我怎么还是识别不了呢?服务器不能生成dmp文件。翻.墙访问
log:
INFO: cmd_ln.c(691): Parsing command line:


Current configuration:
[NAME] [DEFLT] [VALUE]
-agc none none
-agcthresh 2.0 2.000000e+00
-alpha 0.97 9.700000e-01
-ascale 20.0 2.000000e+01
-aw 1 1
-backtrace no no
-beam 1e-48 1.000000e-48
-bestpath yes yes
-bestpathlw 9.5 9.500000e+00
-bghist no no
-ceplen 13 13
-cmn current current
-cmninit 8.0 8.0
-compallsen no no
-debug 0
-dict
-dictcase no no
-dither no no
-doublebw no no
-ds 1 1
-fdict
-feat 1s_c_d_dd 1s_c_d_dd
-featparams
-fillprob 1e-8 1.000000e-08
-frate 100 100
-fsg
-fsgusealtpron yes yes
-fsgusefiller yes yes
-fwdflat yes yes
-fwdflatbeam 1e-64 1.000000e-64
-fwdflatefwid 4 4
-fwdflatlw 8.5 8.500000e+00
-fwdflatsfwin 25 25
-fwdflatwbeam 7e-29 7.000000e-29
-fwdtree yes yes
-hmm
-input_endian little little
-jsgf
-kdmaxbbi -1 -1
-kdmaxdepth 0 0
-kdtree
-latsize 5000 5000
-lda
-ldadim 0 0
-lextreedump 0 0
-lifter 0 0
-lm
-lmctl
-lmname default default
-logbase 1.0001 1.000100e+00
-logfn
-logspec no no
-lowerf 133.33334 1.333333e+02
-lpbeam 1e-40 1.000000e-40
-lponlybeam 7e-29 7.000000e-29
-lw 6.5 6.500000e+00
-maxhmmpf -1 -1
-maxnewoov 20 20
-maxwpf -1 -1
-mdef
-mean
-mfclogdir
-min_endfr 0 0
-mixw
-mixwfloor 0.0000001 1.000000e-07
-mllr
-mmap yes yes
-ncep 13 13
-nfft 512 512
-nfilt 40 40
-nwpen 1.0 1.000000e+00
-pbeam 1e-48 1.000000e-48
-pip 1.0 1.000000e+00
-pl_beam 1e-10 1.000000e-10
-pl_pbeam 1e-5 1.000000e-05
-pl_window 0 0
-rawlogdir
-remove_dc no no
-round_filters yes yes
-samprate 16000 1.600000e+04
-seed -1 -1
-sendump
-senlogdir
-senmgau
-silprob 0.005 5.000000e-03
-smoothspec no no
-svspec
-tmat
-tmatfloor 0.0001 1.000000e-04
-topn 4 4
-topn_beam 0 0
-toprule
-transform legacy legacy
-unit_area yes yes
-upperf 6855.4976 6.855498e+03
-usewdphones no no
-uw 1.0 1.000000e+00
-var
-varfloor 0.0001 1.000000e-04
-varnorm no no
-verbose no no
-warp_params
-warp_type inverse_linear inverse_linear
-wbeam 7e-29 7.000000e-29
-wip 0.65 6.500000e-01
-wlen 0.025625 2.562500e-02

INFO: cmd_ln.c(691): Parsing command line:
\
-nfilt 20 \
-lowerf 1 \
-upperf 4000 \
-wlen 0.025 \
-transform dct \
-round_filters no \
-remove_dc yes \
-feat 1s_c_d_dd \
-svspec 0-12/13-25/26-38 \
-agc none \
-cmn current \
-cmninit 54,-1,2 \
-varnorm no

Current configuration:
[NAME] [DEFLT] [VALUE]
-agc none none
-agcthresh 2.0 2.000000e+00
-alpha 0.97 9.700000e-01
-ceplen 13 13
-cmn current current
-cmninit 8.0 54,-1,2
-dither no no
-doublebw no no
-feat 1s_c_d_dd 1s_c_d_dd
-frate 100 100
-input_endian little little
-lda
-ldadim 0 0
-lifter 0 0
-logspec no no
-lowerf 133.33334 1.000000e+00
-ncep 13 13
-nfft 512 512
-nfilt 40 20
-remove_dc no yes
-round_filters yes no
-samprate 16000 8.000000e+03
-seed -1 -1
-smoothspec no no
-svspec 0-12/13-25/26-38
-transform legacy dct
-unit_area yes yes
-upperf 6855.4976 4.000000e+03
-varnorm no no
-verbose no no
-warp_params
-warp_type inverse_linear inverse_linear
-wlen 0.025625 2.500000e-02

INFO: acmod.c(242): Parsed model-specific feature parameters from /sdcard/Android/data/test/hmm/tdt_sc_8k/feat.params
INFO: feat.c(684): Initializing feature stream to type: '1s_c_d_dd', ceplen=13, CMN='current', VARNORM='no', AGC='none'
INFO: cmn.c(142): mean[0]= 12.00, mean[1..12]= 0.0
INFO: acmod.c(163): Using subvector specification 0-12/13-25/26-38
INFO: mdef.c(520): Reading model definition: /sdcard/Android/data/test/hmm/tdt_sc_8k/mdef
INFO: mdef.c(531): Found byte-order mark BMDF, assuming this is a binary mdef file
INFO: bin_mdef.c(330): Reading binary model definition: /sdcard/Android/data/test/hmm/tdt_sc_8k/mdef
INFO: bin_mdef.c(507): 70 CI-phone, 65021 CD-phone, 3 emitstate/phone, 210 CI-sen, 5210 Sen, 11271 Sen-Seq
INFO: tmat.c(205): Reading HMM transition probability matrices: /sdcard/Android/data/test/hmm/tdt_sc_8k/transition_matrices
INFO: acmod.c(117): Attempting to use SCHMM computation module
INFO: ms_gauden.c(198): Reading mixture gaussian parameter: /sdcard/Android/data/test/hmm/tdt_sc_8k/means
INFO: ms_gauden.c(292): 1 codebook, 3 feature, size:
INFO: ms_gauden.c(294):  256x13
INFO: ms_gauden.c(294):  256x13
INFO: ms_gauden.c(294):  256x13
INFO: ms_gauden.c(198): Reading mixture gaussian parameter: /sdcard/Android/data/test/hmm/tdt_sc_8k/variances
INFO: ms_gauden.c(292): 1 codebook, 3 feature, size:
INFO: ms_gauden.c(294):  256x13
INFO: ms_gauden.c(294):  256x13
INFO: ms_gauden.c(294):  256x13
INFO: ms_gauden.c(354): 0 variance values floored
INFO: s2_semi_mgau.c(908): Loading senones from dump file /sdcard/Android/data/test/hmm/tdt_sc_8k/sendump
INFO: s2_semi_mgau.c(932): BEGIN FILE FORMAT DESCRIPTION
INFO: s2_semi_mgau.c(1027): Using memory-mapped I/O for senones
INFO: s2_semi_mgau.c(1304): Maximum top-N: 4 Top-N beams: 0 0 0
INFO: phone_loop_search.c(105): State beam -230231 Phone exit beam -115115 Insertion penalty 0
INFO: dict.c(306): Allocating 4107 * 20 bytes (80 KiB) for word entries
INFO: dict.c(321): Reading main dictionary: /sdcard/Android/data/test/lm/test.dic
ERROR: "dict.c", line 194: Line 1: Phone 'EH' is mising in the acoustic model; word '<S>不好</S>' ignored
ERROR: "dict.c", line 194: Line 2: Phone 'EH' is mising in the acoustic model; word '<S>好</S>' ignored
ERROR: "dict.c", line 194: Line 3: Phone 'EH' is mising in the acoustic model; word '<S>小赖</S>' ignored
ERROR: "dict.c", line 194: Line 4: Phone 'EH' is mising in the acoustic model; word '<S>祝东芝</S>' ignored
INFO: dict.c(212): Allocated 0 KiB for strings, 0 KiB for phones
INFO: dict.c(324): 0 words read
INFO: dict.c(330): Reading filler dictionary: /sdcard/Android/data/test/hmm/tdt_sc_8k/noisedict
INFO: dict.c(212): Allocated 0 KiB for strings, 0 KiB for phones
INFO: dict.c(333): 7 words read
INFO: dict2pid.c(396): Building PID tables for dictionary
INFO: dict2pid.c(404): Allocating 70^3 * 2 bytes (669 KiB) for word-initial triphones
INFO: dict2pid.c(131): Allocated 59080 bytes (57 KiB) for word-final triphones
INFO: dict2pid.c(195): Allocated 59080 bytes (57 KiB) for single-phone word triphones
INFO: ngram_model_arpa.c(477): ngrams 1=6, 2=8, 3=4
INFO: ngram_model_arpa.c(135): Reading unigrams
INFO: ngram_model_arpa.c(516):        6 = #unigrams created
INFO: ngram_model_arpa.c(195): Reading bigrams
INFO: ngram_model_arpa.c(533):        8 = #bigrams created
INFO: ngram_model_arpa.c(534):        3 = #prob2 entries
INFO: ngram_model_arpa.c(542):        3 = #bo_wt2 entries
INFO: ngram_model_arpa.c(292): Reading trigrams
INFO: ngram_model_arpa.c(555):        4 = #trigrams created
INFO: ngram_model_arpa.c(556):        2 = #prob3 entries
INFO: ngram_search_fwdtree.c(99): 0 unique initial diphones
INFO: ngram_search_fwdtree.c(147): 0 root, 0 non-root channels, 8 single-phone words
INFO: ngram_search_fwdtree.c(186): Creating search tree
INFO: ngram_search_fwdtree.c(191): before: 0 root, 0 non-root channels, 8 single-phone words
INFO: ngram_search_fwdtree.c(326): after: max nonroot chan increased to 128
ERROR: "ngram_search_fwdtree.c", line 336: No word from the language model has pronunciation in the dictionary
INFO: ngram_search_fwdtree.c(338): after: 0 root, 0 non-root channels, 7 single-phone words
INFO: ngram_search_fwdflat.c(156): fwdflat: min_ef_width = 4, max_sf_win = 25
INFO: pocketsphinx.c(299): zslog use ngs
2 楼 wushaoliu3000 2012-05-21  
我更惨了,我连apk文件都不能运行,请博主多指点
  相关解决方案