-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload-phrases-xml.js
39 lines (32 loc) · 1.35 KB
/
load-phrases-xml.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
function parseFile(file){
const parser = require('fast-xml-parser');
const allPhrases = require('fs').readFileSync(file, {encoding: 'utf8'});
function parseAttribute (val, attrName) {
if(attrName="filename") return val.replace('.wav','');
else return val;
}
var jsonObj = parser.parse(allPhrases, {ignoreAttributes :false, attributeNamePrefix:'', attrValueProcessor: parseAttribute });
//un-nest to our actual data -- assuming: <language><SOME-LANGUAGE, e.g. en, es>
jsonObj = jsonObj.language;
const language = Object.keys(jsonObj);
jsonObj=jsonObj[language[0]];
//remove the unnecessary .prompt in every section
var keys = Object.keys(jsonObj);
console.log(keys);
keys.forEach(function(value){
jsonObj[value] = jsonObj[value].prompt;
})
keys.forEach(function(value){//if we specified a "polly" attribute, then overwrite the phrase.
jsonObj[value].forEach(function(val,index){
if(val.polly) {
console.log('overwriting standard text with polly specific text:',jsonObj[value][index]['phrase'],"=>",val.polly);
jsonObj[value][index]['phrase']=val.polly;
}
})
})
//remove where there's at type -- music or tone.
jsonObj.conference = jsonObj.conference.filter(data => !data.type);
//console.log(require('util').inspect(jsonObj, {showHidden: false, depth: null, colors:true}))
return jsonObj;
}
module.exports = parseFile;