Using PocketSphinx to interpret your commands

Sound is cool, and speech is even cooler, but you also want to be able to communicate with your projects through voice commands. This section will show you how to add speech recognition to your robotic projects.

Prepare for lift off

Now that your project can speak, you want it to listen as well. This isn't nearly as simple as the speaking part, but thankfully you have some significant help from the development community. You are going to download a set of capabilities called PocketSphinx, which will allow your project to listen to your commands.

Engage thrusters

The first step is downloading the PocketSphinx capability. Unfortunately, this is not quite as user friendly as the eSpeak process, so follow along carefully.

Go to the Sphinx website, hosted by Carnegie Mellon University at http://cmusphinx.sourceforge.net/. This is an open source project that provides you with the speech recognition SW. With your smaller embedded system, you will be using the PocketSphinx version of this code.

You will have to download two pieces of SW modules: sphinxbase and PocketSphinx. Select the download option at the top of the page, and then find the latest version of both of these packages. Download the .tar.gz version of these and move them to the /home/ubuntu directory of your BeagleBone Black. However, before you build these, you need two libraries.

The first library is libasound2-dev. If you skipped the first two objectives of this project, you'll need to download it now using sudo apt-get install libasound2-dev. If you're unsure that it's installed, try it again. The system will warn you if it's already installed.

The second is a library called Bison. This is a general purpose, open source parser that will be used by PocketSphinx. To get this package, type sudo apt-get install bison.

Once everything is installed and downloaded, you can build PocketSphinx. First, your home directory should look like the following, with the tar.gz files of both pocketsphinx and sphinxbase:

Engage thrusters

To unpack and build the sphinxbase, type sudo tar –xzvf sphinx-base-0.x.tar.gz, where x is the version number; in my case it is 8. This should unpack all the files from the archive into a directory called sphinxbase-0.x. Now change directory to sphinxbase-0.x. Listing the files should show something like the following:

Engage thrusters

To build the application, start by issuing the command: ./configure --enable-fixed. This command will check to make sure everything is fine with the system and then configure a build. When I first attempted this command, I got the following error:

Engage thrusters

This highlighted an interesting problem. The time and date on my BeagleBone Black was not set to the current time and date. The BeagleBone Black does not have a battery like your PC, so it cannot store a date. Issuing the date command confirmed this as shown in the following screenshot:

Engage thrusters

If you need to set the current date and time, do that by issuing the command sudo date nnddhhmmyyyy.ss, where nn is the month, dd is the day, hh is the hour, mm is the minute, yyyy is the year, and ss is the seconds. This will set the date to the desired date. Now you can reissue the ./configure --enable-fixed command.

One final install will enable you to use makefiles to compile your code. This library is build-essential. Install this by typing sudo apt-get install build-essential. Now you are ready to actually build the sphinxbase codebase. This is a two-step process:

  1. Type make, and the system will build all the executable files.
  2. Type sudo make install, and it will install all the executables onto the system.

Now you need to make the second part of the system: the PocketSphinx code itself.

Go to the home directory and uncompress and unarchive the code by typing tar -xzvf pocketsphinx-0.8.tar.gz. The files should now be unarchived, and you can now build the code. You'll follow similar steps for these files:

  1. Change directory to the pocketsphinx-0.8 directory and type ./configure to see if you are ready to build the files.
  2. Type make, wait for a bit for everything to build, then type sudo make install.

Note

Several possible additions to your library installation will be useful later if you are going to use your PocketSphinx capability with Python as a coding language. You can install python-dev using sudo apt-get install python-dev and Cython using sudo apt-get install cython. You can also choose to install pkg-config, a utility that can sometimes help do with complex compilations. Install it using sudo apt-get install pkg-config.

Once the installation is complete, you'll need to let the system know where your files are. To do this you will need to edit the /etc/ld.so.conf as root. Add one line to the end of the file, /usr/local/lib, so that your file looks like this:

Engage thrusters

Now type /sbin/ldconfig, and the system will now be aware of your PocketSphinx libraries.

Everything is installed, so you can try your speech recognition. Change directory to the bring this all on one line directory to try a demo program. Type pocketsphinx_continuous. This program takes in input from the microphone and turns it into speech. After running the command, you'll get a lot of irrelevant information and then see the following:

Engage thrusters

Even though it tells you that it can't find your microphone element or a capture element, if you have set things up as previously described, you should be ready to give it a command. Say "hello" into the microphone. When it senses that you have stopped speaking, it will process your speech, give lots of irrelevant information again, but should eventually show this screen:

Engage thrusters

Notice the 000000001: hello. It recognized your speech! You can try other words and phrases too. The system is very sensitive, so it may pick up background noise. You are also going to find that it is not very accurate. If you'd like to improve the accuracy, see the Classified intel section. To stop the program, type cntrl-c.

Objective complete – mini debriefing

Your system can understand your speech input! In the next section of this project, you'll learn how to use this input to have the project respond.

Classified intel

There are two ways to make the system more accurate. One is to train the system to more accurately understand your voice. It is a bit complex, and if you want to know more go to Carnegie Mellon University's (CMU) PocketSphinx website.

The second way to improve accuracy is to limit the number of words that your system uses to determine what you are saying. The default has literally thousands of word possibilities, so if two words are close, it may choose the wrong word. To avoid this, you can make your own grammar to restrict the words it has to choose from.

The first step is to create a file with the words or phrases you want the system to recognize. Then you use a web tool to create two files that the system will use to define your grammar. I'll do this through the vncserver, since I'll need to use a web browser. The next step is to create a file called grammar.txt and insert the text shown in the following screenshot:

Classified intel

Now you must use the CMU web tool to turn this file into two files that the system can use to define its dictionary. On my system, I have already installed Firefox using sudo apt-get install firefox. So, now I can open a web browser window and go to this URL: http://www.speech.cs.cmu.edu/tools/lmtool-new.html. If I hit the browse button, I can then find and select the file. It should look something like the following:

Classified intel

Open the grammer.txt file, then on the web page select COMPILE KNOWLEDGE BASE, and the following window should pop up:

Classified intel

You need to download the .tgz file the tool created, in this case the TAR1565.tgz file. This will download to your /home/ubuntu/Download directory. Move it to the /home/ubuntu/pocketsphinx-0.8/src/programs directory and unarchive it using tar –xzvf and the filename. You should end up with the programs shown in the following screenshot in the directory:

Classified intel

Now you can invoke pocketsphinx_continuous to use this dictionary by typing pocketsphinx_continuous -lm 1565.lm -dict 1565.dic, and it will look in that directory to find matches to your commands.

You can also do this on your remote computer using Windows, creating the file in a text editor such as WordPad. Once you have created the required grammar files, you can download them to your BeagleBone Black using WinScp.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.22.160