This pattern demonstrates the use of API Gateway, Lambda, Step Functions, Transcribe, Translate, Polly and S3 to create an online language converter app.
Learn more about this pattern at Serverless Land Patterns: << Add the live URL here >>
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
This is a Node.js project which uses WebPack along with AWS SDK for Javascript.
The AWS services used in this pattern are
- Amazon API Gateway
- Amazon S3
- AWS Lamdba
- AWS Step Functions
- Amazon Transcribe
- Amazon Translate
- Amazon Polly
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- AWS Serverless Application Model (AWS SAM) installed
-
Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/serverless-patterns
-
Change directory to the pattern directory:
cd serverless-patterns/apigw-lambda-sfn-transcribe-translate-polly-sam
-
Build the stack using sam:
sam build
-
Once build succeeded, deploy the stack. Choose options as needed:
sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
-
Note the outputs from the Serverless deployment process. These contain the input bucket name where the audio file has to be copied, the state machine arn and websocket API.
API Gateway handles incoming traffic and sends it to the lambda which in turn invokes the step function. The step function orchestrates the process to transcribe for converting speech to text, then to translate for language translation of the text file and finally to polly for converting text to speech and store the audio file in S3. The step function at last returns the S3 signed url to the lambda which is returned as response from API Gateway websockets.
Follow the steps to test the pattern:
- Copy the audio to the input bucket (available from the output of the cloudformation stack).
aws s3 cp audio.ogg s3://{input-bucket-name}
- Install the websocket client
npm install -g wscat
- Run websocket client to invoke the API Gateway. Get the API ID from the output of the deployment step
wscat -c wss://<API-ID>.execute-api.<Region>.amazonaws.com/dev?proto=https
- On the next prompt, add the input parameters. Replace the input bucket name. It can be tested with other language codes as well.
{ "bucketName": "<input-bucket-name>", "objectKey": "audio.ogg", "inputLanguageCode": "en-IN", "outputLanguageCode" : "Hindi |hi-IN" }
- A signed S3 url will be returned as an output containing the audio file. Play the file from the url.
-
Manually delete all the S3 buckets created by the stack.
-
Delete the stack
sam delete
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0