-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (82 loc) · 2.55 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const providergooglecreate = require("./lib/sample-google");
const providermicrosoftcreate = require("./lib/sample-ms");
const statparsercreate = require("./stats");
const comparison = require("./lib/transcript_comparison");
const properties = require("./properties");
const transcripts = require("./transcripts");
const path = require("path");
var results = [];
var result = {
google: {
transcription: ""
},
microsoft: {
transcription: ""
}
};
var original = "";
(async function() {
var google = providergooglecreate(properties.providers.google);
var microsoft = providermicrosoftcreate(properties.providers.microsoft);
try {
const dir = await require("fs").promises.opendir(properties.resources);
var i = 0;
for await (const dirent of dir) {
// read resources directory to get the list of all files
console.log(dirent.name);
if (i < properties.files) {
// process no more than number of properties.files
for (element in transcripts) {
//and only if the file is in transcript array
// and there is no miss flag set true
if (
dirent.name === transcripts[element].file &&
(transcripts[element].miss == "undefined" ||
!transcripts[element].miss)
) {
transcripts[element].file = path.resolve(dir.path, dirent.name);
result = {
google: {
transcription: ""
},
microsoft: {
transcription: ""
}
};
original = transcripts[element].transcript;
var audio = transcripts[element].file;
result.google.transcription = await google.run(
transcripts[element],
update_result
);
result.microsoft.transcription = await microsoft.run(
transcripts[element],
update_result
);
results.push({
audio: audio,
original: transcripts[element].transcript,
result: result
});
original = "";
// update counter to make sure to stop
i++;
}
}
}
}
//console.log(JSON.stringify(results, 2));
var s = statparsercreate();
s.parse(results);
} catch (err) {
console.log(err);
}
})();
function update_result(transcript, provider) {
result[provider].transcription = transcript;
result[provider].match = comparison(
transcript,
original,
properties.tolowercase
);
}