forked from junzew/HanTTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (36 loc) · 1.23 KB
/
app.js
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
37
38
39
40
41
const express = require('express')
var bodyParser = require('body-parser');
const spawn = require('child_process').spawn;
var fs = require('fs');
const app = express()
app.use(express.static('public'))
app.use('/audio', express.static('audio'))
app.use(bodyParser.json()); // for parsing application/json
app.listen(process.env.PORT || 3000, function () {
console.log('app listening on port 3000')
var dir = './audio';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
console.log("created directory ./audio")
}
});
app.post("/", function(req, res) {
var text = req.body.text;
console.log(text)
args = ["./main.py", 'synthesize', '--text', text, '--src', "./syllables/", '--dst', "./audio/"]
var process = spawn('python', args);
var output = "";
process.stdout.on('data', function(data){ output += data });
process.stderr.on('data', function(data){ console.error(`stderr: ${data}`); });
process.on("close", function(code) {
if (code !== 0) {
return res.send(`child process exited with code ${code}`)
}
console.log(output)
console.log("sending response")
res.send('<audio src="./audio/generated.wav" controls="true"></audio>')
});
});
app.get("/file", function(req, res) {
res.download("./audio/generated.wav")
});