aiTextToSpeech
parent
101e1a2749
commit
0a78f89fa9
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iimttapi",
|
||||
"version": "0.0.1",
|
||||
"version": "1.0.0",
|
||||
"description": "Create a Node.js app for building production-ready RESTful APIs using Express, by running one command",
|
||||
"bin": "bin/createNodejsApp.js",
|
||||
"main": "src/index.js",
|
||||
|
@ -24,7 +24,7 @@
|
|||
"docker:dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up",
|
||||
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
},
|
||||
"keywords": [
|
||||
"node",
|
||||
"node.js",
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
const aiTextToSpeech = async (req, res) => {
|
||||
const AWS = require('aws-sdk');
|
||||
AWS.config.update({
|
||||
region: 'ap-south-1',
|
||||
accessKeyId: process.env.AWS_polly2_ACCESS_KEY_ID,
|
||||
secretAccessKey: process.env.AWS_polly2_SECRET_ACCESS_KEY,
|
||||
});
|
||||
|
||||
const polly = new AWS.Polly();
|
||||
|
||||
const voiceIdMap = {
|
||||
"Ava": "Ivy",
|
||||
"Monstero": "Justin",
|
||||
"Dax": "Kevin",
|
||||
"Kai": "Daniele",
|
||||
"Yara": "Sally"
|
||||
};
|
||||
|
||||
const { text, voiceId: frontendVoiceId } = req.body;
|
||||
|
||||
if (!text || !frontendVoiceId) {
|
||||
return res.status(400).json({ error: 'Text and voiceId are required' });
|
||||
}
|
||||
|
||||
const pollyVoiceId = voiceIdMap[frontendVoiceId];
|
||||
if (!pollyVoiceId) {
|
||||
return res.status(400).json({ error: 'Invalid voiceId provided' });
|
||||
}
|
||||
|
||||
const params = {
|
||||
Text: text,
|
||||
OutputFormat: 'mp3',
|
||||
VoiceId: pollyVoiceId,
|
||||
};
|
||||
|
||||
try {
|
||||
const data = await polly.synthesizeSpeech(params).promise();
|
||||
const audioBuffer = data.AudioStream;
|
||||
|
||||
res.json({
|
||||
audioContent: audioBuffer.toString('base64'),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error generating speech:', error);
|
||||
res.status(500).json({ error: 'Error generating speech' });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = aiTextToSpeech;
|
|
@ -28,6 +28,7 @@ const aiFeedbackActionParent = require("../api/aiFeedbackActionParent");
|
|||
const aiFollowupQuestion = require("../api/aiFollowupQuestion");
|
||||
const aiMarkDrawing = require("../api/aiMarkDrawing");
|
||||
const aiFeedbackOnReportWithFollowup = require("../api/aiFeedbackOnReportWithFollowup");
|
||||
const aiTextToSpeech = require("../api/aiTextToSpeech");
|
||||
|
||||
|
||||
|
||||
|
@ -172,6 +173,13 @@ router.get("/ping", (req, res) => {
|
|||
router.post("/aiMarkDrawing", (req, res) => {
|
||||
aiMarkDrawing(req, res);
|
||||
});
|
||||
|
||||
// AI to provide star for drawing.
|
||||
router.post("/aiTextToSpeech", (req, res) => {
|
||||
aiTextToSpeech(req, res);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Reference in New Issue