In this section, you will build a pipeline where you can integrate AWS Lambda with Amazon Polly. The pipeline reads a text file and generates an MP3 file, saving it to another folder in the same bucket. You will monitor the task’s progress in CloudWatch logs.
You will begin by creating an IAM role for Lambda. Let’s get started:
Next, you will create a Lambda function:
Important note
The default is 3 seconds. Since this is an asynchronous operation, any retried attempts will create more files.
Figure 8.6 – Edit basic settings window
Now, you will create a bucket to trigger an event.
Figure 8.7 – The S3 bucket after uploading a text file for further processing
File Content: Hello Everyone, Welcome to Dublin.
How
are you doing today?
{‘ResponseMetadata’: {‘RequestId’: ’74ca4afd-5844-
47d8-9664-3660a26965e4′, ‘HTTPStatusCode’: 200,
‘HTTPHeaders’: {‘x-amzn-requestid’: ’74ca4afd-5844-
47d8-9664-3660a26965e4′, ‘content-type’:
‘application/json’, ‘content-length’: ‘471’, ‘date’:
‘Thu, 24 Sep 2020 18:50:57 GMT’}, ‘RetryAttempts’: 0},
‘SynthesisTask’: {‘Engine’: ‘standard’, ‘TaskId’:
‘57548c6b-d21a-4885-962f-450952569dc7’, ‘TaskStatus’:
‘scheduled’, ‘OutputUri’: ‘https://s3.us-east-
1.amazonaws.com/polly-test-baba/output-
audio/.57548c6b-d21a-4885-962f-450952569dc7.mp3′,
‘CreationTime’: datetime.datetime(2020, 9, 24, 18, 50,
57, 769000, tzinfo=tzlocal()), ‘RequestCharacters’:
59, ‘OutputFormat’: ‘mp3’, ‘TextType’: ‘text’,
‘VoiceId’: ‘Aditi’, ‘LanguageCode’: ‘en-GB’}}
The logs sample is shown in Figure 8.8:
Figure 8.8 – The logs in the CloudWatch console
Figure 8.9 – The output file that was created in the S3 bucket
Important note
The most scalable and cost-effective way for your mobile apps or web apps is to generate an AWS pre-signed URL for S3 buckets and provide it to your users. These S3 Put events asynchronously invoke downstream AI workflows to generate results and send a response to the end users. Many users can be served at the same time through this approach, and it may increase performance and throughput.
In this section, you learned how to implement text to speech. In the next section, you will learn about Amazon Transcribe, a speech-to-text AI service.