Make Spencer listen and repeat

For the ultimate coding challenge, let's make Spencer listen to what we say and repeat that same sentence with his funny robotic voice. 


We can just continue with the code you have made in the previous chapter for this one. 

Firstly, delete the "synthesize and say" block by right-clicking on it and pressing the delete option.

random image

So now we need the "start listening" block.

random image

Place it here: 

random image

With this code, every time you press its red button, Spencer is going to check if WiFi is connected, play the loading animation, and start listening to what you say. 

When Spencer is done listening, let's play an animation so that we know it's now processing our voice command.

random image

Now find the "when speech gets processed" event block. This block will be triggered once Spencer processes your voice command and receives a transcript from the server.

random image

Drag and drop it onto the drawing area:

random image

Since we want Spencer to repeat what you've said to him, let's find the "Synthesize and say" block: 

random image

Place it here since we want to make Spencer repeat your words as soon as your voice gets processed:

random image

We want Spencer to say the exact thing that you have said. That's why you need to take the red "intentResult->transcript" value block and drop it into the
"synthesize and say" block.

random image

Finally, let's play a talking animation when Spencer's voice sample gets generated and make him wink once he's done talking.

random image

Awesome, your code is done now. 
Save it and run it on your Spencer.

Smack Spencer's head and tell him something (i.e., "Hello Spencer, you are my friend"). Spencer will process your voice command and repeat it with his robotic voice.