-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
60 lines (57 loc) · 1.5 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
#!/usr/bin/env node
const eSpeakNg = require('./lib/espeak-ng')
const optMap = {
voice: '-v',
amplitude: '-a',
wordGap: '-g',
capital: '-k',
lineLength: '-l',
pitch: '-p',
speed: '-s',
encoding: '-b',
hasTags: '-m',
noFinalPause: '-z',
punct: '--punct',
}
module.exports = function () {
let parsedArguments = [arguments[0], '-w wav.wav']
if (arguments[1] && arguments[1] instanceof Object) {
for (let prop in arguments[1]) {
if (!optMap[prop]) {
throw new Error(`invalid option ${prop}`)
}
if (typeof arguments[1][prop] == 'boolean') {
if (arguments[1][prop] === true) {
parsedArguments.push(optMap[prop])
}
continue
}
if (optMap[prop].startsWith('--')) {
if (arguments[1][prop]) {
parsedArguments.push(optMap[prop] + '="' + arguments[1][prop].replace('"', '\\"') + '"')
}
continue
}
parsedArguments.push(optMap[prop])
parsedArguments.push(arguments[1][prop])
}
} else {
parsedArguments = parsedArguments.concat(Array.from(arguments).slice(1))
}
return new Promise((resolve) => {
let Module = {
arguments: parsedArguments,
postRun: function () {
Module.FS.unmount('/usr/share')
resolve(new Uint8Array(Module.FS.root.contents['wav.wav'].contents))
}
}
eSpeakNg(Module)
})
}
if (require.main === module) {
(async () => {
let out = await module.exports(...process.argv.slice(2))
process.stdout.write(out)
})()
}