Python Amazon Polly

By now if you have been following my blog, you know about AWSary.

What if we could generate sound out of text, what if I could "magically" have AWS generate all AWS Services names in voice format so I know how to pronounce them?

First we importo boto3 the AWS SDK for Python.

import boto3

Then we load initiate a DynamoDB client as well as a Polly client.

dynamodb = boto3.resource('dynamodb', region_name='eu-west-1')
table = dynamodb.Table('AWSary-services')
polly_client = boto3.client('polly')

Now that we have the clients, let's scan the table for some items, since we want all of them

response = table.scan()
items = response['Items']

For each item in the table that we scanned, let's print out to the CLI just for feedback, then call polly client and save the result on a file in the local disk, we will use this later to copy for our S3 to serve with CloudFront on the iOS Mobile Application.

for item in items:
    print("Start working on: " + item['name'])
    service_name = item['longName']
    response = polly_client.synthesize_speech(VoiceId='Brian', OutputFormat='mp3', Text=service_name)

    file = open('speech/' + item['name'].replace(' ','_') + '_Brian_' + 'en-GB' + '.mp3', 'wb')
    file.write(response['AudioStream'].read())
    file.close()
    print("Done with: " + item['name'])

Let's look at everything together:

AWSary-iOS/utils/polly.py at main · AWSary/AWSary-iOS
AWS Dictionary iOS App. Contribute to AWSary/AWSary-iOS development by creating an account on GitHub.
import boto3

dynamodb = boto3.resource('dynamodb', region_name='eu-west-1')
table = dynamodb.Table('AWSary-services')
polly_client = boto3.client('polly')

response = table.scan()
items = response['Items']

for item in items:
    print("Start working on: " + item['name'])
    service_name = item['longName']
    response = polly_client.synthesize_speech(VoiceId='Brian', OutputFormat='mp3', Text=service_name)

    file = open('speech/' + item['name'].replace(' ','_') + '_Brian_' + 'en-GB' + '.mp3', 'wb')
    file.write(response['AudioStream'].read())
    file.close()
    print("Done with: " + item['name'])

What should I do next, open an issue and let me know your ideas:

Issues · AWSary/AWSary-iOS
AWS Dictionary iOS App. Contribute to AWSary/AWSary-iOS development by creating an account on GitHub.