Skip to main content

Hello world!

To conclude this first series of posts, and before we dwell into other projects, we will write a simple program that verifies we managed to perform all steps correctly, and therefore we are capable of freely using the bridges established between Cozmo, the Voice Kit and our smartphone. In order to access the various examples which will allow us to create the first test program, we should open the "Dev terminal", which can be found on the Desktop, and navigate our way to the voice examples. (use "cd aiyprojects-raspbian/src/examples/voice" to do so). Our "Hello world" will be based on the program "assistant_library_with_local_commands_demo.py", which allows the user to create custom voice commands to be executed or interpreted by the AIY's Voice Kit.

To create such new command, we should first create a string that represents the words the user should say. For instance, if we wish Cozmo to say some words when asked to, we can use the string "robot speak". Make sure it's two words long at most. We should insert these next lines of code after the 77th line in the aforementioned Python script:

 elif text = 'robot speak'
        # insert desired function here

After importing all Cozmo's libraries via writing "import cozmo" at the very beggining of the script, we will also write down the function in charge of making our robot speak. My personal "Hello world" was a sentence I hold dear to me: "The little ones bite, but they're still not a threat". To create said function, we must write the following after all the "imports":

def cozmo_helloworld(robot: cozmo.robot.Robot):
        robot.say_text("The little ones bite but they're still not a threat").wait_for_completed() 

Finally, we will call this function from the aforementioned "elif":
 
 elif text = 'robot speak'
        cozmo.run_program(cozmo_helloworld)

This way, when we execute the "assistant_library_with_local_commands_demo.py" script, we only have to wait until the program boots up, and then say "OK Google" to trigger it's "listening" mechanic (the button wil light up if the Voice Kit is listening). Then, we can say "robot speak" and watch how Cozmo says teh sentence we previously wrote ("The little ones bite, but they're still not a threat"). this very same process allows the user not only to make Cozmo say anything they want, but also to run more complex commands, involving movement, artifical vision and path learning, all using Cozmo's SDK libraries. A small example could be this small clip where my mother asks Cozmo to recite some verses from José de espronceda's "Canción del Pirata":




The only thing left now is to let our imagination flow to get our little buddy to do everything we want. Perhaps this could be the start of a new project by your side. Feel free to comment with your ideas and experiences. I will also make sure to answer any doubts you might have regarding Cozmo or the Voice Kit.

It has been a pleasure getting involved in this little project, and I hope anyone who reads this gets to feel the same sense of fulfillment I got to experience when watching Cozmo pronounce his first words.

Comments

Popular posts from this blog

Hardware setup

In order to properly illustrate our setup's assembly progress, we will divide it in two sections which we will later join together. On one hand, we will show the required configuration for our Cozmo robot and, on the other, the Voice Kit's, aiding the process with images and simple schemes. We will start off with the connection setup between our Cozmo robot and the Raspberry Pi 3B. As seen on the scheme above, the connection between these two devices is pretty straight-forward: just accomodate the robot in his charger, connecting it to any nearby power point, and activate the Wi-Fi communication protocols between our smartphone and the device. These protocols are predefined in the Cozmo mobile app, and don't require any additional intervention by the user aside from connecting to the appropiated network using the password displayed on Cozmo's screen (in case the password doesn't appear, we can turn on said screen by manually raising and lowering his lift). ...

Software setup

Given that Raspbian's OS is a comfortable environment to work with Python, and provided that the libraries and programs in charge of controlling both the Voice Kit and Cozmo are avaliable in the same language, it will be the one we will be using to write our scripts and future programs. But before this, it's required that we obtain the appropiated libraries for an optimal communication between the robot and our board, while verifying the kit is working accordingly. We will start off by making the adequated checks regarding this last one: According to the user manual associated to the AIY's Voice Kit, in order to check both the microphone and speaker are working fine, it will be necessary to execute the Python script "Check audio.py".    After executing it from the LXTerminal, our output shows the program has been executed successfuly and, because of this, we can safely assume both peripherials are working. Next up, we need to check our Raspberry Pi'...