-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT2M.js
More file actions
83 lines (66 loc) · 2.02 KB
/
Copy pathT2M.js
File metadata and controls
83 lines (66 loc) · 2.02 KB
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
"use strict";
let fs = require("fs");
let exec = require("child_process").exec;
class T2M {
constructor() {
this.init();
}
getRequestOptions(body) {
return {
title: body.Title,
text: body.Text,
preciseSearch: body.PreciseSearch,
optionsDropDown: body.OptionsDropDown
};
}
createSoundFile(req, callback) {
if (req.text.length < 1) {
return callback("No Text provided", null);
}
let that = this;
this._createFile(req, (error, textpath) => {
if (error !== null) {
return callback("Error creating file: " + error, null);
}
that._executeT2M(textpath, req, (error, soundpath) => {
if (error !== null) {
return callback("Error executing T2M: " + error, null);
}
return callback(null, soundpath);
});
});
}
_createFile(req, callback) {
let fileName = req.title.replace(/ /g, "") + ".txt";
let path = "public/textfiles/" + fileName;
fs.writeFile(path, req.text, error => {
if (error) {
return callback("Cannot create File. FS Error: " + error, null);
}
return callback(null, "public/textfiles/" + fileName);
});
}
_executeT2M(path, req, callback) {
//articleFile outputFile -db databaseFile -[output] [mp3 wav midi play ] -[precise] -db databaseFile
let textpath = path.replace(/ /g, "") + " ";
let exportPath = "public/soundfiles/";
let filnename = req.title.replace(/ /g, "") + ".wav";
let database = " wordsDB.csv";
let output = " -o wav";
let command = textpath + exportPath + filnename + database + output;
console.log(command);
if (req.preciseSearch) {
command = command + " -precise";
}
exec("java -jar t2m.jar " + command, (error, stdout, stderr) => {
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
if (error !== null) {
return callback(error, null);
}
return callback(null, "soundfiles/" + filnename);
});
}
init() {}
}
module.exports = T2M;