One of the most common ways for people to communicate is talking to each other. Today we want to create a program so we can talk to the robot!
First, we need to understand what a conversation is.
The step of a discussion which requires the robot to listen and understand is achieved with a Choregraphe box named: Speech Reco.
How does this box work?
Let's explore, look at the board and the box that is shown and identify the following:
Make the robot distinguish multiple names or words.
In this next exercise, we will program the robot to listen for different names and respond differently after hearing each one.
Open Choregraphe and look into the box library for Speech Reco drag it to the workspace.
Explore by clicking on the wrench to configure a word list.
Set the word list to “nao;r 2 d 2;c 3 p o”. The semicolons separate different words in the library. Do not forget to add the spaces. Once again, set the threshold to 10%.
Next, add a Switch Case box. This is found in the list of flow control tools.
Change the predefined inputs of the Switch Case box to match the words in the speech recognition library. You need to add quotation marks around each word to indicate that it is a string, e.g., “nao”. Note also that the capitalization should be the same as in the speech recognition library—the strings must match exactly. When a word in the speech recognition library is heard, the Speech Recognition box sends that word to the Switch Case box.
Now add four Say boxes, and connect the boxes in order for each say to be triggered by the right word.
Add relevant messages to the Say boxes.
Find a way to stop the robot listening function when a word is passed by the speech recognition box.
Press play and try saying the different names.
You may notice that the speech recognition is not perfect. For example, the robot may hear “c 3 p o” when you said “r 2 d 2”. Or, the robot may not understand what you said, even though you said “nao”. The level of recognition can be adjusted via the threshold in the Speech Recognition box.
Recall that we set the threshold to 10% in the Speech Recognition box. This means that the robot has to only be 10% sure of what it hears to recognize the word. Why not set the threshold to a much higher number like 90% then? If the threshold is too high, then the robot may not understand the words you say because it is unsure.
Try changing the value of the threshold, to get a better idea of what it does and how it affects the speech recognition. What value works best?
Advanced Task: Self-Introductions
In this exercise, we will create a box using Python that introduces the NAO based on whichever name a human says.
1. Drag and drop a Speech Reco box, click the wrench and insert the following words:“nao;r 2 d 2;c 3 p o”
2. (Right click, choose “Add a New Box”) and select a python box. Choose an appropriate name (for example- Speech box), tooltip and image. In the Inputs / Outputs / Parameters section, click the center button to the right of “Inputs: onStart”, the first line. This allows us to set the properties of the onStart input.
3. A dialog box appears. Change the type to string, and click OK. This makes the input to the box take a string (a sequence of characters).
4. The Speech Recognition box outputs a string, the word that has been recognized. Now we can link the two boxes together since the onStart input accepts a string.
5. Double-click on the new box to edit the Python source code.
hint: You need a function that will make the robot speak and a way to get the string from the input.
6. Next, you need to add a way for the robot to communicate when he doesn't understand.
7. Hit play and try speaking the different names.
Advanced Task: Specialized Introductions with if Statements
Until now, we have always executed the same code in each program. But we can also use conditionals to execute code only if some condition is satisfied. We will modify the previous exercise to give specialized greetings for each robot name.
- Begin with the result of the previous exercise.
- Double click on the custom box to edit the Python source code.
4. Run the program and try speaking the different names.
- Have the NAO ask “How are you?” Depending on what you say, the NAO should reply “That’s good to hear” or “I hope your day gets better!”
- Create a chain of interactions with the NAO, where it first asks if you like cake or pie. If you like cake, it asks if you like chocolate cake or cheesecake. If you like pie, the NAO asks if you like apple pie or pumpkin pie. Finally, depending on the type of cake or pie you like, the NAO will say something appropriate and relevant, such as “I like chocolate cake too, especially with whipped cream on top.”
- Create a voice-controlled robot, where you can tell the NAO to walk forward, turn left or turn right, and the NAO executes the action you said.
- Write a Python script to execute the actions in the exercise above.