Now that your robot can both speak and listen, let's see if you can make it respond to your commands.
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.
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:
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:
/* Exit
, if the first word spoken was GOODBYE */
.if (strcmp(word, "good bye") == 0)
, change the good bye
to GOODBYE
.{ }
around the break;
statement and add the following statement just before the break;
: system ("espeak" "good bye"");
.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:
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.
3.145.179.35