AI - A Voice Translator (Difficulty: 2)
-
Key Topics Covered
Introduction
In this tutorial, we’ll build an AI program that can translate between any 2 languages. For example, the user might say some words in English, then we display the translation in Spanish, and also speak out those words.
Step 1 - Pick a Backdrop
Please create a new project, and remove the dog sprite. Select a backdrop for the stage, such as “Stars”.
Step 2 - Add the First Label
Please load the “Widgets” extension, then add a label widget. Its text should be “Say something in English”, and please try to make it cover the upper half of the stage:
As shown, you can use the “widget position” tool to manually move and resize the label widget. You need to move the mouse slowly to keep dragging the handles. The position and size values in the block will be updated automatically as you drag.
Step 3 - Format the Label
Next, let’s make the label look nicer, with a transparent background and larger text.
Here are the blocks you need to add. Note that since we have already added the label, you can choose it from the dropdown list.
Step 4 - Recognize Speech
Next, let’s open the microphone and recognize what the user is saying for 3 seconds:
Step 5 - Display the recognized text
Now let’s display the recognized text in the label. You can use the “text from speech” block to read the recognized text, and use the “set value to” block to set the text on the label.
Now if you try to say something in English, it will show up in the label:
Step 6 - Translate the text
Next, we need to translate the words into Spanish. Let’s use 2 new variables “English words” and “Spanish words” to store the original text and the Spanish translation.
Step 7 - Add another label
Next, we need to display the Spanish words. Please add another label, and then update its style. Note that you have to add this new label first, then you can see its name in the dropdown menu of other blocks.
And here are the new blocks you need:
Step 8 - Speak the Spanish Words
For the last step, we need to also speak out the Spanish words. You can use the “AI Speaker” for this.
This is the final result:
Creative Ideas
There are many ways you can extend this project. Here are some ideas for your inspiration:
-
Allow the user to pick 2 languages: you can use 2 dropdown menus to allow the user to pick the languages.
-
Continuous Mode: after speaking out the translated words, you can restart a new speech recognition, so the user does not need to click the green flag button.
-
-