Build A Translator App in 30 Min or Less
Use Amazon Translate, Amazon Comprehend, Amazon Lambda, Amazon Polly, and Amazon Lex to bring a translation application to life and test it in 30 minutes or less.
About | ||
---|---|---|
✅ AWS Level | Intermediate - 200 | |
⏱ Time to complete | 30 minutes | |
💰 Cost to complete | AWS Free Tier | |
🧩 Prerequisites | - AWS Account - Foundational knowledge of Python | |
📢 Feedback | Any feedback, issues, or just a 👍 / 👎 ? | |
⏰ Last Updated | 2023-09-15 |
- How to use Artificial Intelligence service to detect the dominant language in texts.
- How to use Artificial Intelligence service to translate text.
- How to use Artificial Intelligence service to convert text into lifelike speech.
- How to create a Artificial Intelligence conversational interfaces bot to handle translation requests.
- Amazon Comprehend in charge of detecting the language entered.
- Amazon Translate it will translate into the desired language.
- Amazon Polly it delivers the audio with the correct pronunciation.

- Part 1 - Create the Function That Detects the Language and Translates It Into the Desired Languag 🌎.
- Part 2 - Create the Function to Converts Text Into Lifelike Speech 🦜.
- Part 3 - Configure the Chatbot Interface With Amazon Lex🤖.
- Part 4 - Build the Interface Between the Backend and the Frontend.
- Part 5 - Integrate the Backend With the Frontend.
- Part 6 - Let’s Get It to Work!
- Part 7 - Deploy Your Translator App.
- Text (string): The text to translate.
- SourceLanguageCode (string): One of the supported language codes for the source text, if you specify auto, Amazon Translate will call Amazon Comprehend to determine the source language ✅.
- TargetLanguageCode (string): One of the supported language codes for the target text.

StartSpeechSynthesisTask Parameters | GetSpeechSynthesisTask Parameter |
---|---|
OutputFormat(string): the value at which the result will be returned and it can be: json,mp3, ogg_vorbis or pcm. OutputS3BucketName (string): It's the Amazon S3 bucket name to which the output file will be saved. Text (string): The input text to synthesize. Engine (string): It specifies the engine (standard or neural) for Amazon Polly to use when processing input text for speech synthesis. VoiceId (string): Voice ID is used for the synthesis. | TaskId (string): This is the Amazon Polly generated identifier for a speech synthesis task. |
- StartSpeechSynthesisTask:
- GetSpeechSynthesisTask:
🚨Note: This application will not wait for the SpeechSynthesisTask, since the duration depends on the length of the text. GetSpeechSynthesisTask only delivers the status of the task id.
Component | Descripcion | Value |
---|---|---|
Language | You can select any Languages and supported by Amazon Lex V2. | English (US) |
Intent | An intent represents an action that the user wants to perform | TranslateIntent |
Slot types | Allow a Lex bot to dynamically collect data from users during a conversational flow in order to complete actions and provide customized responses. There are built-in slot types and Custom Slot Types. In this tutorial you're going to create custom slots. | text_to_translate: the text you want to translate. language: the language into which you want to translate the text. |
Utterances | Indicate the user's intent, activate the chat. It should be in the language of the chatbot | I want to translate I want to do a translation I want to translate to {language} |
- Sign in to the AWS Management Console and open the Amazon Lex console
- Follow the instructions To create an Amazon Lex V2 bot (Console) for the Creation method chosse Create a blank bot and To add a language to a bot
text_to_translate
, language
).- In the left menu, choose Slot types, then Add slot type and select Add blank slot type.
- Complete with the following parameters for each slot type:
Parameter | language | text_to_translate |
---|---|---|
Slot type name | language | text_to_translate |
Slot value resolution | built-in slot type | Restrict to slot values |
Slot type values | [0-9][a-z][A-Z] | Value: Language Code - new Value: Language (Find Language code and Languages values here) - Add as many as you want |
Image result | ![]() | ![]() |
- Sample utterances: Type the values of Utterances
- Slots: Select Add Slot and complete the following information:
Parameter | language | text_to_translate |
---|---|---|
Name | language | text_to_translate |
Slot type | language | Restrict to slot values |
Prompts | What language do you want to translate? | What do you want to translate? Just type and I'll tell you the language... magic! |
Image result | ![]() | ![]() |
🚨Important: The order matters, make sure thatlanguage
type is the first slot to be required.

👩🏻💻Note: When you build a Lex bot, you are re-training the bot with updated configurations and logic, allowing it to learn from the new parameters.
- ConfirmIntent - The next action is asking the user if the intent is complete and ready to be fulfilled. This is a yes/no question such as "Place the order?"
- Close - Indicates there will not be a response from the user. For example, the statement "Your order has been placed" does not require a response.
- Delegate - The next action is determined by Amazon Lex.
- ElicitIntent - The next action is to determine the intent that the user wants to fulfill.
- ElicitSlot - The next action is to elicit a slot value from the user.

- The user starts the Intent, triggering the Lambda Function which is always listening. Lambda does not receive the expected
language
value, so it will Delegate Lex to continue handling the conversation by eliciting thelanguage
slot. - The user provides the language and Lex interprets the value as a language code. The Lambda Function sees the
language
value and asks Lex to ElicitSlottext_to_translate
. - The user provides the text to translate. Since the text is variable and unpredictable, Lex cannot interpret it as the
text_to_translate
value. So the Lambda Function interprets the text insted Lex and starts the translation and text-to-speech process. Finally, it replies to Lex with an ElicitIntent containing the translated text and a pre-signed link.
interpretation
is an array with values of the slots and the state of the conversation.activeContexts
) inside of the state of the user's session (sessionState
) value. To get it, use:sessionAttributes
:🚨Important: Import the necessary libraries, define the name of the bucket_name and initialize the clients for Boto3 from the AWS services, and Deploy to save.
- Open the Functions page of the Lambda console, and choose the name of a function.
- Choose Configuration, and then choose Permissions, then click on the Role name (Fig. 9).

- In the Identity and Access Management (IAM) console, go to Add Permision --> Create inline policy
- Select JSON, in the Policy editor. Copy this JSON:
🚨Important: Replace YOU-BUCKET-NAME with your bucket name.
- Select Next, write the Policy name and then Create policy.
- Open the Amazon Lex console choose the name of the bot that created in Part 2.
- In the left panel choose Aliases, choose the name of the alias (Fig. 10).

- From the list of supported languages, choose the language (English (US)).
- Choose the name of the Lambda function to use, then choose the version or alias of the function and choose Save.


- Go to your Bot, then in the left panel select Bot version and select Create version (Fig. 13).

- Create a Bot version and select Create.
- Then to Deployment --> Aliases and select Create Alias.
- Named de Alias and Associate with a version, choose the new version (Fig. 14), and select Create.

- You can also learn more about All the things that Amazon Comprehend, Rekognition, Textract, Polly, Transcribe, and Others Do.
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.