-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathlambda_s3_trigger_transcribe.py
More file actions
43 lines (35 loc) · 1.19 KB
/
lambda_s3_trigger_transcribe.py
File metadata and controls
43 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
-*- coding: utf-8 -*-
========================
AWS Lambda
========================
Contributor: Chirag Rathod (Srce Cde)
========================
"""
import json
from urllib.parse import unquote_plus
import boto3
transcribe = boto3.client("transcribe")
def lambda_handler(event, context):
if event:
file_obj = event["Records"][0]
bucket_name = str(file_obj["s3"]["bucket"]["name"])
file_name = unquote_plus(str(file_obj["s3"]["object"]["key"]))
s3_uri = create_uri(bucket_name, file_name)
job_name = context.aws_request_id
transcribe.start_transcription_job(
TranscriptionJobName=job_name,
Media={"MediaFileUri": s3_uri},
MediaFormat="mp3",
LanguageCode="en-US",
OutputBucketName="bucket-name",
Settings={
# 'VocabularyName': 'string',
"ShowSpeakerLabels": True,
"MaxSpeakerLabels": 2,
"ChannelIdentification": False,
},
)
return {"statusCode": 200, "body": json.dumps("Transcription job created!")}
def create_uri(bucket_name, file_name):
return "s3://" + bucket_name + "/" + file_name