-
Notifications
You must be signed in to change notification settings - Fork 21
/
manual.html
236 lines (200 loc) · 6.2 KB
/
manual.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta content="utf-8" http-equiv="encoding" />
<meta name="copyright" content="© 2020 Steve Seguin" />
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon" />
<!-- Primary Meta Tags -->
<title>CAPTION.Ninja</title>
<meta name="title" content="CAPTION.Ninja" />
<meta name="description" content="This is a free-to-use captioning tool for OBS. Speech-to-text is done using Machine Learning" />
<meta name="author" content="Steve Seguin" />
<style>
@font-face {
font-family: 'Cousine';
src: url('fonts/Cousine-Bold.ttf') format('truetype');
}
body {
margin:0;
padding:0 10px;
height:100%;
border: 0;
display: flex;
flex-direction: column-reverse;
position:absolute;
bottom:0;
overflow:hidden;
width: 100%;
}
.output {
margin:0;
color: black;
font-family: Cousine, monospace;
font-size: 3.2em;
line-height: 1.1em;
letter-spacing: 0.0em;
text-transform: uppercase;
padding: 0em;
}
.output span {
padding: 8px 8px 0px 8px;
margin:0;
display: block;
}
#interm {
color:blue;
margin:5px;
}
a {
color:blue;
font-size:1.2em;
text-transform: none;
}
input {
width: 100%;
padding: 20px;
margin: 10px 0;
font-size: 2em;
}
</style>
</head>
<body>
<input type="textarea" id="userinput" />
<div id="interm" class="output">
<font style='color:black;font-size:60%;line-height: 1.4em;' ><div >This is a free-to-use captioning tool.</div></font><font style='color:black;font-size:30%;line-height: 1.4em;' >
<div ><br /><br />
The output of this app is mirrored here: <a id="shareLink" href="overlay.html" target='_blank'>*ERROR GENERATING LINK*</a>. Add it to OBS as a browser source overlay if wishing to use it for a live stream.
</div></font>
<br /><br />
</div>
<div id="output" class="output"></div>
<script>
function updateURL(param, force=false) {
var para = param.split('=');
if (!(urlParams.has(para[0].toLowerCase()))){
if (history.pushState){
var arr = window.location.href.split('?');
var newurl;
if (arr.length > 1 && arr[1] !== '') {
newurl = window.location.href + '&' +param;
} else {
newurl = window.location.href + '?' +param;
}
window.history.pushState({path:newurl},'',newurl);
}
} else if (force){
if (history.pushState){
var href = new URL(window.location.href);
if (para.length==1){
href.searchParams.set(para[0].toLowerCase(), "");
} else {
href.searchParams.set(para[0].toLowerCase(), para[1]);
}
log(href.toString());
window.history.pushState({path:href.toString()},'',href.toString());
}
}
}
(function (w) {
w.URLSearchParams = w.URLSearchParams || function (searchString) {
var self = this;
self.searchString = searchString;
self.get = function (name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(self.searchString);
if (results == null) {
return null;
}
else {
return decodeURI(results[1]) || 0;
}
};
};
})(window);
var urlParams = new URLSearchParams(window.location.search);
function generateStreamID(){
var text = "";
var possible = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
for (var i = 0; i < 7; i++){
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
var label = false;
if (urlParams.has("label")){
label = urlParams.get("label");
}
var roomID = "test";
if (urlParams.has("room")){
roomID = urlParams.get("room");
} else if (urlParams.has("ROOM")){
roomID = urlParams.get("ROOM");
} else {
roomID = generateStreamID();
updateURL("room="+roomID);
}
var counter=0;
var url = document.URL.substr(0,document.URL.lastIndexOf('/'));
document.getElementById("shareLink").href= url+"/overlay?room="+roomID;
document.getElementById("shareLink").innerHTML = url+"/overlay?room="+roomID;
navigator.clipboard.writeText(url+"/overlay?room="+roomID).then(() => {
/* clipboard successfully set */
}, () => {
/* clipboard write failed */
});
var apiKey = false;
var socket;
function connectWebSocket() {
socket = new WebSocket("wss://api.caption.ninja:443");
socket.onclose = function() {
console.log("WebSocket connection closed. Attempting to reconnect...");
setTimeout(connectWebSocket, 500); // Try to reconnect after 5 seconds
};
socket.onopen = function() {
console.log("WebSocket connected. Joining room...");
socket.send(JSON.stringify({"join":roomID}));
};
// Add error handling
socket.onerror = function(error) {
console.error("WebSocket error:", error);
setTimeout(connectWebSocket, 5000); // Try to reconnect after 5 seconds
};
}
// Initial connection
connectWebSocket();
function interResults(){
counter+=1;
var interim_transcript = document.getElementById("userinput").value;
document.getElementById("interm").innerHTML = interim_transcript;
try {
socket.send(JSON.stringify({"msg":true, "interm":interim_transcript, "id":counter, "label":label}));
} catch(e){
interim_transcript="";
}
}
function finalResults(){
counter+=1;
var final_transcript = document.getElementById("userinput").value;
try {
if (final_transcript==""){
socket.send(JSON.stringify({"msg":true, "final":"", "id":counter, "label":label}));
} else {
socket.send(JSON.stringify({"msg":true, "final":final_transcript, "id":counter, "label":label}));
}
} catch(e){
final_transcript="";
}
document.getElementById("output").innerHTML+=final_transcript;
document.getElementById("interm").innerHTML="";
document.getElementById("userinput").value = "";
}
document.getElementById("userinput").addEventListener("keyup", function(event) {
if (event.code === 'Enter') {
finalResults();
} else {
interResults();
}
});
</script>
</body>
</html>