-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
38 lines (31 loc) · 906 Bytes
/
handler.js
File metadata and controls
38 lines (31 loc) · 906 Bytes
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
'use strict';
let AWS = require("aws-sdk");
var polly = new AWS.Polly({apiVersion: '2016-06-10'});
module.exports.speak = (event, context, callback) => {
const requestBody = JSON.parse(event.body);
const pollyParams = {
OutputFormat: "mp3",
Text: requestBody.text,
VoiceId: requestBody.voice,
TextType: "ssml"
};
// 1. Getting the audio stream for the text that user entered
polly.synthesizeSpeech(pollyParams)
.on("success", function (response) {
let data = response.data;
let audioStream = data.AudioStream;
let base64audio = audioStream.toString('base64');
let result = {say: base64audio};
callback(null, {
statusCode: 200,
body: JSON.stringify(result)
});
})
.on("error", function (err) {
callback(null, {
statusCode: 500,
body: JSON.stringify(err)
});
})
.send();
};