语音识别——安装CMUCLMTK(生成自己的语言模型)

本文详细介绍了在Ubuntu18.04环境下,安装并使用CUM_Sphinx训练语言模型的过程,包括解决安装过程中遇到的共享库加载错误,以及如何生成自定义的二进制语言模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意:
CUM_Sphinx的安装及使用看这篇帖子:https://blog.youkuaiyun.com/qq_29894613/article/details/92704392

本人的Linux系统为64位,Ubuntu18.04。
本人经理了好多坑才可以训练成最终的语言模型,在此记录下来供后来的人学习。
安装过程整理自以下帖子:

  1. Sphinx武林秘籍(中)――训练自已的中文语言模型与声学模型
    https://www.cnblogs.com/huanghuang/archive/2011/07/18/2109101.html
  2. Android本地语音识别引擎PocketSphinx-语言建模
    https://zuoshu.iteye.com/blog/1413798
  3. Linux中error while loading shared libraries错误解决办法
    https://www.cnblogs.com/codingmengmeng/p/7456539.html

下载CMUCLMTK安装包

官方下载地址:https://sourceforge.net/projects/cmusphinx/files/cmuclmtk/
点击0.7版本,进入下载cmuclmtk-0.7.tar.gz安装包
在这里插入图片描述
在这里插入图片描述

开始安装

解压安装包,然后进入解压后的文件夹
在这里插入图片描述

cd cmuclmtk-0.7
./configure
sudo make
sudo make install

默认安装在/usr/local/bin下面,可以看到下面这些生成文件。如果没有看到全部的文件,说明安装不成功,重新安装(不好意思,我没遇到,不知道失败后怎么安装)。
idngram2lm idngram2stats mergeidngram text2idngram
text2wfreq text2wngram wfreq2vocab

生成自己的语言模型

1. 准备文档
文档类型为txt文档,纯单词,不包含标点。
注意: 文档中的每句话必须用符号<s> </s>引起来。
取自官方的一个例子:https://cmusphinx.github.io/wiki/tutoriallm/#training-an-arpa-model-with-cmuclmtk

<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>

2. 制作声学模型,按照步骤走就行
上面保存的txt文件名为:weather.txt

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  

解决方法:https://www.cnblogs.com/codingmengmeng/p/7456539.html
默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件,通常通过源码包进行安装时,如果不指定–prefix,会将库安装在/usr/local/lib目录下;当运行程序需要链接动态库时,提示找不到相关的.so库,会报错。也就是说,/usr/local/lib目录不在系统默认的库搜索目录中,需要将目录加进去。

1、首先打开/etc/ld.so.conf文件

2、加入动态库文件所在的目录:执行sudo vim /etc/ld.so.conf,在"include ld.so.conf.d/*.conf"下方增加"/usr/local/lib"。

3、保存后,在命令行终端执行:/sbin/ldconfig -v;其作用是将文件/etc/ld.so.conf列出的路径下的库文件缓存到/etc/ld.so.cache以供使用,因此当安装完一些库文件,或者修改/etc/ld.so.conf增加了库的新搜索路径,需要运行一下ldconfig,使所有的库文件都被缓存到文件/etc/ld.so.cache中,如果没做,可能会找不到刚安装的库。

经过以上三个步骤,"error while loading shared libraries"的问题通常情况下就可以解决了。

如果运行应用程序时,还是提示以上错误,那就得确认一下是不是当前用户在库目录下是不是没有可读的权限。像我遇到的问题就是,从别的机子拷贝了一些.so动态库,然后用root权限放到了/usr/local/lib中(普通用户没有对该目录的写权限),然后切换用户运行程序时,始终提示找不到.so库,一直以为是我配置有问题,结果是因为权限原因,那些我用root权限增加到/usr/local/lib中的.so文件对于普通用户而言,是没有访问权限的,所以以普通用户运行程序,当需要链接.so库时,在/usr/local/lib中是查找不到的。

其实,对于由普通用户自己编译生成的.so库文件,比较好的做法是将这些.so库文件的路径用export指令加入到/.bash_profile中的LD_LIBRARY_PATH变量中,LD_LIBRARY_PATH是程序运行需要链接.so库时会去查找的一个目录,/.bash_profile是登陆或打开shell时会读取的文件,这样,每次用户登录时,都会把这些.so库文件的路径写入LD_LIBRARY_PATH,这样就可以正常地使用这些.so库文件了。

解决问题后接着输入以下命令:

# Generate the vocabulary file. This is a list of all the words in the file:
text2wfreq < weather.txt | wfreq2vocab > weather.tmp.vocab
# Generate the ARPA format language model with the commands:
text2idngram -vocab weather.tmp.vocab -idngram weather.idngram < weather.txt
idngram2lm -vocab_type 0 -idngram weather.idngram -vocab weather.tmp.vocab -arpa weather.lm
# Generate the CMU binary form (BIN):
sphinx_lm_convert -i weather.lm -o weather.lm.bin
  1. 大功告成,不出意外的话,在文件夹下面可以看到生成的语言模型。( 二进制类型)
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值