-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (30 loc) · 895 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (30 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 5000;
const getText = require('./SpeechToText/speech');
const getSpeech = require('./TextToSpeech/text');
const cors = require('cors');
const path = require('path');
const jsonParser = bodyParser.json();
app.use(cors());
app.get('/speechToText', async (req, res) => {
try {
const text = await getText();
res.send({ text });
} catch (e) {
res.send(e);
}
});
app.post('/textToSpeech', jsonParser, async (req, res) => {
const { text } = req.body;
const speechBuffer = await getSpeech(text);
console.log({ speechBuffer });
res.send({ speechBuffer });
});
app.get('/audio.mp3', (req, res) => {
res.sendFile(path.join(__dirname, './', 'output.mp3'));
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});