The purpose of this posting is to describe my method for integrating
pocketsphinx and asterisk together.
Dial an extension on your phone and issue voice commands to misterhouse.
Note, this HOWTO is not for the faint of heart ...
- Linux only (I think)
You need to be comfortable with
- Asterisk, extensions, AGI interface
- Pulseaudio, null-sinks, default.pa
- Alsa, .asoundrc configuration
- Misterhouse (of course)
* PULSEAUDIO configuration
We need to use a running pulseaudio server such that we can connect the
asterisk application with the pocketsphinx application. Both asterisk
and pocketsphinx are designed to interface directly with the hardware
layer and not designed to interface with another application.
The pulseaudio server provides a "null_sink" module, which allows an
interim software mechanism to allow the asterisk and pocketsphinx to
interchange audio. I tried once to get JACK to perform this feat, but I
was unsuccessful. Pulseaudio works fine.
I suggest you get a little comfortable with the pulseaudio server first.
Step 1: Setup default.pa
You need these 3 lines in your /etc/pulse/default.pa file on the machine
which hosts the misterhouse application:
load-module module-null-sink sink_name=sphinx_record description="Sphinx
load-module module-null-sink sink_name=sphinx_playback
description="Sphinx Playback Source"
load-module module-combine sink_name=combined master=<your main audio
The sphinx_record null sink is used to receive the inbound audio from
asterisk, which pocketsphinx will listen to.
The sphinx_playback null sink is used by misterhouse to speak back to,
which becomes the audio playback to asterisk.
The combined sink is required such that the misterhouse audio will go to
both the local speakers and asterisk.
Your audio setup may vary. You might need to change specifics for your
You need to setup the .asoundrc for the user which runs the misterhouse
.asoundrc for misterhouse user:
device <your microphone hardware>;
device <your microphone hardware>;
source <your microphone hardware>;
You need to setup the .asoundrc for the user which runs the asterisk
application. You need to change the "server" to the machine which runs
the misterhouse application. In my case, that machine name is "linux".
If misterhouse and asterisk run on the same host, then you can remove
the server line.
.asoundrc for asterisk user
* Pocketsphinx configuration
You need to install pocketsphinx, see the instructions in
mh/lib/PocketSphinx.pm and/or code/common/pocketsphinx_listener.pl
Enable the pocketsphinx_listener.pl code file. You should get
pocketsphinx working with a microphone before attempting to integrate
* Asterisk configuration
You need the following two lines in /etc/asterisk/alsa.conf
You need these lines in your /etc/asterisk/extensions.conf
exten => s,1,AGI(MisterHouse.agi,"Sphinx Connect")
exten => s,n,Dial(CONSOLE/1)
exten => h,1,AGI(MisterHouse.agi,"Sphinx Disconnect")
exten => h,n,Hangup
; - Console Attachment
exten => 503,1,Goto(sphinx,s,1)
In my case, dialing extension 503 in the local context will result in a
connection between the phone and the pocketsphinx application running on
the misterhouse server. You need to tailor for what you want.
You need some code in your /var/lib/asterisk/agi-bin/Misterhouse.agi file:
I have attached a copy of my version for reference.
The Misterhouse.agi code is needed such that the "Sphinx Connect" and
"Sphinx Disconnect" commands are passed to misterhouse when a user dials
the extensions or hangs up the phone. This triggers the start/stop of a
* Misterhouse configuration
You're going to need some code module, example, asterisk.pl, which
allows communication between Asterisk and MH. I'm assuming you've
already done something similar, since you have asterisk. When asterisk
detects the Sphinx extension was dialed, it sends a command to MH which
instructs MH to start a new pocketsphinx listener thread.
I have attached my version, as reference.
A user dials some extension (example 503) on Asterisk.
Asterisk connects the call to the alsa console interface.
Asterisk sends a command to MH through the AGI interface to inform MH
that a user has dialed the Sphinx connection.
MH receives the AGI command and starts a new pocketsphinx listener thread.
The asterisk console and pocketsphinx applications are glued together by
virtue of the pulseaudio server through the sphinx_record and
sphinx_playback null_sink modules, in conjunction with information in
the .asoundrc files for both the asterisk user and MH user.
MH speaks "voice activation is now available and ready" through the
asterisk alsa console to the user on the phone. The user speaks MH
voice commands into the headset, which get forwarded to the pocketshinx
application which is now listening. MH responds to voice commands.
The user hangs up. Asterisk informs MH of the hangup. MH stops the
pocketsphinx listener application.
Not the greatest HOW TO, but I hope you get the idea.