With HaloCode's microphone and built-in Wi-Fi, we can make a simple speech recognition application. The internet enables HaloCode to use Microsoft's speech recognition service. You need to sign in/up to mBlock 5 to connect your HaloCode to the internet.
Sign UP / Sign In to mBlock 5
Click the sign in/sign up icon at the tool bar, and then follow the instructions to finish signing up or signing in.
Create a Speech Recognition Project
We will create a new project to light up the LEDs of HaloCode by voice command.
Step One: Connect to the Internet
1. Drag an Events block when HaloCode starts up to the Scripts area.
2. Add a Wi-Fi block connect to Wi-Fi () password (). Input the SSID (network name) and password.
3. To make sure Wi-Fi is successfully connected, we need to add a Control block wait () and a Wi-Fi block Wi-Fi is connected?.
4. We want to know when the Wi-Fi is successfully connected. Add a Lighting block all the LEDs light up () to make all the LEDs light up green.
Step Two: Speech Recognition
1. Drag an Events block when button is pressed to the Scripts area.
2. Add a Lighting block all the LEDs light up () to make all the LEDs light up white, and a Wi-Fi block recognize () for () seconds. Set the language to English and keep the default time. When speech recognition is complete, we would like to light off all the LEDs to prevent us from giving overrun speech, so we need to add another Lighting block light off all the LEDs.
3. Since we need to use the recognition result continuously, we can make it a variable. Choose Variables block, and click "Make a Variable". Name the variable "results" and click "OK".
4. Add a Variables block set results to () and a Wi-Fi block speech recognition result to set the recognition result to variable "results".
5. If the word "red" is recognized, we want all the LEDs of HaloCode to light up red and then go off. We need to add a Control block if () then (), an Operators block () contains ()?, and a Variables block results. Input "red" to another box of the Operators block () contains ()?.
6. Add a Lighting block all the LEDs light up (), a Control block wait () seconds, and another Lighting block light off all the LEDs, wrapped up by the Control block if () then (). Set the color to red and keep the default time.
7. Click "Upload" to upload the program to HaloCode.
8. Wait until all the LEDs light up green. Then press the button and say "red". Check the LEDs of HaloCode.