-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (70 loc) · 2.56 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require("fs")
const { exec } = require('child_process')
const express = require("express");
const app = express();
const kLoger = require("./kloger");
const loger = new kLoger({
info: true,
debug: true,
error: true
})
// エラーハンドリング
process.on("uncaughtException", function(err) {
loger.error(err)
})
const server = app.listen(21454,'0.0.0.0', () => {
loger.info("OpenJtalk HTTP API bind on "+server.address().address+":"+ + server.address().port);
});
app.get("/synthesize", async (req, res, next) => {
let text = req.query.text
let type = req.query.type
let speed = req.query.speed
let pitch = req.query.pitch
if(!text){
res.json({
status:"error"
})
return
}
if(!type){
type = "./openjtalk/mei/mei_normal.htsvoice"
}else if(type == "mei_normal"){
type = "./openjtalk/mei/mei_normal.htsvoice"
}else if(type == "mei_sad"){
type = "./openjtalk/mei/mei_sad.htsvoice"
}else if(type == "mei_angry"){
type = "./openjtalk/mei/mei_angry.htsvoice"
}else if(type == "mei_bashful"){
type = "./openjtalk/mei/mei_bashful.htsvoice"
}else if(type == "mei_happy"){
type = "./openjtalk/mei/mei_happy.htsvoice"
}else if(type == "takumi_normal"){
type = "./openjtalk/mei/takumi_normal.htsvoice"
}else if(type == "takumi_sad"){
type = "./openjtalk/mei/takumi_sad.htsvoice"
}else if(type == "takumi_angry"){
type = "./openjtalk/mei/takumi_angry.htsvoice"
}else if(type == "takumi_bashful"){
type = "./openjtalk/mei/takumi_bashful.htsvoice"
}else if(type == "takumi_happy"){
type = "./openjtalk/mei/takumi_happy.htsvoice"
}else{
type = "./openjtalk/mei/mei_normal.htsvoice"
}
if(!speed){speed = 0.8}
if(!pitch){pitch = -0.5}
const inTEMP = "./temp/"+Math.floor(Math.random() * ( 999999 - 100000 ) + 100000)
const outTEMP = "./temp/"+Math.floor(Math.random() * ( 999999 - 100000 ) + 100000)
fs.writeFileSync(inTEMP,text)
const openjtalkCMD = `./openjtalk/open_jtalk -x ./openjtalk/dic -g 10 -m ${type} -r ${speed} -fm ${pitch} -ow ${outTEMP} ${inTEMP}`
exec(openjtalkCMD, (err, stdout, stderr) => {
if (err) {
loger.error(err);
return;
}
loger.debug(`audio query => ${text} : ${type} : ${speed} : ${pitch}`);
res.send(fs.readFileSync(outTEMP));
fs.unlinkSync(inTEMP);
fs.unlinkSync(outTEMP);
})
});