Created
January 20, 2021 01:22
-
-
Save petereskandar/921b27da1ca605e42add0bb35f77cf3b to your computer and use it in GitHub Desktop.
Transcription job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
exports.handler = async (event) => { | |
var region = 'put your region'; | |
var s3bucket = event['Input']['Bucket']; | |
var s3object = event['Input']['Key']; | |
const transcribe = new AWS.TranscribeService(region); | |
const s3 = new AWS.S3(region); | |
// Start Transcribe job | |
const params = { | |
TranscriptionJobName: s3bucket + '_' + Math.floor(Math.random() * 101), | |
IdentifyLanguage: true, | |
LanguageOptions: ["en-US", "es-US", "fr-FR", "it-IT"], | |
MediaFormat: s3object.split('.')[1].toLowerCase(), | |
Media:{ | |
MediaFileUri : `https://s3-eu-west-3.amazonaws.com/${s3bucket}/${s3object}` | |
} | |
} | |
const response = await new Promise((resolve, reject) => { | |
transcribe.startTranscriptionJob(params, function(err, data) { | |
if(err) reject(err); // an error occurred | |
else resolve(data); // successful response | |
}); | |
}); | |
// get S3Object tags --> email | |
// each uploaded file will have a tag ['Email'] | |
// referring to the user email | |
const s3Params = { | |
Bucket: s3bucket, | |
Key: s3object | |
} | |
const tagsList = await new Promise((resolve, reject) => { | |
s3.getObjectTagging(s3Params, function(err, data) { | |
if(err) reject(err); // an error occurred | |
else resolve(data); // successful response | |
}); | |
}) | |
return { | |
Email: tagsList['TagSet'][0]['Value'], | |
TranscriptionJobName: response['TranscriptionJob']['TranscriptionJobName'] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment