pocketsphinx 安装

  1. 下载
# sphinxbase-5prealpha.tar.gz、pocketsphinx-5prealpha.tar.gz、sphinxtrain-5prealpha.tar.gz
https://sourceforge.net/projects/cmusphinx/files/
# 模型文件
https://sourceforge.net/projects/cmusphinx/files
Acoustic and Language Models下Mandarin文件夹为中文普通话
解压后如下:
zh_cn.cd_cont_5000 文件夹下为声学模型的相关文件
zh_cn.dic  字典文件
zh_cn.lm.bin  语言模型
  1. 编译
  • 编译 sphinxbase
tar zxvf sphinxbase-5prealpha.tar.gz
mv sphinxbase-5prealpha sphinxbase
cd sphinxbase
./configure
make
sudo make install

./configure的时候提示缺少bison:

configure: error: You need to install bison
使用sudo apt install bison进行安装

提示缺少python-dev:

configure: error: 
  Could not link test program to Python. Maybe the main Python library has been
  installed in some non-standard library path. If so, pass it to configure,
  via the LDFLAGS environment variable.
  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
  ============================================================================
   ERROR!
   You probably have to install the development version of the Python package
   for your distribution.  The exact name of this package varies among them.
  ============================================================================

使用sudo apt install python-dev进行安装

提示缺少swig

configure: error: swig not found
使用sudo apt install swig进行安装
  • 编译 pocketsphinx
tar zxvf pocketsphinx-5prealpha.tar.gz
mv pocketsphinx-5prealpha pocketsphinx
cd pocketsphinx
./configure
make
sudo make install
  • 编译sphinxtrain
tar -zxvf sphinxtrain-5prealpha.tar.gz
mv sphinxtrain-5prealpha sphinxtrain
cd sphinxtrain
./configure
make
  1. 运行
pocketsphinx_continuous
报错如下:
pocketsphinx_continuous: error while loading shared libraries: libpocketsphinx.so.3: cannot open shared object file: No such file or directory

这是因为pocketsphinx生成动态库路径不在我的默认路径内,通过如下方法解决:

sudo vi /etc/ld.so.conf
# 在文件中追加下面两行
# /usr/local/lib
# /usr/local/lib/pkgconfig
sudo ldconfig
  1. 识别
  • 实时识别
    使用-inmic,进行实时语音识别
pocketsphinx_continuous -hmm zh_cn.cd_cont_5000/ -lm zh_cn.lm.bin -dict zh_cn.dic -inmic yes
-hmm选项指定声学模型文件夹 
-lm选项指定语言模型 
-dict选项指定字典文件
报错如下:
......
ad_oss.c(115): Failed to open audio device(/dev/dsp): No such file or directory
FATAL: "continuous.c", line 245: Failed to open audio device

说sphinx没有找到audio device, 说在安装sphinxbase时,配置脚本会检测音频环境,然后会编译进sphinxbase,所以在配置之前我们需要先安装libpulse audio device。

sudo apt install libpulse-dev
然后重复安装sphinxbase和pocketsphinx的步骤。

再次尝试,不进行报错,但识别效果很一般。

  • 识别文件
pocketsphinx_continuous -lm zh_cn.lm.bin -dict zh_cn.dic -infile /home/lhy/Downloads/qingcheng.wav > /home/lhy/Downloads/qingcheng.txt

未找到合适的音频文件,报错了

ERROR: "continuous.c", line 131: Input audio file has [2] channels, expected single channel mono
FATAL: "continuous.c", line 165: Failed to process file '/home/lhy/Downloads/qingcheng.wav' due to format mismatch.

参考https://blog.csdn.net/xj853663557/article/details/84583973
参考https://www.jianshu.com/p/96c114eb4417

你可能感兴趣的:(pocketsphinx 安装)