Thamaraikannan commited on
Commit
b355e83
·
verified ·
1 Parent(s): d255781

Update routes/index.js

Browse files
Files changed (1) hide show
  1. routes/index.js +17 -15
routes/index.js CHANGED
@@ -1,24 +1,26 @@
1
  var express = require('express');
2
  var router = express.Router();
3
- var textToSpeech = require('../helpers/tts');
4
-
5
- /* POST /talk */
6
- router.post('/talk', function(req, res, next) {
7
- textToSpeech(req.body.text, req.body.voice)
8
- .then(result => {
9
- res.json(result);
10
- })
11
- .catch(err => {
12
- res.json({});
13
- });
14
- });
15
 
 
 
 
 
16
 
 
 
 
17
 
 
 
 
 
18
 
19
- /* GET home page. */
20
- router.get('/', function(req, res, next) {
21
- res.render('index', { title: 'Express' });
 
 
22
  });
23
 
24
  module.exports = router;
 
1
  var express = require('express');
2
  var router = express.Router();
3
+ var textToSpeech = require('../helpers/tts'); // Ensure the helper function is correctly imported
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ // POST /talk - Converts text to speech
6
+ router.post('/talk', async function (req, res) {
7
+ try {
8
+ const { text, voice } = req.body;
9
 
10
+ if (!text) {
11
+ return res.status(400).json({ error: "Text is required" });
12
+ }
13
 
14
+ const result = await textToSpeech(text, voice);
15
+
16
+ console.log("Blend Shapes:", result.blendData); // Logs blend shapes
17
+ console.log("Generated File:", result.filename); // Logs output filename
18
 
19
+ res.json(result);
20
+ } catch (err) {
21
+ console.error("Error in TTS:", err);
22
+ res.status(500).json({ error: err.message || "Internal Server Error" });
23
+ }
24
  });
25
 
26
  module.exports = router;