Using Polly with Lambda

Tried using Polly with Lambda and here’s the code:

import json
import boto3

def lambda_handler(event, context):
# TODO implement
polly_client = boto3.Session(region_name=’us-east-1′).client(‘polly’)
# aws_access_key_id=,
# aws_secret_access_key=,
# region_name=’us-west-2′).client(‘polly’)

response = polly_client.synthesize_speech(VoiceId=’Joanna’,
OutputFormat=’mp3′,
Text = ‘This is a sample text to be synthesized.’)

file = open(‘/tmp/speech.mp3’, ‘wb’)
file.write(response[‘AudioStream’].read())
file.close()

s3 = boto3.client(‘s3’)
with open(“/tmp/speech.mp3”, “rb”) as f:
s3.upload_fileobj(f, “paulpajo.bucket.xxxxx”, “speechconvert.mp3”)

return {
‘statusCode’: 200,
‘body’: json.dumps(‘Hello from Lambda!’)
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s