Last Updated: July 30, 2017
· bossjones

How to Setup Speech Recognition using a #RaspberryPi + #Pocketsphinx + #ps3eye

Took me a while, with with some help from a couple sources ( they will be listed in my answer ) and some helpful hints from nikolay-shmyrev, I finally came up with an answer that worked for me.

Key assumptions:

  1. running these commands as the pi user ( previously I was running them as root, which was incorrect )

  2. I'm using continuous recognition and I was ONLY looking for the ability to "wake-up" my raspberry pi. Upon waking it up, I have other plans on how it should interact.

My setup:

  1. Canakit RaspberryPi

  2. HDMI cable to my Toshiba TV

  3. usb wifi dongle

  4. Playstation 3 Eye for speech recognition

Moving forward. I ran the following commands on my RaspberryPi to get PulseAudio + pocketsphinx working together w/ my Playstation 3 Eye. ( If you see any places for improvement please let me know )

Install pulse audio / development packages

<!-- language-all: sh -->

sudo apt-get install gstreamer0.10-pulseaudio libao4 libasound2-plugins libgconfmm-2.6-1c2 libglademm-2.4-1c2a libpulse-dev libpulse-mainloop-glib0 libpulse-mainloop-glib0-dbg libpulse0 libpulse0-dbg libsox-fmt-pulse paman paprefs pavucontrol pavumeter pulseaudio pulseaudio-dbg pulseaudio-esound-compat pulseaudio-esound-compat-dbg pulseaudio-module-bluetooth pulseaudio-module-gconf pulseaudio-module-jack pulseaudio-module-lirc pulseaudio-module-lirc-dbg pulseaudio-module-x11 pulseaudio-module-zeroconf pulseaudio-module-zeroconf-dbg pulseaudio-utils oss-compat -y

Setting up ALSA

Per instructions from http://forums.debian.net/viewtopic.php?f=16&t=12497

sudo \cp -pf /etc/asound.conf /etc/asound.conf.ORIG 
sudo echo 'pcm.pulse {
    type pulse

ctl.pulse {
    type pulse

pcm.!default {
    type pulse

ctl.!default {
    type pulse
}' > /etc/asound.conf

Make sure your camera device loads on boot

_DEVICE_LOAD_ON_START=$(grep "snd.bcm2835" /etc/modules | wc -l)
if [[ "${_DEVICE_LOAD_ON_START}" = "0" ]]; then

  sudo \cp -pf /etc/modules /etc/modules.ORIG
  sudo echo "snd-bcm2835" >> /etc/modules


# Disallow module loading after startup. This is a security feature since it disallows additional module loading during runtime and on user request.
_DISALLOW_MODULE_LOADING=$(grep "DISALLOW_MODULE_LOADING=1" /etc/default/pulseaudio | wc -l)
if [[ "${_DISALLOW_MODULE_LOADING}" = "0" ]]; then

  sudo \cp -pf /etc/default/pulseaudio /etc/default/pulseaudio.ORIG
  sudo sed -i "s,DISALLOW_MODULE_LOADING=1,DISALLOW_MODULE_LOADING=0,g" /etc/default/pulseaudio


Set up the PulseAudio daemon for network connections

# allow other clients on the network to connect to pulseaudio daemon ( only add auth-anonymous=1 if you know EVERY machine on your LAN ... this could be a security risk otherwise )
sudo \cp -fvp /etc/pulse/system.pa /etc/pulse/system.pa.ORIG
sudo echo "
# ScarlettPi ADDED THIS
load-module module-native-protocol-tcp auth-ip-acl=; auth-anonymous=1
load-module module-zeroconf-publish" >> /etc/pulse/system.pa

sudo echo "
# ScarlettPi added this
#load-module module-native-protocol-tcp
#load-module module-zeroconf-publish
load-module module-native-protocol-tcp auth-ip-acl=; auth-anonymous=1
load-module module-zeroconf-publish" >> /etc/pulse/default.pa

# check to make sure it looks okay
cat /etc/pulse/default.pa

Change default sound driver from alsa to pulseaudio

sudo \cp -fvp /etc/libao.conf /etc/libao.conf.ORIG
sudo sed -i "s,default_driver=alsa,default_driver=pulse,g" /etc/libao.conf 

# daemon settings according to Pi-Musicbox ( https://github.com/woutervanwijk/Pi-MusicBox )
sudo \cp -fvp /etc/pulse/daemon.conf /etc/pulse/daemon.conf.ORIG

sudo echo "
# ScarlettPi added this
high-priority = yes
nice-level = 5
exit-idle-time = -1
resample-method = src-sinc-medium-quality
default-sample-format = s16le
default-sample-rate = 48000
default-sample-channels = 2" >> /etc/pulse/daemon.conf.ORIG

Add pi user to the pulse access group

sudo adduser pi pulse-access

# shut down the machine to make sure all the settings we just made are loaded correctly
sudo shutdown -r now

Make sure to add /usr/local/lib to library path

export LD_LIBRARY_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

# also add these to your .bashrc so they get set once you login 
echo "
# scarlettPi added this
export LD_LIBRARY_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig" >> ~/.bashrc

Install base PocketSphinx

# install python dev packages
sudo apt-get install python2.7-dev -y

# sphinxbase install ( required to install pocketsphinx )
sudo apt-get install bison -y
cd ~pi/
wget  http://downloads.sourceforge.net/project/cmusphinx/sphinxbase/0.8/sphinxbase-0.8.tar.gz
tar -xvf sphinxbase-0.8.tar.gz
cd sphinxbase-0.8
sudo make install
cd -

# pocketsphinx install
# set this: LD_LIBRARY_PATH=/path/to/pocketsphinxlibs /usr/local/bin/pocketsphinx_continuous
# http://www.voxforge.org/home/forums/message-boards/speech-recognition-engines/howto-use-pocketsphinx
wget http://sourceforge.net/projects/cmusphinx/files/pocketsphinx/0.8/pocketsphinx-0.8.tar.gz
tar -xvf pocketsphinx-0.8.tar.gz
cd pocketsphinx-0.8
sudo make install
cd -

# install sphinxtrain
wget http://sourceforge.net/projects/cmusphinx/files/sphinxtrain/1.0.8/sphinxtrain-1.0.8.tar.gz
tar -xvf sphinxtrain-1.0.8
cd sphinxtrain-1.0.8
sudo make install
cd -

Check if pulse daemon is running

ps aux | grep pulse

# If it isn't, start it up yourself ( need to figure out the best way to make this run on boot...init.d script maybe? )
/usr/bin/pulseaudio --start --log-target=syslog --system=false

Finally, run Sphinx


Assumimg existing corpus file, .jsgf file, .dic, and .lm files (using lmtool)

cd ~pi/pocketsphinx-0.8
pocketsphinx_continuous -lm /home/pi/scarlettPi/config/speech/lm/scarlett.lm -dict /home/pi/scarlettPi/config/speech/dict/scarlett.dic -hmm /home/pi/scarlettPi/config/speech/model/hmm/en_US/hub4wsj_sc_8k -silprob  0.1 -wip 1e-4 -bestpath 0


I plan on adding more details behind why I used certain setting, configurations in a blog post i'm writing on my home automation project, but figured, i'd share what i've done thus far incase someone else was stuck like me and would like to move forward with what they're working on. Hope this helps someone. Thanks for the advice guys.

2 Responses
Add your response


Hi Michael,

I see you are setting the sampling rate at 48kHz(default-sample-rate = 48000). Do you know if you are able to record with that frequency?

I'm asking this because a few years back using ALSA I wasn't able to record with more than 16kHz using the Playstation Eye.

Thank you!

over 1 year ago ·

When I try the second command, I am given this error:

\cp -/etc/.conf/etc/asound.conf.ORIG

cp: cannot stat ‘/etc/asound.conf’: No such file or directory

Do you have any idea on how to fix this, or maybe if the file has been downloaded to the wrong place?

over 1 year ago ·
Filed Under