Speech Recognition

Do you know how Alexa or other personal assistants work?

Alexa

Well, don’t you worry! You’ll learn that in this lesson.

Topic Covered in the Lesson

At the end of  the lesson, you will be able to:

  1. Understand how speech recognition works.
  2. Use AI blocks in PictoBlox to convert speech into text.
  3. Make your own virtual assistant in PictoBlox which recognizes your that can recognize your command play the requested song.

Key Learning Outcomes

  1. Speech Recognition
  2. How does Alexa work?
  3. Speech Recognition in PictoBlox
  4. Text to Speech in PictoBlox

Let’s begin! 

How Do Humans Learn a Language?

From the time we are born, we hear words and sounds around us. Even before we can speak, we hear some words that we start responding to words like Mama, Dada, Yes, No.

Our brain tries to find patterns to differentiate various sounds and words and categorize them. It may seem as though humans are pre-programmed to listen and understand but it is not so. We have been trained to develop this ability.

Multiple_languages

 

Speech recognition technology has been developed on the same lines. Computers are also trained in the same way. 

Speech Recognition

Speech recognition is very complex and a lot of mathematical equations are involved. Let’s break it down into simple steps:

  1. First, the machine records the audio file.
  2. Then, it breaks down the audio to extract consonants and vowels (the building blocks of a text). After this process, we get a list of consonants and vowels. 
  3. Using the word database of the language, the machine tries to identify words from the list and then make sentences thus converting the speech into text. 

How Alexa Works

Alexa, Amazon’s virtual assistant AI technology, uses natural language processing, a procedure of converting speech into sounds, words, and ideas.

Here’s how she works:

  1. Alexa first records your speech. Then, this recording is sent to Amazon’s servers to be analyzed more efficiently.
  2. Amazon breaks down the recording into individual sounds. It then consults a database containing various words’ pronunciations to find which words most closely correspond to the combination of individual sounds.
  3. It then identifies keywords to make sense of the tasks and carry out corresponding functions. E.g. if Alexa notices words like “weather” or “temperature”, it will open the weather app.
  4. Amazon’s servers send the information back to your device. If Alexa needs to say anything back to you, it will go through the same process described above, but in reverse order.

Speech-to-Text Blocks in PictoBlox

The Artificial Intelligence extension in PictoBlox has blocks dedicated to speech recognition. Let’s first add the extension in our project:

  1. Create a new project in PictoBlox.
  2. Select evive as your board from the Board tab in the menu bar.
  3. Next, click on the Add Extension button and add Artificial Intelligence extension.

AI Extension

Speech Recognition Block

To execute speech recognition, we have the recognize speech for () s in ()

recognize speech () s in ()

When the block is executed, the recognition window will open and you will get a specified time during which PictoBlox will record whatever you say. Once recorded, the speech will be converted to the text of the language you spoke in and saved locally. 

Speech Result Block

To get the result, we have the speech recognition result block. It reports the last text detected from the speech.

speech recognition result

Here is a simple example of how to use the speech recognition blocks:

Speech Recognition

SR

Activity: Make Your Own Alexa

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:

  1. Spider Man: https://learn.thestempedia.com/wp-content/uploads/2020/04/Spiderman.mp3
  2. Mario: https://learn.thestempedia.com/wp-content/uploads/2020/04/Mario.mp3

Once you open the link:

Follow the steps to set up the Stage:

  1. Switch to Sounds tab and select Upload Sound from the bottom left corner.
    Choose Sound
  2. Select the two sounds downloaded, and open the sounds.
  3. Delete the Grunt sound from the library.
  4. 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.

Text to Speech

Speech Recognition

  1. Add a when flag clicked block into the scripting area.
  2. Snap a recognize speech for () s in () block below the when flag clicked block. Change the time to 4 seconds.
    Alexa 1
  3. Now, snap an if () else block below the recognize speech for () seconds block.
  4. 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.
  5. Add a speak () block from Text to Speech palette under the if arm and write the message “Playing Mario Song!“.
  6. Next, a snap play sound () until done block below the speak () block and select Mario. This is how the script look:
    Alexa 2
  7. Duplicate the if () else block and snap it under the else arm.
  8. Change “mario” to “spiderman” in the condition of the if arm.
  9. Change the message in the speak block to “Playing Spiderman Song!“.
  10. Change the sound to Spiderman.
    Alexa 3
  11.  Finally, in under 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:Alexa 4Click the green flag to start the script.

Next Session

Session 6

Machine Learning

Download PictoBlox – Coding and AI Project Making App

Incase of any difficulty with PictoBlox, please feel free to write us at support@thestempedia.com

Copyright 2021 – Delhi Government All rights reserved | Managed by Valeur Fabtex Private Limited | Technology Partner – STEMpedia