In this project, we will make our own personal assistant like Alexa.
We will be making a script that will recognize our voice command and analyze it to play the Mario theme song or the Spider-Man theme song. If the command is not recognized, it will say that it didn’t understand the command.
Let’s start.
Setting Up the Stage
Download the songs from here:
- Spider-Man: https://ql.reallyai.net/wp-content/uploads/2022/02/Spiderman.mp3
- Mario: https://ql.reallyai.net/wp-content/uploads/2022/02/Mario.mp3
Follow the steps to set up the Stage:
- Switch to the Sounds tab and select Upload Sound from the bottom left corner.
- Select the two sounds downloaded, and open the sounds.
- Delete the Grunt sound from the library.
- Switch to Code Tab.
In this project, we will also use the Text to Speech extension to respond to the user. To add it, click the Add extension button and add the Text to Speech extension.
Speech Recognition
- Add a when flag clicked block into the scripting area.
- Snap a recognize speech for () s in () block below the when flag clicked block. Change the time to 4 seconds.
- Now, snap an if () else block below the recognize speech for () seconds block.
- In the condition of the if () else block, add a () contains ()? block from the Operators palette. In the first argument, add a speech recognition result block, and in the second write “mario“. So, if the decoded text contains the word Mario, it will execute the if branch blocks.
- Add a speak () block from Text to Speech palette under the if arm and write the message “Playing Mario Song!“.
- Next, a snap play sound () until done block below the speak () block and select Mario. This is how the script looks:
- Duplicate the if () else block and snap it under the else arm.
- Change “mario” to “spiderman” in the condition of the if arm.
- Change the message in the speak block to “Playing Spiderman Song!“.
- Change the sound to Spiderman.
- Finally, under the else arm, add a speak () block and write “Sorry, I am unable to understand the command“.
The script is complete. It will look like this: Click the green flag to start the script.
Assignment
Before you move on to the next lesson, a small assignment awaits you!
You must upload the PictoBlox program you wrote in this activity to the website.
Submitting the assignment is a must in order to receive the certificate after completing the course.
Follow the steps below to upload your assignment:
- Click Choose File.
- Select the image from the pop-up window that opens up.
- Once the image is selected, click Upload Assignment.
Good luck!