Commit 62b67495 authored by Navodya Pasqual's avatar Navodya Pasqual

Added voice output using amazon polly

parent 6fe22cd6
This diff is collapsed.
......@@ -12,20 +12,21 @@
"author": "",
"license": "ISC",
"dependencies": {
"actions-on-google": "^2.6.0",
"aws-sdk": "^2.1231.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"config": "^3.3.6",
"cors": "^2.8.5",
"dialogflow": "^0.10.2",
"dialogflow-fulfillment": "^0.6.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"mongoose": "^6.0.8",
"nodeJS": "^1.0.0",
"nodemon": "^2.0.13",
"actions-on-google": "^2.6.0",
"dialogflow": "^0.10.2",
"dialogflow-fulfillment": "^0.6.1"
"nodemon": "^2.0.13"
},
"devDependencies": {
"formidable": "^1.2.2",
......
const express = require('express');
const router = express.Router();
const dialogflow = require('dialogflow');
const AWS = require('aws-sdk');
fs = require('fs');
const config = require('../../config/digitalHuman/config');
......@@ -8,7 +9,16 @@ const projectId = config.googleProjectID
const sessionId = config.dialogFlowSessionID
const languageCode = config.dialogFlowSessionLanguageCode
const credentials={
// Credentials for Amazon Polly
const Polly = new AWS.Polly({
region: 'us-west-2',
accessKeyId: 'AKIAWJCX4TSYJQYA5O5H',
secretAccessKey: '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'
})
// Credentials for dialogflow
const credentials = {
client_email: config.googleClientEmail,
private_key: config.googlePrivateKey
}
......@@ -39,14 +49,38 @@ router.post('/textQuery', async (req, res) => {
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
fs.writeFile('output.txt', result.fulfillmentText , function (err,data) {
// voice initialization
const voice = {
Text: result.fulfillmentText,
OutputFormat: "mp3",
VoiceId: "Joanna"
}
// Generating wav output
Polly.synthesizeSpeech(voice, (err, data) => {
if (err) {
console.log(err)
return
}
if (data.AudioStream instanceof Buffer) {
fs.writeFile('voice_output.wav', data.AudioStream, (err) => {
if (err) {
console.error(err)
return
}
console.log('Respond converted into wav file')
})
}
}
)
//output as a text
fs.writeFile('output.txt', result.fulfillmentText, function (err, data) {
if (err) {
return console.log(err);
}
console.log(data);
console.log('Respond converted into text file')
});
res.send(result)
})
......@@ -73,6 +107,7 @@ router.post('/eventQuery', async (req, res) => {
console.log(` Response: ${result.fulfillmentText}`);
res.send(result)
})
}
)
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment