-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_audio.js
80 lines (74 loc) · 1.83 KB
/
display_audio.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
function getAudioDiv(i, fileNames) {
console.log("name=" + i);
const audioDiv = `<div>
<table>
<h3>Excerpt ${i}</h3>
<tr>
<td>Original:</td>
<td>
<audio controls>
>
<source src="${fileNames[0]}" />
</audio>
</td>
</tr>
<tr>
<td>Model 1:</td>
<td>
<audio controls>
>
<source src="${fileNames[1]}" />
</audio>
</td>
</tr>
<tr>
<td>Model 2:</td>
<td>
<audio controls>
>
<source src="${fileNames[2]}" />
</audio>
</td>
</tr>
<tr>
<td>Model 3:</td>
<td>
<audio controls>
>
<source src="${fileNames[3]}" />
</audio>
</td>
</tr>
</table>
</div>
<br />
`;
return audioDiv;
}
function getRandomNumbers(low, high, count) {
const numbers = [...Array(10).keys()].slice(low, high);
let selectedNumbers = [];
for (let i = 0; i < count; i++) {
const randomIndex = Math.floor(Math.random() * numbers.length);
const selectedNumber = numbers.splice(randomIndex, 1)[0];
selectedNumbers.push(selectedNumber);
}
return selectedNumbers;
}
let QUESTION_COUNT = 2;
let fileNames;
fetch("file_names.json")
.then((res) => res.json())
.then((data) => {
fileNames = data;
// console.log(fileNames);
numbersSelected = getRandomNumbers(0, 9, QUESTION_COUNT);
console.log(numbersSelected);
for (let i = 0; i < QUESTION_COUNT; i++) {
const div = getAudioDiv(
numbersSelected[i] + 1,
fileNames[numbersSelected[i]]
);
document.getElementById("audio-container").innerHTML += div;
}
});