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 @@ ...@@ -12,20 +12,21 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"actions-on-google": "^2.6.0",
"aws-sdk": "^2.1231.0",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"config": "^3.3.6", "config": "^3.3.6",
"cors": "^2.8.5", "cors": "^2.8.5",
"dialogflow": "^0.10.2",
"dialogflow-fulfillment": "^0.6.1",
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"express": "^4.17.1", "express": "^4.17.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mongoose": "^6.0.8", "mongoose": "^6.0.8",
"nodeJS": "^1.0.0", "nodeJS": "^1.0.0",
"nodemon": "^2.0.13", "nodemon": "^2.0.13"
"actions-on-google": "^2.6.0",
"dialogflow": "^0.10.2",
"dialogflow-fulfillment": "^0.6.1"
}, },
"devDependencies": { "devDependencies": {
"formidable": "^1.2.2", "formidable": "^1.2.2",
......
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const dialogflow = require('dialogflow'); const dialogflow = require('dialogflow');
const AWS = require('aws-sdk');
fs = require('fs'); fs = require('fs');
const config = require('../../config/digitalHuman/config'); const config = require('../../config/digitalHuman/config');
...@@ -8,7 +9,16 @@ const projectId = config.googleProjectID ...@@ -8,7 +9,16 @@ const projectId = config.googleProjectID
const sessionId = config.dialogFlowSessionID const sessionId = config.dialogFlowSessionID
const languageCode = config.dialogFlowSessionLanguageCode 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, client_email: config.googleClientEmail,
private_key: config.googlePrivateKey private_key: config.googlePrivateKey
} }
...@@ -39,14 +49,38 @@ router.post('/textQuery', async (req, res) => { ...@@ -39,14 +49,38 @@ router.post('/textQuery', async (req, res) => {
console.log(` Query: ${result.queryText}`); console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`); 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) { if (err) {
return console.log(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')
})
} }
console.log(data); }
}); )
//output as a text
fs.writeFile('output.txt', result.fulfillmentText, function (err, data) {
if (err) {
return console.log(err);
}
console.log('Respond converted into text file')
});
res.send(result) res.send(result)
}) })
...@@ -71,8 +105,9 @@ router.post('/eventQuery', async (req, res) => { ...@@ -71,8 +105,9 @@ router.post('/eventQuery', async (req, res) => {
const result = responses[0].queryResult; const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`); console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`); console.log(` Response: ${result.fulfillmentText}`);
res.send(result) res.send(result)
}) }
)
module.exports = router; 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