Build a Serverless Application for Audio to Text conversion

Learn how to use Amazon Transcribe and AWS Lambda to build an audio to text conversion application written in Go.

Abhishek Gupta
Amazon Employee
Published Jun 28, 2023
Last Modified Mar 14, 2024
Amazon Transcribe is a service that utilizes machine learning models to convert speech to text automatically. It offers various features that can enhance the accuracy of the transcribed text, such as language customization, content filtering, multi-channel audio analysis, and individual speaker speech partitioning. Amazon Transcribe can be used as a standalone transcription service or to add speech-to-text capabilities to any application. You can transcribe media in real time (streaming) or you can transcribe media files located in an Amazon S3 bucket (batch).
In this tutorial, you will learn how to build a Serverless application for speech (audio) to text conversion using Amazon Transcribe, AWS Lambda and the Go programming language.
We will cover how to:
We will be using the following Go libraries:

Application overview

Application overview
Here is how the application works:
  1. MP3 audio files uploaded to a S3 bucket will trigger a Lambda function.
  2. The Lambda function will submit an asynchronous job to Amazon Transcribe which will finally store the resulting file (containing the converted text) in another S3 bucket.


Before starting this tutorial, you will need the following:
āœ… AWS Level100 - Beginner
ā± Time to complete20 minutes
šŸ’° Cost to completeFree when using the AWS Free Tier
šŸ’» Code SampleCode sample used in tutorial on GitHub
šŸ“¢ FeedbackAny feedback, issues, or just a šŸ‘ / šŸ‘Ž ?
ā° Last Updated2023-06-28

Use AWS CDK to deploy the solution

Clone the project and change to the right directory:
The AWS Cloud Development Kit (AWS CDK) is a framework that lets you define your cloud infrastructure as code in one of its supported programming and provision it through AWS CloudFormation.
To start the deployment, simply invoke cdk deploy and wait for a bit. You will see a list of resources that will be created and will need to provide your confirmation to proceed.
Enter y to start creating the AWS resources required for the application.
If you want to see the AWS CloudFormation template which will be used behind the scenes, run cdk synth and check the cdk.out folder
You can keep track of the stack creation progress in the terminal or navigate to AWS console: CloudFormation > Stacks > LambdaTranscribeAudioToTextGolangStack.
Once the stack creation is complete, you should have:
  • Two S3 buckets: Source bucket to upload audio files and the target bucket to store the transcribed text files.
  • A Lambda function to convert audio to text using Amazon Transcribe.
  • And a few other resources (such as IAM roles etc.)
You will also see the following output in the terminal (resource names will differ in your case). In this case, these are the names of the S3 buckets created by CDK:
You are ready to verify the solution.

Convert speech to text

To try the solution, you can use a MP3 audio file of your own. Since, I really enjoy listening to the Go Time podcast, I will simply use one of its episodes and upload it (the MP3 file) to the S3 source bucket using the AWS CLI.
This will invoke a Transcription Job. You can check its status in the AWS console: Amazon Transcribe > Jobs. Once it completes, you should see a new file in the output S3 bucket with the same name as the audio file you uploaded, but with a .txt extension. This is the output file generated by Amazon Transcribe.
Amazon Transcribe Job
Download and open the output file.
Interestingly enough, it has a JSON payload that looks like this:
You can use the transcript property to extract the actual text.
Now that you have verified the end-to-end solution, you can clean up the resources and explore the Lambda function logic.

Clean up

Once you're done, to delete all the services, simply use:

Lambda function code walk through

Here is a quick overview of the Lambda function logic. Please note that some code (error handling, logging etc.) has been omitted for brevity since we only want to focus on the important parts.
The Lambda function is triggered when a new file is uploaded to the source bucket. The handler function iterates over the S3 event records and calls the audioToText function.
Let's go through the audioToText function.
  • The audioToText function submits a transcription job to Amazon Transcribe.
  • The transcription job is configured to output the results to a file in the target S3 bucket.
Note that the name of the output file is derived from the name of the input file.


In this tutorial, you used AWS CDK to deploy a Go Lambda function to convert audio to text using Amazon Transcribe and store the results in another S3 bucket. Here are a few things you can try out to extend this solution:
  • Build another Lambda function that's triggered by the transcribed file in the output bucket, parse the JSON content and extract the transcribed text.
  • Try to generate transcriptions in real-time with Amazon Transcribe streaming.

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.