-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtranscribeAudio.js
58 lines (49 loc) · 1.87 KB
/
transcribeAudio.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict'
const AWS = require('aws-sdk');
const Scribe = new AWS.TranscribeService({apiVersion: '2017-10-26'});
const pt = require('./parseTranscript.js');
exports.transcribe = async event => {
console.log(JSON.stringify(event));
const filepath = event.Records[0].s3.object.key;
const directory = filepath.split('/');
const filename = directory.pop();
const extension = filename.split('.').pop().toLowerCase();
const sourceBucket = event.Records[0].s3.bucket.name;
const sourceUri = ["https://s3.amazonaws.com", sourceBucket, filepath]
.join('/');
const transcriptBucket = process.env.TRANSCRIPT_DESTINATION_S3BUCKET_NAME;
const transcriptEmail = process.env.TRANSCRIPT_DESTINATION_EMAIL;
const transcriptName = filepath
.replace(/\//g, "...")
.replace(/[^0-9a-zA-Z._-]+/g, "");
//add random job number, AWS doesn't allow for matching job names.
const getRandomInt = (ceiling) => Math.floor(Math.random() * ceiling);
const randomizedJobName = transcriptName + '.' + getRandomInt(999999999);
const vocab_param = {
LanguageCode: 'en-US',
Phrases: [],
VocabularyName: ''
}
const scribe_param = {
LanguageCode: "en-US",
Media: {
MediaFileUri: sourceUri,
},
MediaFormat: extension,
TranscriptionJobName: randomizedJobName,
OutputBucketName: transcriptBucket,
Settings: {
ShowSpeakerLabels: true,
MaxSpeakerLabels: process.env.NUMBER_OF_SPEAKERS,
VocabularyName: process.env.VOCABULARY_NAME
}
};
console.log(JSON.stringify(scribe_param));
return Scribe.startTranscriptionJob(scribe_param).promise()
.then(data => {
console.log(JSON.stringify(data));
})
.catch(error => {
console.log(JSON.stringify(error));
});
}