-
Notifications
You must be signed in to change notification settings - Fork 0
/
evs.html
118 lines (97 loc) · 3.43 KB
/
evs.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<html>
<head>
<title>EduVideoScript</title>
<meta charset="utf-8"/>
<script type="text/javascript" src="voicefunctions.js"></script>
<script type="text/javascript" src="ytfunctions.js"></script>
<script type="text/javascript" src="evs.js"></script>
<script type="text/javascript" src="commands.js"></script>
<script type="text/javascript">
"use strict";
const RESPONSIVE_VOICE_API_KEY = "S09NiLlR";
let evsi;
let userCommands = [
["say",{"text":"no program loaded"}]
];
let EVS_OUTPUT, START_BUTTON, STOP_BUTTON, SKIP_SELECT;
function setCommandData(commands) {
userCommands = commands;
SKIP_SELECT.innerHTML = "";
for (let i = 0; i < commands.length; i++) {
let tx;
if (commands[i][0] == "label") {
tx = "Label: " + commands[i][1].label;
} else {
tx = JSON.stringify(commands[i]).substring(0,32);
}
let op = document.createElement("option");
op.value = i;
op.appendChild(document.createTextNode(tx));
SKIP_SELECT.appendChild(op);
}
resetEVS();
}
function setInfoOutputText(text) {
EVS_OUTPUT.innerHTML = "";
EVS_OUTPUT.appendChild(document.createTextNode(text));
}
onload = async function() {
EVS_OUTPUT = document.getElementById("evsContent");
START_BUTTON = document.getElementById("startButton");
STOP_BUTTON = document.getElementById("stopButton");
SKIP_SELECT = document.getElementById("skipSelect");
setCommandData(userCommands);//prepare skip select for default program
setInfoOutputText("loading YouTube IFrame API...");
await loadYouTubeIframeAPI();
setInfoOutputText("loading responsive Voice API...");
await loadResponsiveVoiceAPI(RESPONSIVE_VOICE_API_KEY);
evsi = new EVSInstance();
setInfoOutputText("ready!");
START_BUTTON.disabled = false;
SKIP_SELECT.disabled = false;
}
function resetEVS() {
EVS_OUTPUT.innerHTML = "";
let ytpd = document.createElement("div");
ytpd.id = "ytplayer";
EVS_OUTPUT.appendChild(ytpd);
evsi = new EVSInstance();
}
async function startMe(startIndex) {
let commands = EVSCommandType.parseCommands(COMMAND_TYPES,userCommands);
if (startIndex !== undefined) commands = EVSInstance.createCommandsSkipFrom(commands,startIndex);
resetEVS();
START_BUTTON.disabled = true;
STOP_BUTTON.disabled = false;
await evsi.runCommands(commands);
START_BUTTON.disabled = false;
STOP_BUTTON.disabled = true;
}
async function stopMe() {
await evsi.stop();
resetEVS();
START_BUTTON.disabled = false;
STOP_BUTTON.disabled = true;
}
async function skipMe(index) {
await evsi.stop();
resetEVS();
await startMe(index);
}
window.addEventListener('message', function(e) {
let d = JSON.parse(e.data);
if (d.command == "loadCode") {
setCommandData(d.code);
}
});
</script>
</head>
<body style="margin:0px">
<p id="evsContent">loading...</p>
<input type="button" id="startButton" value="start" onclick="startMe()" disabled/><br/>
<input type="button" id="stopButton" value="stop" onclick="stopMe()" disabled/><br/>
<select id="skipSelect" disabled onchange="skipMe(this.value*1)"></select><br/>
<a href="https://responsivevoice.org">Responsivevoice.org</a>
<!--script src="https://code.responsivevoice.org/responsivevoice.js?key=S09NiLlR"></script-->
</body>
</html>