Skip to content

Instantly share code, notes, and snippets.

@skippednote
Created December 17, 2020 18:58
Show Gist options
  • Save skippednote/86a700a49b2f1d8734aebfd5f7851c02 to your computer and use it in GitHub Desktop.
Save skippednote/86a700a49b2f1d8734aebfd5f7851c02 to your computer and use it in GitHub Desktop.
import * as TranscribeService from 'aws-sdk/clients/transcribeservice';
const { TRANSLATIONS_BUCKET_NAME, CLIPS_BUCKET_ARN } = process.env;
const ts = new TranscribeService();
export const handler = async (event: any = {}): Promise<any> => {
try {
console.log(JSON.stringify(event, null, 2));
const { Records } = JSON.parse(event.Records[0].body);
Records.forEach(async (record: any) => {
const { object, bucket } = record.s3;
const key = decodeURI(object.key);
const a = await ts
.startTranscriptionJob({
TranscriptionJobName: key.replace('.mp3', ''),
Media: {
MediaFileUri: `s3://${bucket.name}/${key}`,
},
LanguageCode: 'en-US',
OutputBucketName: TRANSLATIONS_BUCKET_NAME!,
JobExecutionSettings: {
AllowDeferredExecution: true,
DataAccessRoleArn: CLIPS_BUCKET_ARN,
},
})
.promise();
});
return { statusCode: 201, body: 'Queued for Transcribing!' };
} catch (e) {
return { statusCode: 503, body: `Failed to transcribe, ${e}` };
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment