· 4 years ago · Dec 18, 2020, 04:30 AM
1 case "acapela2": {
2 var buffers = [];
3 var getNonce = https.request({
4 hostname: "acapelavoices.acapela-group.com",
5 path: "/index/getnonce",
6 method: "POST",
7 headers: {
8 "Content-Type": "application/x-www-form-urlencoded",
9 },
10 },
11 (r) => {
12 r.on("data", (b) => buffers.push(b));
13 r.on("end", () => {
14 var json = JSON.parse(Buffer.concat(buffers));
15 const beg = json.indexOf("nonce\":\"");
16 const end = json.indexOf("\"", beg);
17 const sub = json.subarray(beg, end).toString();
18 console.log("Nonce:");
19 console.log(sub);
20 });
21 }
22 );
23 var q = qs.encode({
24 req_voice: voice.arg,
25 cl_pwd: "",
26 cl_vers: "1-30",
27 req_echo: "ON",
28 cl_login: "AcapelaGroup",
29 req_comment: "{\"nonce\":" + getNonce + "\"user\":\"" + acapelaEmail + "@gmail.com\"}",
30 req_text: text,
31 cl_env: "ACAPELA_VOICES",
32 prot_vers: 2,
33 cl_app: "AcapelaGroup_WebDemo_Android",
34 });
35 var req = https.request({
36 hostname: "acapela-group.com",
37 port: "8080",
38 path: "/webservices/1-34-01-Mobility/Synthesizer",
39 method: "POST",
40 headers: {
41 "Content-Type": "application/x-www-form-urlencoded",
42 },
43 },
44 (r) => {
45 var buffers = [];
46 r.on("data", (d) => buffers.push(d));
47 r.on("end", () => {
48 const html = Buffer.concat(buffers);
49 const beg = html.indexOf("&snd_url=") + 9;
50 const end = html.indexOf("&", beg);
51 const sub = html.subarray(beg + 4, end).toString();
52 if (!sub.startsWith("://")) return rej();
53 console.log("Successfully retrieved MP3 stream:");
54 console.log(sub);
55 get(buffers.toString()).then(res).catch(rej);
56 /*get(`https${sub}`).then(res).catch(rej);*/
57 });
58 r.on("error", rej);
59 }
60 );
61 req.end(q);
62 break;
63 }