generated from Alex-star225/GoAnimate-2012-Online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
213 lines (210 loc) · 6.36 KB
/
load.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
const loadPost = require('../request/post_body');
const mp3Duration = require('mp3-duration');
const voices = require('./info').voices;
const asset = require('../asset/main');
const get = require('../request/get');
const qs = require('querystring');
const https = require('https');
const http = require('http');
function processVoice(voiceName, text) {
return new Promise((res, rej) => {
const voice = voices[voiceName];
switch (voice.source) {
case 'polly': {
var q = qs.encode({
texttype: "text",
text: text,
fallbackLanguage: "0",
voice: voice.arg,
rate: "0",
whisper: "false",
soft: "false",
wordbreakms: "0",
volume: "0",
marksid: "ca6108ea-0a10-476d-9c87-b32508002c80",
d: "true",
format: "mp3",
});
https.get({
host: 'talkify.net',
path: `/api/internal/speech?${q}`,
method: 'GET',
headers: {
Referer: 'https://talkify.net/text-to-speech',
Origin: 'https://talkify.net',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
},
}, r => {
var buffers = [];
r.on('data', d => buffers.push(d));
r.on('end', () => res(Buffer.concat(buffers)));
r.on('error', rej);
});
break;
}
case 'cepstral':
case 'voiceforge': {
https.get('https://www.voiceforge.com/demo', r => {
const cookie = r.headers['set-cookie'];
var q = qs.encode({
voice: voice.arg,
voiceText: text,
});
var buffers = [];
var req = https.get({
host: 'www.voiceforge.com',
path: `/demos/createAudio.php?${q}`,
headers: { Cookie: cookie },
method: 'GET',
}, r => {
r.on('data', b => buffers.push(b));
r.on('end', () => {
const html = Buffer.concat(buffers);
const beg = html.indexOf('id="mp3Source" src="') + 20;
const end = html.indexOf('"', beg);
const loc = html.subarray(beg, end).toString();
get(`https://www.voiceforge.com${loc}`).then(res).catch(rej);
})
});
});
break;
}
case 'vocalware': {
var q = qs.encode({
EID: voice.arg[0],
LID: voice.arg[1],
VID: voice.arg[2],
TXT: text,
IS_UTF8: 1,
HTTP_ERR: 1,
ACC: 3314795,
API: 2292376,
vwApiVersion: 2,
CB: 'vw_mc.vwCallback',
});
var req = https.get({
host: 'cache-a.oddcast.com',
path: `/tts/gen.php?${q}`,
method: 'GET',
headers: {
Referer: 'https://www.vocalware.com/index/demo',
Origin: 'https://www.vocalware.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
},
}, r => {
var buffers = [];
r.on('data', d => buffers.push(d));
r.on('end', () => res(Buffer.concat(buffers)));
r.on('error', rej);
});
break;
}
case 'voicery': {
var q = qs.encode({
text: text,
speaker: voice.arg,
ssml: text.includes('<'),
//style: 'default',
});
https.get({
host: 'www.voicery.com',
path: `/api/generate?${q}`,
}, r => {
var buffers = [];
r.on('data', d => buffers.push(d));
r.on('end', () => res(Buffer.concat(buffers)));
r.on('error', rej);
});
break;
}
case 'watson': {
var q = qs.encode({
text: text,
voice: voice.arg,
download: true,
accept: "audio/mp3",
});
console.log(https.get({
host: 'text-to-speech-demo.ng.bluemix.net',
path: `/api/v3/synthesize?${q}`,
}, r => {
var buffers = [];
r.on('data', d => buffers.push(d));
r.on('end', () => res(Buffer.concat(buffers)));
r.on('error', rej);
}));
break;
}
case 'acapela': {
var q = qs.encode({
cl_login: "VAAS_MKT",
req_snd_type: "",
req_voice: voice.arg,
cl_app: "seriousbusiness",
req_text: text,
cl_pwd: "M5Awq9xu",
});
console.log(http.get({
host: 'vaassl3.acapela-group.com',
path: `/Services/AcapelaTV/Synthesizer?${q}`,
method: 'GET',
}, r => {
var buffers = [];
r.on('data', d => buffers.push(d));
r.on('end', () => {
const html = Buffer.concat(buffers);
const beg = html.indexOf('&snd_url=') + 9;
const end = html.indexOf('&', beg);
const loc = `https${html.subarray(beg+4, end).toString()}`;
get(loc).then(res).catch(rej);
})
r.on('error', rej);
}));
break;
}
case 'readloud': {
const req = https.request({
host: 'readloud.net',
path: voice.arg,
method: 'POST',
port: '443',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}, r => {
var buffers = [];
r.on('data', d => buffers.push(d));
r.on('end', () => {
const html = Buffer.concat(buffers);
const beg = html.indexOf('/tmp/');
const end = html.indexOf('.mp3', beg) + 4;
const sub = html.subarray(beg, end).toString();
const loc = `https://readloud.net${sub}`;
get(loc).then(res).catch(rej);
});
r.on('error', rej);
});
req.write(qs.encode({
but1: text,
but: 'Enviar',
}));
req.end();
break;
}
}
});
}
module.exports = function (req, res, url) {
if (req.method != 'POST' || url.path != '/goapi/convertTextToSoundAsset/') return;
loadPost(req, res).then(data => {
processVoice(data.voice, data.text).then(buffer => {
mp3Duration(buffer, (e, duration) => {
if (e || !duration) return res.end(1 + process.env.FAILURE_XML);
const title = `[${voices[data.voice].desc}] ${data.text}`;
const id = asset.saveLocal(buffer, data.presaveId, '-tts.mp3');
res.end(`0<response><asset><id>${id}</id><enc_asset_id>${id}</enc_asset_id><type>sound</type><subtype>tts</subtype><title>${title}</title><published>0</published><tags></tags><duration>${1e3 * duration}</duration><downloadtype>progressive</downloadtype><file>${id}</file></asset></response>`)
});
});
});
return true;
}