-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-voices-list.js
36 lines (29 loc) · 1001 Bytes
/
generate-voices-list.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
const fs = require('fs');
const path = require('path');
const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat({
name: file,
path: path.join(dir, file),
//size: fs.statSync(path.join(dir, file)).size
});
});
return filelist;
}
const files = walkSync('wave-tables');
const voices = [];
files.forEach(({ name, path }) => {
console.log("Found wavetable for " + name);
let tableData = JSON.parse(
fs.readFileSync(path, 'utf8')
.replace(/[\n\t]/g, "")
.replace(/\'/g, '"')
.replace(/\,\]/g, ']')
.replace(/\,\}/g, '}')
)
voices.push(name)
fs.writeFileSync(`voices/${name}.json`, JSON.stringify(tableData));
})
fs.writeFileSync(`voices/index.json`, JSON.stringify(voices));