Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-066
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
2022-066
2022-066
Commits
62b67495
Commit
62b67495
authored
Oct 09, 2022
by
Navodya Pasqual
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added voice output using amazon polly
parent
6fe22cd6
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
580 additions
and
178 deletions
+580
-178
Backend/Node/package-lock.json
Backend/Node/package-lock.json
+532
-166
Backend/Node/package.json
Backend/Node/package.json
+5
-4
Backend/Node/src/routes/digitalHuman/dialogFlow.js
Backend/Node/src/routes/digitalHuman/dialogFlow.js
+43
-8
Backend/Node/voice_output.wav
Backend/Node/voice_output.wav
+0
-0
No files found.
Backend/Node/package-lock.json
View file @
62b67495
This diff is collapsed.
Click to expand it.
Backend/Node/package.json
View file @
62b67495
...
...
@@ -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"
,
...
...
Backend/Node/src/routes/digitalHuman/dialogFlow.js
View file @
62b67495
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
:
'
Wg6zHy15QjZv4jHx2+YokuzWDLzW975hbljcVhab
'
})
// 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
)
{
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
)
})
...
...
@@ -71,8 +105,9 @@ router.post('/eventQuery', async (req, res) => {
const
result
=
responses
[
0
].
queryResult
;
console
.
log
(
` Query:
${
result
.
queryText
}
`
);
console
.
log
(
` Response:
${
result
.
fulfillmentText
}
`
);
res
.
send
(
result
)
})
}
)
module
.
exports
=
router
;
Backend/Node/voice_output.wav
0 → 100644
View file @
62b67495
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment