I have been following the Jasper project for a while now. I installed it a couple months ago on my raspberry pi, and got some rudimentary features working. Now that Pi is in full service running a home automation system and I have received my next single board computer, the Beaglebone black . Having nothing better to do with it, I decided to see how far Jasper has come and try to get it running on the black. below are my efforts.
Here is my setup;
A Beaglebone black rev C running the 2014-05-14 SD card Debian image. My sound card is a Logitech usb headset, but any USB soundcard should work. I will eventually be getting this one and will report back once it arrives.
I started with the default SD card Debian image for the BBB available here. Although you shouldn’t have any problem installing it directly on rev C boards with 4 gb of emmc. – This has not been tested.
As for accessing the BBB command line, I will be using an ssh session as root through putty. The cloud 9 ide should work, but is not tested at this point.
Much of the documentation in this page is ripped straight from here and has has small changes that enable it to run on the BBB. (To a point, not everything is working yet)
Here goes nothing.
Boot up your BBB and ssh into it.
Run the following commands to update BBB
sudo apt-get update sudo apt-get upgrade -y cd /opt/scripts/tools/ git pull sudo ./update_kernel.sh sudo reboot
You will eventually have to reboot for the update to complete. If anything fails, such as you getting an “out of space” message, you may need to pop the sd card into a Ubuntu machine and expand the filesystem with gparted.
Install some useful tools.
sudo apt-get install vim git-core espeak python-dev python-pip bison libasound2-dev libportaudio-dev python-pyaudio --yes
This is where some things differ between the Rpi and BBB. The Rpi has an audio out port, the BBB does not. (The HDMI does, but I doubt that you’ll be using that) That means that we have to disable the hdmi and make our usb card the default device (card 0)
To disable the hdmi sound card, plug the BBB into your computer with a usb cable. It should show up as a regular flash drive. Find the file called;
Open up the file in your favorite text editor (I use Notepad++) and find the section saying
##Disable HDMI #cape_disable=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN
Remove the # from the start of the second line. The section should now look like
##Disable HDMI cape_disable=capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN
That’s it! Save the file and reboot the BBB.
Once your BBB reboots, plug in your USB sound card and run this command;
You should get a response something like
**** List of PLAYBACK Hardware Devices **** card 1: Headset [Logitech USB Headset], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
We need to allow the USB sound card to become card 0.
(configuring the sound card probably does not need to be done as we will need to switch out the hw variable in the aplay commands jasper uses shortly anyways. I am just documenting what I have done in my efforts so far.)
Let’s open up an ALSA configuration file in vim:
sudo vim /etc/modprobe.d/alsa-base.conf
Comment out the following line:
options snd-usb-audio index=-2
It should now look like this:
#options snd-usb-audio index=-2
The raspi commands are slightly different from this, instead of commenting out the like, they changed -2 to 0. When I tried this and reloaded alsa (next step) my sound card dissapeared from the # aplay -l command, but could be verified that it was still connected via # lsusb.
Back in the shell, run:
sudo alsa force-reload aplay -l
You should now see something like
root@beaglebone:~/jasper# sudo alsa force-reload Unloading ALSA sound driver modules: snd-usb-audio snd-hwdep snd-usbmidi-lib. Loading ALSA sound driver modules: snd-usb-audio snd-hwdep snd-usbmidi-lib. root@beaglebone:~/jasper# aplay -l **** List of PLAYBACK Hardware Devices **** card 0: Headset [Logitech USB Headset], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
Next, test that recording works (you may need to restart your BBB) by recording some audio with the following command:
Make sure you have speakers or headphones connected to the audio jack of your BBB. You can play back the recorded file:
This is slightly different then the command in the raspi setup docs, which is
aplay -D hw:1,0 temp.wav
This will cause a problem later as the sound-card HW id’s are hardcoded into Jasper (Developers- please put mic and speaker id’s into a config file!!) We will have to go into the jasper scripts and switch the id’s out manually later.
If all of the steps above succeed, continue on.
Add the following line to the end of ~/.bash_profile (you may need to run
touch ~/.bash_profile if the file doesn’t exist already):
export LD_LIBRARY_PATH="/usr/local/lib" source .bashrc
And this to your ~/.bashrc or ~/.bash_profile:
LD_LIBRARY_PATH="/usr/local/lib" export LD_LIBRARY_PATH PATH=$PATH:/usr/local/lib/ export PATH
With that, we’re ready to install the core software that powers Jasper.
We will be installing jasper in the home folder. Putting it in a folder has not been successfully tested.
Jasper uses Pocketsphinx for voice recognition. Let’s download and unzip the sphinxbase and pocketsphinx packages:
wget http://downloads.sourceforge.net/project/cmusphinx/sphinxbase/0.8/sphinxbase-0.8.tar.gz wget http://downloads.sourceforge.net/project/cmusphinx/pocketsphinx/0.8/pocketsphinx-0.8.tar.gz tar -zxvf sphinxbase-0.8.tar.gz tar -zxvf pocketsphinx-0.8.tar.gz
Now we build and install sphinxbase:
cd ~/sphinxbase-0.8/ ./configure --enable-fixed make sudo make install
cd ~/pocketsphinx-0.8/ ./configure make sudo make install
Once the installations are complete, restart your BBB.
Note that some of these installation steps take more time to complete than previous steps.
Begin by installing some dependencies:
sudo apt-get install subversion autoconf libtool automake gfortran g++ --yes
Next, move into your home (or Jasper) directory to check out and install CMUCLMTK:
svn co https://svn.code.sf.net/p/cmusphinx/code/trunk/cmuclmtk/ cd cmuclmtk/ sudo ./autogen.sh && sudo make && sudo make install cd ..
Then, when you’ve left the CMUCLTK directory, download the following libraries:
wget http://distfiles.macports.org/openfst/openfst-1.3.3.tar.gz wget https://mitlm.googlecode.com/files/mitlm-0.4.1.tar.gz wget https://phonetisaurus.googlecode.com/files/phonetisaurus-0.7.8.tgz wget http://phonetisaurus.googlecode.com/files/g014b2b.tgz
Untar the downloads:
tar -xvf openfst-1.3.3.tar.gz tar -xvf phonetisaurus-0.7.8.tgz tar -xvf mitlm-0.4.1.tar.gz tar -xvf g014b2b.tgz
Build OpenFST: !!! Do not attempt this step, It will take a really long time and fail !!!
cd openfst-1.3.3/ sudo ./configure --enable-compact-fsts --enable-const-fsts --enable-far --enable-lookahead-fsts --enable-pdt sudo make install # come back after a really long time
Create and mount a swap file
These commands will be added later - once jasper gets to the point where it is processing audio on the BBB. if you run into this tutorial before it is updated, just follow the swap file guide linked above.
After these compiles are done, the swap-file is no longer needed. It can be removed after everything is built. Otherwise it may wear down your flash storage.
I’m not sure if this next part is actually needed, as the swap file was the last problem I solved before openfst compiled, (if someone could confirm this that would be great, otherwise once everything is working I’ll install jasper following all instructions in this guide.) but I’m documenting everything anyway with the hope that this will be extremely easy to turn into a guide for jasper on the BBB.
Change the gcc compiler
sudo apt-get install gcc-4.4 g++-4.4 cpp-4.4 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20 sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 sudo update-alternatives --set cc /usr/bin/gcc sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 sudo update-alternatives --set c++ /usr/bin/g++
Now that we have the right compiler and enough memory, go ahead and install openfst. I am using screen here as well as I don’t want an accidental ssh closure to stop my build. It will take a couple of hours.
cd openfst-1.3.3/ cpufreq-set -g performance # Increase cpu frequency to 1000mhz for faster compiling. Usually set at 300 - 600mhz screen sudo ./configure --enable-compact-fsts --enable-const-fsts --enable-far --enable-lookahead-fsts --enable-pdt sudo make install # come back after a really long time
OpenFST should compile correctly after this. If you have to leave, disconnect from the screen session using:
CTRL + A D
And reconnect once you log in again using
Once the compile is finished, move onto the next steps.
cd ~ nano /etc/apt/sources.list
deb http://ftp.debian.org/debian experimental main contrib non-free
to the bottom of the file.
CTRL + X , then
enter to save and close. we have now added experimental packages to our sources.
install the experimental package
apt-get update apt-get -t experimental install m2m-aligner
cd .. cd mitlm-0.4.1/ sudo ./configure sudo make install
cd .. cd phonetisaurus-0.7.8/ cd src sudo make
Move some of the compiled files:
sudo cp ~/jasper/phonetisaurus-0.7.8/phonetisaurus-g2p /usr/local/bin/phonetisaurus-g2p
Build Phonetisaurus model: (If you get dictionary errors, reboot the black and rebuild this)
cd g014b2b/ ./compile-fst.sh
Finally, rename the following folder for convenience:
mv ~/g014b2b ~/phonetisaurus
At this point, we’ve installed Jasper and all the necessary software to run it. Before we start playing around, though, we need to configure Jasper and provide it with some basic information.
You can follow the normal jasper instructions from here. things are somewhat working (jasper starts) but there seems to be some bitrate and soundcard issues still.