This repository contains a GitHub Actions workflow for synthesizing speech from text using Amazon Polly and uploading the resulting audio files to an S3 bucket. ☁️
- Setup AWS Credentials and S3 Bucket
- Create an IAM User with Programmatic Access
- Attach IAM Policies
- Create Access Keys
- Configure GitHub Secrets
- Trigger the Workflows
- Verify the Uploaded .mp3 Files
To set up AWS credentials and an S3 bucket, follow these steps:
-
AWS Account: Ensure you have an AWS account. If not, create one at AWS. 🌐
-
Create an S3 Bucket:
- Go to the S3 service in the AWS Management Console.
- Click on "Create bucket".
- Choose a unique name for your bucket and select a region.
- Configure any additional settings as needed and create the bucket. 🪣
To create an IAM user with programmatic access:
- Sign in to the AWS Management Console.
- Navigate to the IAM service.
- Click on "Users" in the sidebar, then click on "Create user".
- Enter a username for the new user and click on "Next" to proceed to the Set permissions section.
- Click on "Next" to proceed to the "Review and create" section.
- Click "Create user" to proceed. ✅
After creating the IAM user, you need to attach the necessary policies:
-
Create the
AcmeLabsAmazonPollyReadOnlyPolicy:- In the IAM console, go to "Policies" and click "Create policy".
- Switch to the "JSON" tab and paste the following policy:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AcmeLabsAmazonPollyReadOnly", "Effect": "Allow", "Action": [ "polly:SynthesizeSpeech", "polly:DescribeVoices" ], "Resource": "*" } ] } - Click "Next", give it a name (
AcmeLabsAmazonPollyReadOnly), and click "Create policy". 📝
-
Create the
AcmeLabsAmazonS3ReadWritePolicy:- Repeat the steps to create another policy and paste the following JSON:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AcmeLabsAmazonS3ReadWrite", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::acmelabs-aws-polly-synthesize", "arn:aws:s3:::acmelabs-aws-polly-synthesize/*" ] } ] } - Name this policy
AcmeLabsAmazonS3ReadWriteand create it. 🛡️
- Repeat the steps to create another policy and paste the following JSON:
-
Attach Policies to the User:
- Click on "Users" in the sidebar, then click on your new user's name.
- Click on the "Permissions" tab.
- Click on "Add permissions", choose "Attach existing policies directly", and select both
AcmeLabsAmazonPollyReadOnlyandAcmeLabsAmazonS3ReadWrite. - Click "Next" and then "Add permissions". ➕
- Navigate to the "Security credentials" tab of your user.
- Click on "Create access key" tab.
- Click on "Other" for the "Use case".
- Click on "Next" and fill out the "Description tag value" (name the secret).
- Click on "Create access key".
- Make sure to copy the Access Key ID and Secret Access Key.
- You will need these for your GitHub Actions workflow.
- Store these credentials securely, as you will not be able to view the Secret Access Key again. 🔒
- You can also download the credentials as a CSV file for safekeeping.
- Click "Done" to finish. 🎉
-
Go to your GitHub repository.
-
Navigate to
Settings>Secrets and variables>Actions. -
Add the following secrets:
- Click on the "Secrets" tab.
- Click on "New repository secret".
- Name the secrets as follows:
ACMELABS_SYNTHESIZE_AWS_ACCESS_KEY_IDACMELABS_SYNTHESIZE_AWS_SECRET_ACCESS_KEYACMELABS_SYNTHESIZE_AWS_S3_BUCKET
- Enter the corresponding values for each secret.
- For example:
ACMELABS_SYNTHESIZE_AWS_ACCESS_KEY_ID:AKIAIOSFODNN7EXAMPLEACMELABS_SYNTHESIZE_AWS_SECRET_ACCESS_KEY:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYACMELABS_SYNTHESIZE_AWS_S3_BUCKET:acmelabs-aws-polly-synthesize
- For example:
- Click "Add secret" to save each one. 💾
-
Add the following environment variables:
- Click on the "Variables" tab.
- Click on "New repository variable".
- Name the variables as follows:
ACMELABS_SYNTHESIZE_AWS_REGIONACMELABS_SYNTHESIZE_AWS_S3_KEY_PRODACMELABS_SYNTHESIZE_AWS_S3_KEY_BETAACMELABS_SYNTHESIZE_AWS_S3_PREFIX
- Enter the corresponding values for each variable.
- For example:
ACMELABS_SYNTHESIZE_AWS_REGION:us-east-1ACMELABS_SYNTHESIZE_AWS_S3_KEY_PROD:prod.mp3ACMELABS_SYNTHESIZE_AWS_S3_KEY_BETA:beta.mp3ACMELABS_SYNTHESIZE_AWS_S3_PREFIX:polly-audio
- For example:
- Click "Add variable" to save each one. 🌍
The workflows are triggered automatically based on changes to the speech.txt file:
- Create a new branch.
- Make changes to the
speech.txtfile.- Open the
speech.txtfile located in the repository. - Edit the content of the file as needed. For example:
Where’s the kaboom? There was supposed to be an earth-shattering kaboom! - Save your changes.
- Open the
- Commit and push your changes and create a pull request into the
mainbranch to trigger the workflow.- Review GitHub Actions to ensure the workflow runs successfully.
- Click on "Actions" tab in your GitHub repository.
- In the left sidebar, select the workflow named
On Pull Request. - Click on the latest run to view the details.
- Check the logs to ensure that the speech synthesis and S3 upload steps completed successfully. 📊
- Review GitHub Actions to ensure the workflow runs successfully.
- Merge the pull request into the
mainbranch to trigger the workflow.- Review GitHub Actions to ensure the workflow runs successfully.
- Click on "Actions" tab in your GitHub repository.
- In the left sidebar, select the workflow named
On Merge. - Click on the latest run to view the details.
- Check the logs to ensure that the speech synthesis and S3 upload steps completed successfully. 👍
- Review GitHub Actions to ensure the workflow runs successfully.
To verify that the .mp3 files have been uploaded to your S3 bucket:
- Go to the S3 service in the AWS Management Console.
- Navigate to your bucket, click on "Objects" to view the contents.
- Check for the uploaded .mp3 files under the specified prefix (e.g.,
polly-audio). - You can open or download the files to verify their content. 📥
This workflow automates the process of synthesizing text to speech and uploading the audio files to S3. Ensure that your AWS credentials are kept secure and not shared publicly. 🔒