Skip to content

Instantly share code, notes, and snippets.

@em-shea
Created May 3, 2023 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save em-shea/384a88e15a0a65905d33c6ae8a6086f3 to your computer and use it in GitHub Desktop.
Save em-shea/384a88e15a0a65905d33c6ae8a6086f3 to your computer and use it in GitHub Desktop.
ASL definition for audio generation workflow
{
"Comment": "Generates and save audio files for a given list ID.",
"StartAt": "Get word list",
"States": {
"Get word list": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload": {
"list_id.$": "$.list_id",
"last_word_token.$": "$.last_word_token"
},
"FunctionName": "${GetWordsForListIdFunction}"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Next": "Iterate over word batch"
},
"Iterate over word batch": {
"Type": "Map",
"Iterator": {
"StartAt": "Generate audio file",
"States": {
"Generate audio file": {
"Type": "Task",
"Parameters": {
"OutputFormat": "mp3",
"OutputS3BucketName": "${PronunciationAudioBucket}",
"OutputS3KeyPrefix": "audio/",
"Text.$": "$.text",
"VoiceId": "Zhiyu"
},
"Resource": "arn:aws:states:::aws-sdk:polly:startSpeechSynthesisTask",
"Next": "Update item with audio file key",
"ResultPath": "$.pollyOutput"
},
"Update item with audio file key": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:updateItem",
"Parameters": {
"TableName": "${TableName}",
"Key": {
"PK": {
"S.$": "$.list_id"
},
"SK": {
"S.$": "$.word_id"
}
},
"UpdateExpression": "set #w.#a = :audioFileKey",
"ExpressionAttributeValues": {
":audioFileKey": {
"S.$": "$.pollyOutput.SynthesisTask.OutputUri"
}
},
"ExpressionAttributeNames": {
"#w": "Word",
"#a": "Audio file key"
}
},
"Next": "Wait"
},
"Wait": {
"Type": "Wait",
"Seconds": 1,
"End": true
}
}
},
"MaxConcurrency": 10,
"ItemsPath": "$.word_list",
"Next": "Is last_word_token present?",
"ResultPath": "$.mapStepResult"
},
"Is last_word_token present?": {
"Type": "Choice",
"Default": "Get word list",
"Choices": [
{
"Variable": "$.last_word_token",
"IsNull": true,
"Next": "Go to end"
}
]
},
"Go to end": {
"Type": "Pass",
"End": true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment