Skip to content

Latest commit

 

History

History

apigw-lambda-sfn-transcribe-translate-polly-sam

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

API Gateway Websockets - Lambda - Step Functions - Transcribe - Translate - Polly - S3

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.

Programming Language

This is a Node.js project which uses WebPack along with AWS SDK for Javascript.

Services

The AWS services used in this pattern are

  • Amazon API Gateway
  • Amazon S3
  • AWS Lamdba
  • AWS Step Functions
  • Amazon Transcribe
  • Amazon Translate
  • Amazon Polly

architecture

Requirements

Deployment Instructions

  1. 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
    
  2. Change directory to the pattern directory:

    cd serverless-patterns/apigw-lambda-sfn-transcribe-translate-polly-sam
    
  3. Build the stack using sam:

    sam build
    
  4. Once build succeeded, deploy the stack. Choose options as needed:

    sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
    
  5. 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.

How it works

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.

Testing

Follow the steps to test the pattern:

  1. Copy the audio to the input bucket (available from the output of the cloudformation stack).
    aws s3 cp audio.ogg s3://{input-bucket-name}
  2. Install the websocket client
    npm install -g wscat
  3. 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
  4. 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" }
  5. A signed S3 url will be returned as an output containing the audio file. Play the file from the url.

Cleanup

  1. Manually delete all the S3 buckets created by the stack.

  2. Delete the stack

    sam delete

Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0