in src/podcast_transcribe.py [0:0]
def lambda_handler(event, context):
session = boto3.session.Session()
region = session.region_name
# Default to unsuccessful
isSuccessful = "FALSE"
# Create a random name for the transcription job
jobname = id_generator()
# Extract the bucket and key from the downloadPodcast lambda function
bucket = event['audioS3Location']['bucket']
key = event['audioS3Location']['key']
content_type = event['audio_type']
if content_type not in CONTENT_TYPE_TO_MEDIA_FORMAT:
raise InvalidInputError(content_type + " is not supported audio type.")
media_type = CONTENT_TYPE_TO_MEDIA_FORMAT[content_type]
logger.info("media type: " + content_type)
# Assemble the url for the object for transcribe. It must be an s3 url in the region
url = "https://s3-" + region + ".amazonaws.com/" + bucket + "/" + key
try:
settings = {
'VocabularyName': event['vocabularyInfo']['name'],
'ShowSpeakerLabels': False
}
if int(event['speakers']) > 1:
settings['ShowSpeakerLabels'] = True
settings['MaxSpeakerLabels'] = max(int(event['speakers']), 4)
# Call the AWS SDK to initiate the transcription job.
response = client.start_transcription_job(
TranscriptionJobName=jobname,
LanguageCode='en-US',
Settings=settings,
MediaFormat=media_type,
Media={
'MediaFileUri': url
}
)
isSuccessful = "TRUE"
except client.exceptions.BadRequestException as e:
# There is a limit to how many transcribe jobs can run concurrently. If you hit this limit,
# return unsuccessful and the step function will retry.
logger.error(str(e))
raise ThrottlingException(e)
except client.exceptions.LimitExceededException as e:
# There is a limit to how many transcribe jobs can run concurrently. If you hit this limit,
# return unsuccessful and the step function will retry.
logger.error(str(e))
raise ThrottlingException(e)
except client.exceptions.ClientError as e:
# Return the transcription job and the success code
# There is a limit to how many transcribe jobs can run concurrently. If you hit this limit,
# return unsuccessful and the step function will retry.
logger.error(str(e))
raise ThrottlingException(e)
return {
"success": isSuccessful,
"transcribeJob": jobname
}