Providing the capability to interpret your commands and have your robot initiate an action

Now that your robot can both speak and listen, let's see if you can make it respond to your commands.

Prepare for lift off

Now that the system can both hear and speak, you want to provide the capability to respond to your speech and execute some commands based on the speech input. Now you're going to configure the system to respond to simple commands.

Engage thrusters

In order to respond, you're going to edit the continuous.c code in the /home/ubuntu/src/programs directory. You could create your own C file, but this file is already set up in the makefile system and is an excellent starting spot. I like to make a copy of the current file into continuous.c.old, so I can always get back to the starting program if it is required. Then you will need to edit the continuous.c file. It is very long and a bit complicated, but you are specifically looking for the following section in the code:

Engage thrusters

In this section of the code, the word has already been decoded and is held in the variable hyp. You can add code here to make your system do things based on the value associated with the word you have decoded. First, let's try adding the capability to respond to "hello" and "goodbye" to see if you can get the program to stop. Make the following changes to the code:

  1. Find the comment /* Exit, if the first word spoken was GOODBYE */.
  2. In the statement if (strcmp(word, "good bye") == 0), change the good bye to GOODBYE.
  3. Put { } around the break; statement and add the following statement just before the break;: system ("espeak" "good bye"");.
  4. Add another else if statement to the clause by typing else if (strcmp(hyp, "HELLO") == 0). Add { } after the else if statement and inside the brackets, system ("espeak" "good bye"");.

The file should now look like this:

Engage thrusters

Now you need to rebuild your code. Since the make system already knows how to build the program pocketsphinx_continuous, anytime you make a change to the continuous.c file, it will rebuild the application. Simply type make, and the file will compile and create a new version of pocketsphinx_continuous. To run your new version, type ./pocketsphinx_continuous. Make sure you type the ./ at the start; if not, the system has another version of pocketsphinx_continuous in the library and will run that.

If everything is set correctly, saying "hello" should result in a response of "hello" from your BeagleBone Black. Saying "good bye" should elicit a response of "good bye," as well as shutting down the program. Notice the system command can be used to run any program that runs with a command line. Now you can use this program to start and run other programs based on the commands.

Objective complete – mini debriefing

Finally, your BeagleBone Black will both listen and respond, and it will execute a command. You are now ready to move on to providing sight for your system.

Classified intel

I'm using the C files that came with PocketSphinx to interact with the system. A set of Python files also came with the system. If you prefer to work in Python, go ahead and explore those examples in the /home/ubuntu/pocketsphinx-0.8/python directory.

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

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