2021-01-13 03:18:19 +00:00
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const app = require('express')()
|
|
|
|
const fs = require('fs')
|
|
|
|
const tmp = require('tmp')
|
|
|
|
const exec = require('child_process').exec;
|
|
|
|
|
|
|
|
const eSpeakExecutable = process.platform === "win32" ? `"C:\\Program Files\\eSpeak NG\\espeak-ng.exe"` : `/usr/bin/espeak-ng`
|
|
|
|
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
app.post('/get', (req, res, next) => {
|
|
|
|
tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
|
|
|
|
if (err) throw err;
|
|
|
|
|
2021-01-13 06:29:05 +00:00
|
|
|
fs.writeFile(path, req.body.sourceText.replace(/\n/gi,",\n"), {encoding: "utf-8"}, ()=> {
|
2021-01-13 03:32:59 +00:00
|
|
|
exec(`${eSpeakExecutable} -v"${req.body.selectedLanguage}" -q -f "${path}" --ipa`, ((error, stdout, stderr) => {
|
2021-01-13 06:29:05 +00:00
|
|
|
res.json({out: stdout, stderr})
|
|
|
|
cleanupCallback()
|
2021-01-13 03:18:19 +00:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = app
|
|
|
|
|