-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.html
More file actions
1843 lines (1665 loc) · 68.7 KB
/
index.html
File metadata and controls
1843 lines (1665 loc) · 68.7 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- Primary Meta Tags -->
<title>CAPTION.Ninja - Free Live Captions & Translation for OBS, vMix, Streaming</title>
<meta name="title" content="CAPTION.Ninja - Free Live Captions & Translation for OBS, vMix, Streaming" />
<meta name="description" content="Free browser-based live captioning, transcription, and real-time translation for OBS, vMix, and live streams. No installation required. Speech-to-text powered by browser AI. Created by Steve Seguin, maker of VDO.Ninja." />
<meta name="keywords" content="captions, subtitles, OBS, vMix, live streaming, transcription, translation, speech to text, closed captions, accessibility, free, browser, real-time" />
<meta name="author" content="Steve Seguin" />
<meta name="copyright" content="Steve Seguin" />
<meta name="robots" content="index, follow" />
<link rel="canonical" href="https://caption.ninja/" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://caption.ninja/" />
<meta property="og:title" content="CAPTION.Ninja - Free Live Captions & Translation" />
<meta property="og:description" content="Free browser-based live captioning and real-time translation for OBS, vMix, and live streams. No installation required." />
<meta property="og:image" content="https://caption.ninja/favicon.svg" />
<meta property="og:site_name" content="CAPTION.Ninja" />
<!-- Twitter -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:url" content="https://caption.ninja/" />
<meta name="twitter:title" content="CAPTION.Ninja - Free Live Captions & Translation" />
<meta name="twitter:description" content="Free browser-based live captioning and real-time translation for OBS, vMix, and live streams." />
<meta name="twitter:image" content="https://caption.ninja/favicon.svg" />
<meta name="twitter:creator" content="@steveseguin" />
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<link rel="shortcut icon" href="favicon.svg" />
<!-- Structured Data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "CAPTION.Ninja",
"url": "https://caption.ninja",
"description": "Free browser-based live captioning, transcription, and real-time translation for OBS, vMix, and live streams.",
"applicationCategory": "Multimedia",
"operatingSystem": "Any",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
},
"author": {
"@type": "Person",
"name": "Steve Seguin",
"url": "https://github.com/steveseguin"
},
"creator": {
"@type": "Person",
"name": "Steve Seguin"
}
}
</script>
<style>
@font-face {
font-family: 'Cousine';
src: url('fonts/Cousine-Bold.ttf') format('truetype');
}
:root {
--primary-color: #2498Eb;
--secondary-color: #2c3e50;
--background-color: #0000;
--text-color: #333;
--border-radius: 4px;
--cc-background: #000000;
--cc-text-color: #ffffff;
--cc-font-size: 24px;
--cc-line-height: 1.2;
}
button {
max-width: 600px;
}
body {
margin:0;
padding:0 10px;
height:100%;
border: 0;
display: flex;
flex-direction: column-reverse;
position:absolute;
bottom:0;
overflow:hidden;
max-width: calc(100vw - 20px);
}
.hidden {
display:none!important;
}
.output {
margin:0;
background-color: #0000;
color: white;
font-family: Cousine, monospace;
font-size: 3.2em;
line-height: 1.1em;
letter-spacing: 0.0em;
padding: 0em;
text-shadow: 0.05em 0.05em 0px rgba(0,0,0,1);
}
.output span {
background-color: black;
padding: 8px 8px 0px 8px;
margin:0;
max-width: 100%;
}
a {
color:white;
font-size:1.2em;
text-transform: none;
}
.github {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAd5JREFUOE+d1MurjlEUBvDfIZQZShEGmMhQiZGZlAlyK4eEAZHcyiVRyq1cUq5FwsD1MJGJiT/AzEzRcR8xMnGOW89pv9q9fScfe/J977o8e61nP2v16HzGYBWWYA4mlbBPeI5HuI9v7fSeDnircRqTh7msMX/ALtyr42rAEbiAzX8BaruTsx0/46gBL/0HWAMe0G01YNq8Xbz5PYuN2ISvCHc5oWEsruA69mJF8a0Mr6kwD/C64mw3zpSgCfjc6nE8vhRbAE+U/+8xI4DrcKNKOol9XfJ4CimgOb0BfIilxfIds/GyS8BZeIGRJf5BAN9gWjE8xcIuwZqwZ1hQPvoDOIBRxRCiN/wj4C30lpyBNmAmYNk/Aj7G4pIz2G75I6Y2Iu0CONwlZ2Ldcl+rqmjvWhdgCdmCi1Xs0KOsxc3C5WDhcw8uI9+dzugyVZFNw3/i1jTCfoVIJmo/VDiJeJ9gPX4U1CRHs4swrnXTO8xsZjlAd9GP+WU1zcPxckGde7WMZbvy5eirl8N5bMUxHMSvYdo9igMt3znsiK29vuLI1ojYU+2dwmWdnwv3V4YskozfUAGdFmzaz4KdgiM43KomNGTW32JnGd0/IZ0A48wrhpPMdFZ+feZievjqpILf7lRg3csIRqAAAAAASUVORK5CYII=");
background-color: #FFF !important;
width: 4px;
height: 12px;
background-repeat: no-repeat;
display: inline-block;
top: 2px;
position: relative;
left: 2px;
filter: invert(100%);
-webkit-filter: invert(100%);
}
.small-text-container {
background-color: black;
padding: 10px;
margin-top: 10px;
}
.toggle-button {
background-color: var(--primary-color);
color: white;
border: none;
padding: 10px 20px;
border-radius: var(--border-radius);
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s ease;
margin: 10px 0;
position: absolute;
top:0;
right:0;
}
.toggle-button:hover {
background-color: var(--secondary-color);
}
.toggle-button.paused {
background-color: #dc3545;
}
.control-buttons {
position: fixed;
top: 10px;
left: 10px;
right: 10px;
display: flex;
justify-content: flex-start;
gap: 10px;
}
.control-button {
background-color: var(--primary-color);
color: white;
border: none;
padding: 10px 20px;
border-radius: var(--border-radius);
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s ease;
}
.control-button:hover {
background-color: var(--secondary-color);
}
.control-button.paused {
background-color: #dc3545;
}
/* Language toggle control styles */
.lang-toggle-container {
position: fixed;
top: 10px;
left: 10px;
z-index: 1000;
display: flex;
align-items: center;
gap: 8px;
background: rgba(0, 0, 0, 0.85);
padding: 8px 12px;
border-radius: 6px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.lang-toggle-container.hidden {
display: none !important;
}
.lang-toggle-label {
color: #9aa3b2;
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.lang-toggle-btn {
background: var(--primary-color);
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-weight: 600;
font-size: 14px;
transition: background-color 0.2s, transform 0.1s;
min-width: 60px;
text-align: center;
}
.lang-toggle-btn:hover {
background: #1d7acc;
}
.lang-toggle-btn:active {
transform: scale(0.98);
}
.lang-toggle-btn .lang-code {
font-weight: 700;
}
.lang-toggle-shortcut {
color: #6b7280;
font-size: 10px;
margin-left: 4px;
}
.output {
direction: auto;
unicode-bidi: bidi-override;
}
.output span {
background-color: black;
padding: 8px 8px 0px 8px;
margin: 0;
display: inline-block;
direction: inherit;
text-align: start;
}
.error-banner {
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: #dc3545;
color: white;
padding: 10px;
text-align: center;
z-index: 10000;
font-size: 16px;
display: none;
}
.error-banner button {
background-color: white;
color: #dc3545;
border: none;
padding: 5px 10px;
margin-left: 10px;
border-radius: 4px;
cursor: pointer;
}
@media (max-width: 768px) {
.small-text-container {
padding: 5px;
margin-top: 5px;
}
.output {
font-size: 2.2em;
line-height: 1em;
text-shadow: 0.03em 0.03em 0px rgba(0,0,0,1);
}
.output span {
padding: 5px 5px 0px 5px;
}
body {
padding: 0 5px;
max-width: calc(100vw - 10px);
}
.control-button {
padding: 8px 12px;
font-size: 14px;
}
ol, ul {
padding-left: 20px;
}
.small-text-container font {
font-size: 40% !important;
}
}
/* For very small screens */
@media (max-width: 480px) {
.output {
font-size: 1.6em;
}
.small-text-container font {
font-size: 50% !important;
}
}
/* Customize Overlay Modal */
.modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.7);
z-index: 9999;
align-items: center;
justify-content: center;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}
.modal-overlay.open {
display: flex;
}
.modal-content {
background: #1e2430;
border-radius: 12px;
padding: 24px;
max-width: 640px;
width: 90%;
max-height: 85vh;
overflow-y: auto;
color: #e6e9ef;
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
font-family: inherit;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
border-bottom: 1px solid #2d3543;
padding-bottom: 12px;
}
.modal-header h2 {
margin: 0;
font-size: 1.3em;
font-weight: 600;
}
.modal-close {
background: none;
border: none;
font-size: 24px;
color: #9aa3b2;
cursor: pointer;
font-family: inherit;
}
.modal-close:hover {
color: #fff;
}
.modal-section {
margin-bottom: 24px;
padding-bottom: 16px;
border-bottom: 1px solid #2d3543;
}
.modal-section:last-of-type {
border-bottom: none;
}
.modal-section h3 {
font-size: 11px;
font-weight: 600;
color: #7a8599;
margin: 0 0 14px 0;
text-transform: uppercase;
letter-spacing: 0.8px;
}
.modal-group {
margin-bottom: 16px;
}
.modal-group:last-child {
margin-bottom: 0;
}
.modal-row {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 4px;
}
.modal-row label {
min-width: 150px;
font-size: 14px;
font-weight: 500;
}
.modal-row input, .modal-row select {
flex: 1;
padding: 8px 12px;
background: #232a36;
border: 1px solid #2d3543;
border-radius: 6px;
color: #e6e9ef;
font-size: 14px;
font-family: inherit;
}
.modal-row input:focus, .modal-row select:focus {
outline: none;
border-color: var(--primary-color);
}
.modal-row input[type="checkbox"] {
flex: 0;
width: 18px;
height: 18px;
cursor: pointer;
}
.modal-row input[type="number"] {
max-width: 100px;
}
.modal-help {
font-size: 12px;
color: #6b7785;
margin: 2px 0 0 162px;
line-height: 1.4;
}
.url-preview {
background: #0f1017;
padding: 12px;
border-radius: 6px;
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Consolas', monospace;
font-size: 11px;
word-break: break-all;
margin-top: 16px;
border: 1px solid #2d3543;
max-height: 80px;
overflow-y: auto;
line-height: 1.5;
}
.url-preview strong {
color: #7a8599;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.capture-note {
margin-top: 10px;
font-size: 12px;
color: #b8c0cc;
background: #2d3543;
padding: 10px 12px;
border-radius: 6px;
border-left: 3px solid var(--primary-color);
}
.capture-note strong {
color: #e6e9ef;
}
.modal-actions {
display: flex;
gap: 12px;
margin-top: 20px;
}
.modal-actions button {
flex: 1;
padding: 12px 16px;
border-radius: 6px;
font-weight: 600;
cursor: pointer;
border: none;
font-size: 14px;
font-family: inherit;
transition: background-color 0.2s, transform 0.1s;
}
.modal-actions button:active {
transform: scale(0.98);
}
.modal-actions .copy-btn {
background: var(--primary-color);
color: white;
flex: 2;
}
.modal-actions .copy-btn:hover {
background: #1d7acc;
}
.modal-actions .cancel-btn {
background: #232a36;
color: #9aa3b2;
border: 1px solid #2d3543;
}
.modal-actions .cancel-btn:hover {
background: #2d3543;
color: #e6e9ef;
}
@media (max-width: 600px) {
.modal-content {
padding: 16px;
max-height: 90vh;
}
.modal-row {
flex-wrap: wrap;
}
.modal-row label {
min-width: 100%;
margin-bottom: 4px;
}
}
</style>
</head>
<body>
<div id="errorBanner" class="error-banner">
<span id="errorMessage"></span>
<button id="dismissError">Dismiss</button>
</div>
<!-- Language Toggle Control (hidden by default, enabled via &togglelang=) -->
<div id="langToggleContainer" class="lang-toggle-container hidden">
<span class="lang-toggle-label">Source:</span>
<button id="langToggleBtn" class="lang-toggle-btn" title="Switch source language (Ctrl+L)">
<span id="langToggleCurrent" class="lang-code">EN</span>
</button>
<span class="lang-toggle-shortcut">Ctrl+L</span>
</div>
<div id="interm" class="output">
<font style='font-size:60%;line-height: 1.4em;'><span>Welcome to CAPTION.Ninja - A Free Captioning Tool</span></font>
<div class="small-text-container">
<font style='font-size:30%;line-height: 1.4em;'>
<span>
<br />
<strong>📖 Quick Start:</strong>
<ol>
<li>Accept the microphone permissions when prompted.</li>
<li>Start speaking - your words will appear as captions.</li>
<li>For live streaming, add this link to OBS as a browser source overlay: 👉 <a id="shareLink" href="overlay.html" target='_blank'>*ERROR GENERATING LINK*</a></li>
</ol>
<strong>💡 Tips:</strong>
<ul>
<li>Use Google Chrome or Microsoft Edge for best results. Some users Chrome has a truncation issue though, so maybe just use Edge.</li>
<li>To save the transcription: Select all (CTRL+A), copy (CTRL+C), and paste into a text editor (CTRL+V).</li>
</ul>
<strong>🌐 Translation Options:</strong>
<ul>
<li><a href='./translation-guide.html'>📖 Complete Translation Guide</a> - All translation methods explained</li>
<li><a href='./translate'>Free Translation</a> - 17 languages, no API key required</li>
<li><a href='./translate_premium'>Premium Translation</a> - 100+ languages with Google Cloud API</li>
<li>Quick overlay translation: Add <code>&translate=es</code> (or other <a href="https://cloud.google.com/translate/docs/languages" target="_blank">language code</a>) to any overlay URL</li>
<li>Supported free languages: bg, cs, nl, en, et, de, fr, is, it, nb, nn, fa, pl, pt, ru, es, uk</li>
</ul>
<strong>🔬🛠️ Advanced Features:</strong>
<ul>
<li>Change input language: Add <code>&lang=fr-FR</code> to the URL (<a href="https://cloud.google.com/speech-to-text/docs/languages" target="_blank">speech recognition codes</a>)</li>
<li>Multi-language speakers: Add <code>&togglelang=en-US,fr-FR</code> to enable quick language switching (Ctrl+L or click toggle)</li>
<li>Text to Speech playback is supported. See the <a href="https://github.com/steveseguin/captionninja?tab=readme-ov-file#tts-integration" target="_blank">TTS guide in the GitHub README</a> and visit <a href="https://tts.rocks" target="_blank">tts.rocks</a> for engines and usage.</li>
<li>Use a <a href='https://www.vb-audio.com/Cable/'>Virtual Audio Cable</a> to caption from other audio sources</li>
</ul>
<strong>🆘 Need Help?</strong>
<ul>
<li>Check out more options and details on <a href='https://github.com/steveseguin/captionninja'>GitHub <span class="github"></span></a></li>
<li>Ask for help on <a href='https://discord.vdo.ninja'>our Discord server<span class="discord"></span></a> - @steve for help there</li>
</ul>
</span>
</font>
</div>
<br />
</div>
<div id="output" class="output"></div>
<button id="toggleTranscription" class="hidden control-button">Pause Transcription</button>
<script src="security-utils.js"></script>
<script src="tts-integration.js"></script>
<script src="ws-publisher.js"></script>
<script src="text-rules.js"></script>
<script>
function detectTextDirection(text) {
const rtlChars = /[\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC]/;
return rtlChars.test(text) ? 'rtl' : 'ltr';
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function getOldStorage() {
var values = [],
keys = Object.keys(localStorage),
i = keys.length;
while ( i-- ) {
values.push( localStorage.getItem(keys[i]) );
}
return values;
}
function removeStorage(cname){
localStorage.removeItem(cname);
}
function setStorage(cname, cvalue, exdays=999){
var now = new Date();
var item = {
value: cvalue,
expiry: now.getTime() + (exdays * 24 * 60 * 60 * 1000),
};
try{
localStorage.setItem(cname, JSON.stringify(item));
}catch(e){errorlog(e);}
}
function getStorage(cname) {
try {
var itemStr = localStorage.getItem(cname);
} catch(e){
errorlog(e);
return;
}
if (!itemStr) {
return "";
}
var item = JSON.parse(itemStr);
var now = new Date();
if (now.getTime() > item.expiry) {
localStorage.removeItem(cname);
return "";
}
return item.value;
}
let isPaused = false;
const toggleButton = document.getElementById('toggleTranscription');
toggleButton.addEventListener('click', () => {
isPaused = !isPaused;
if (isPaused) {
recognition.stop();
toggleButton.textContent = 'Resume Transcription';
toggleButton.classList.add('paused');
} else {
recognition.start();
toggleButton.textContent = 'Pause Transcription';
toggleButton.classList.remove('paused');
}
});
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);
var textRulesConfig = (window.CaptionTextRules && window.CaptionTextRules.parseRulesFromUrlParams)
? window.CaptionTextRules.parseRulesFromUrlParams(urlParams)
: { replacements: [], restricted: [], matchMode: 'phonetic' };
var textRulesEngine = (window.CaptionTextRules && window.CaptionTextRules.createEngine)
? window.CaptionTextRules.createEngine(textRulesConfig)
: null;
function applyTextRules(text) {
if (!textRulesEngine || typeof text !== 'string') return text;
try {
return textRulesEngine.apply(text);
} catch (e) {
console.warn('Text rules failed:', e);
return text;
}
}
function isEdge() {
return navigator.userAgent.indexOf("Edg/") !== -1;
}
function sanitize(string) {
var temp = document.createElement('div');
temp.textContent = string;
let text = temp.textContent
.substring(0, Math.min(temp.textContent.length, 500))
.trim();
//if (isEdge()) {
const isRTL = /[\u0591-\u07FF\u200F\u202B\u202E\uFB1D-\uFDFD\uFE70-\uFEFC]/.test(text);
if (isRTL) {
text = text.replaceAll(/[.,!?،؟؛]/g," ");
}
//}
return applyTextRules(text);
}
function escapeHTML(text) {
return String(text)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
// Option 2: Truncate interim text to keep only most recent words/chars
function truncateInterim(text) {
if (!text) return text;
// Apply character limit first (keep end)
if (maxChars > 0 && text.length > maxChars) {
text = "..." + text.slice(-maxChars);
}
// Apply word limit (keep end)
if (maxWords > 0) {
const words = text.split(/\s+/);
if (words.length > maxWords) {
text = "..." + words.slice(-maxWords).join(' ');
}
}
return text;
}
// Option 4: Extract complete sentences for auto-split
function extractCompleteSentences(text) {
// Pattern: sentences ending with . ? ! followed by space
const sentenceEndPattern = /([^.!?]*[.!?]+)\s+/g;
const matches = [];
let lastIndex = 0;
let match;
while ((match = sentenceEndPattern.exec(text)) !== null) {
matches.push(match[1].trim());
lastIndex = match.index + match[0].length;
}
const remaining = text.slice(lastIndex).trim();
return {
complete: matches, // Array of complete sentences
remaining: remaining // Incomplete sentence at the end
};
}
// Option 1: Force finalization of pending interim text
function forceFinalization() {
if (!pendingInterim) return;
counter += 1;
const direction = detectTextDirection(pendingInterim);
document.getElementById("output").innerHTML += `<span id='final_${counter}' dir='${direction}'>${escapeHTML(pendingInterim)}</span><br />`;
document.getElementById("interm").innerHTML = "";
try {
var msgObj = {"msg":true, "final":pendingInterim, "id":counter, "ln": myLang};
if (label) msgObj.label = label;
publishCaption(msgObj);
// Optional: speak final results locally if TTS is enabled
if (window.CAPTION_TTS && typeof window.CAPTION_TTS.speak === 'function') {
window.CAPTION_TTS.speak(pendingInterim);
}
} catch(e) {
console.error(e);
}
pendingInterim = "";
silenceTimer = null;
}
var generateRandomString = function (LLL = 16) {
var text = "";
var words = ["the", "of", "to", "and", "a", "in", "is", "it", "you", "that", "he", "was", "for", "on", "are", "with", "as", "I", "his", "they", "be", "at", "one", "have", "this", "from", "or", "had", "by", "word", "but", "what", "some", "we", "can", "out", "other", "were", "all", "there", "when", "up", "use", "your", "how", "said", "an", "each", "she", "which", "do", "their", "time", "if", "will", "way", "about", "many", "then", "them", "write", "would", "like", "so", "these", "her", "long", "make", "thing", "see", "him", "two", "has", "look", "more", "day", "could", "go", "come", "did", "number", "sound", "no", "most", "people", "my", "over", "know", "water", "than", "call", "first", "who", "may", "down", "side", "been", "now", "find", "any", "new", "work", "part", "take", "get", "place", "made", "live", "where", "after", "back", "little", "only", "round", "man", "year", "came", "show", "every", "good", "me", "give", "our", "under", "name", "very", "through", "just", "form", "sentence", "great", "think", "say", "help", "low", "line", "differ", "turn", "cause", "much", "mean", "before", "move", "right", "boy", "old", "too", "same", "tell", "does", "set", "three", "want", "air", "well", "also", "play", "small", "end", "put", "home", "read", "hand", "port", "large", "spell", "add", "even", "land", "here", "must", "big", "high", "such", "follow", "act", "why", "ask", "men", "change", "went", "light", "kind", "off", "need", "house", "picture", "try", "us", "again", "animal", "point", "mother", "world", "near", "build", "self", "earth", "father", "head", "stand", "own", "page", "should", "country", "found", "answer", "school", "grow", "study", "still", "learn", "plant", "cover", "food", "sun", "four", "between", "state", "keep", "eye", "never", "last", "let", "thought", "city", "tree", "cross", "farm", "hard", "start", "might", "story", "saw", "far", "sea", "draw", "left", "late", "run", "dont", "while", "press", "close", "night", "real", "life", "few", "north", "open", "seem", "together", "next", "white", "children", "begin", "got", "walk", "example", "ease", "paper", "group", "always", "music", "those", "both", "mark", "often", "letter", "until", "mile", "river", "car", "feet", "care", "second", "book", "carry", "took", "science", "eat", "room", "friend", "began", "idea", "fish", "mountain", "stop", "once", "base", "hear", "horse", "cut", "sure", "watch", "color", "face", "wood", "main", "enough", "plain", "girl", "usual", "young", "ready", "above", "ever", "red", "list", "though", "feel", "talk", "bird", "soon", "body", "dog", "family", "direct", "pose", "leave", "song", "measure", "door", "product", "black", "short", "numeral", "class", "wind", "question", "happen", "complete", "ship", "area", "half", "rock", "order", "fire", "south", "problem", "piece", "told", "knew", "pass", "since", "top", "whole", "king", "space", "heard", "best", "hour", "better", "during", "hundred", "five", "remember", "step", "early", "hold", "west", "ground", "interest", "reach", "fast", "verb", "sing", "listen", "six", "table", "travel", "less", "morning", "ten", "simple", "several", "vowel", "toward", "war", "lay", "against", "pattern", "slow", "center", "love", "person", "money", "serve", "appear", "road", "map", "rain", "rule", "govern", "pull", "cold", "notice", "voice", "unit", "power", "town", "fine", "certain", "fly", "fall", "lead", "cry", "dark", "machine", "note", "wait", "plan", "figure", "star", "box", "noun", "field", "rest", "correct", "able", "pound", "done", "beauty", "drive", "stood", "contain", "front", "teach", "week", "final", "gave", "green", "oh", "quick", "develop", "ocean", "warm", "free", "minute", "strong", "special", "mind", "behind", "clear", "tail", "produce", "fact", "street", "inch", "multiply", "nothing", "course", "stay", "wheel", "full", "force", "blue", "object", "decide", "surface", "deep", "moon", "island", "foot", "system", "busy", "test", "record", "boat", "common", "gold", "possible", "plane", "stead", "dry", "wonder", "laugh", "thousand", "ago", "ran", "check", "game", "shape", "equate", "hot", "miss", "brought", "heat", "snow", "tire", "bring", "yes", "distant", "fill", "east", "paint", "language", "among", "grand", "ball", "yet", "wave", "drop", "heart", "am", "present", "heavy", "dance", "engine", "position", "arm", "wide", "sail", "material", "size", "vary", "settle", "speak", "weight", "general", "ice", "matter", "circle", "pair", "include", "divide", "syllable", "felt", "perhaps", "pick", "sudden", "count", "square", "reason", "length", "represent", "art", "subject", "region", "energy", "hunt", "probable", "bed", "brother", "egg", "ride", "cell", "believe", "fraction", "forest", "sit", "race", "window", "store", "summer", "train", "sleep", "prove", "lone", "leg", "exercise", "wall", "catch", "mount", "wish", "sky", "board", "joy", "winter", "sat", "written", "wild", "instrument", "kept", "glass", "grass", "cow", "job", "edge", "sign", "visit", "past", "soft", "fun", "bright", "gas", "weather", "month", "million", "bear", "finish", "happy", "hope", "flower", "clothe", "strange", "gone", "jump", "baby", "eight", "village", "meet", "root", "buy", "raise", "solve", "metal", "whether", "push", "seven", "paragraph", "third", "shall", "held", "hair", "describe", "cook", "floor", "either", "result", "burn", "hill", "safe", "cat", "century", "consider", "type", "law", "bit", "coast", "copy", "phrase", "silent", "tall", "sand", "soil", "roll", "temperature", "finger", "industry", "value", "fight", "lie", "beat", "excite", "natural", "view", "sense", "ear", "else", "quite", "broke", "case", "middle", "kill", "son", "lake", "moment", "scale", "loud", "spring", "observe", "child", "straight", "consonant", "nation", "dictionary", "milk", "speed", "method", "organ", "pay", "age", "section", "dress", "cloud", "surprise", "quiet", "stone", "tiny", "climb", "cool", "design", "poor", "lot", "experiment", "bottom", "key", "iron", "single", "stick", "flat", "twenty", "skin", "smile", "crease", "hole", "trade", "melody", "trip", "office", "receive", "row", "mouth", "exact", "symbol", "die", "least", "trouble", "shout", "except", "wrote", "seed", "tone", "join", "suggest", "clean", "break", "lady", "yard", "rise", "bad", "blow", "oil", "blood", "touch", "grew", "cent", "mix", "team", "wire", "cost", "lost", "brown", "wear", "garden", "equal", "sent", "choose", "fell", "fit", "flow", "fair", "bank", "collect", "save", "control", "decimal", "gentle", "woman", "captain", "practice", "separate", "difficult", "doctor", "please", "protect", "noon", "whose", "locate", "ring", "character", "insect", "caught", "period", "indicate", "radio", "spoke", "atom", "human", "history", "effect", "electric", "expect", "crop", "modern", "element", "hit", "student", "corner", "party", "supply", "bone", "rail", "imagine", "provide", "agree", "thus", "capital", "wont", "chair", "danger", "fruit", "rich", "thick", "soldier", "process", "operate", "guess", "necessary", "sharp", "wing", "create", "neighbor", "wash", "bat", "rather", "crowd", "corn", "compare", "poem", "string", "bell", "depend", "meat", "rub", "tube", "famous", "dollar", "stream", "fear", "sight", "thin", "triangle", "planet", "hurry", "chief", "colony", "clock", "mine", "tie", "enter", "major", "fresh", "search", "send", "yellow", "gun", "allow", "print", "dead", "spot", "desert", "suit", "current", "lift", "rose", "continue", "block", "chart", "hat", "sell", "success", "company", "subtract", "event", "particular", "deal", "swim", "term", "opposite", "wife", "shoe", "shoulder", "spread", "arrange", "camp", "invent", "cotton", "born", "determine", "quart", "nine", "truck", "noise", "level", "chance", "gather", "shop", "stretch", "throw", "shine", "property", "column", "molecule", "select", "wrong", "gray", "repeat", "require", "broad", "prepare", "salt", "nose", "plural", "anger", "claim", "continent", "oxygen", "sugar", "death", "pretty", "skill", "women", "season", "solution", "magnet", "silver", "thank", "branch", "match", "suffix", "especially", "fig", "afraid", "huge", "sister", "steel", "discuss", "forward", "similar", "guide", "experience", "score", "apple", "bought", "led", "pitch", "coat", "mass", "card", "band", "rope", "slip", "win", "dream", "evening", "condition", "feed", "tool", "total", "basic", "smell", "valley", "nor", "double", "seat", "arrive", "master", "track", "parent", "shore", "division", "sheet", "substance", "favor", "connect", "post", "spend", "chord", "fat", "glad", "original", "share", "station", "dad", "bread", "charge", "proper", "bar", "offer", "segment", "slave", "duck", "instant", "market", "degree", "populate", "chick", "dear", "enemy", "reply", "drink", "occur", "support", "speech", "nature", "range", "steam", "motion", "path", "liquid", "log", "meant", "quotient", "teeth", "shell", "neck"];
for (var i = 0; i < 2; i++) {
try {
var rndint = parseInt(Math.random() * 1000);
text += words[rndint]; // capitalizeFirstLetter can be used to improve security
} catch (e) {}
}
var possible = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
text += possible.charAt(Math.floor(Math.random() * possible.length));
while (text.length < LLL) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
try {
text = text.replaceAll("AD", "vDAv"); // avoiding adblockers
text = text.replaceAll("Ad", "vdAv");
text = text.replaceAll("ad", "vdav");
text = text.replaceAll("aD", "vDav");
} catch (e) {
console.error(e);
}
return text;
};
// Secure alphanumeric room ID generator (>=12 chars)
function generateSecureRoomID(len = 16) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let out = '';
const cryptoObj = window.crypto || window.msCrypto;
if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
const randomValues = new Uint8Array(len);
cryptoObj.getRandomValues(randomValues);
for (let i = 0; i < len; i++) {
out += chars.charAt(randomValues[i] % chars.length);
}
return out;
}
for (let i = 0; i < len; i++) {
out += chars.charAt(Math.floor(Math.random() * chars.length));
}
return out;
}
function generateStreamID(){
var text = "";
var possible = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
for (var i = 0; i < 9; i++){
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
var roomID = "test";
let storedRoom = "";
try { storedRoom = localStorage.getItem('cn_room_id') || ""; } catch (e) {}
if (urlParams.has("room")){
roomID = urlParams.get("room");
} else if (urlParams.has("ROOM")){
roomID = urlParams.get("ROOM");
} else if (storedRoom && /^[A-Za-z0-9]{12,}$/.test(storedRoom)) {
roomID = storedRoom;
updateURL("room="+roomID);
} else {
roomID = generateSecureRoomID(16);
updateURL("room="+roomID);
}
try { localStorage.setItem('cn_room_id', roomID); } catch (e) {}
// Check for insecure stream ID and show warning
if (isInsecureStreamId(roomID)) {
injectSecurityStyles();
showSecurityWarning(
'Warning: You are using an insecure room ID that could be easily guessed. Consider using a more secure ID for privacy.',
0 // No auto-dismiss, user must close manually
);
}
var label = false;
if (urlParams.has("label")){
label = urlParams.get("label");
}
var myLang = "en-US";
if (urlParams.has("lang")){
myLang = urlParams.get("lang");
} else {
updateURL("lang="+myLang);
}
console.log("Language: "+myLang);
// Language Toggle Feature - enables quick switching between languages
// Usage: &togglelang=en-US,fr-FR or &togglelang=en-US,fr-FR,es-ES
var toggleLanguages = [];
var currentLangIndex = 0;
if (urlParams.has("togglelang")) {
var toggleParam = urlParams.get("togglelang");
toggleLanguages = toggleParam.split(",").map(function(l) { return l.trim(); }).filter(function(l) { return l.length > 0; });
if (toggleLanguages.length >= 2) {
// Find current language in the toggle list, or default to first
currentLangIndex = toggleLanguages.indexOf(myLang);
if (currentLangIndex === -1) {
// Current lang not in list, set to first toggle language
currentLangIndex = 0;
myLang = toggleLanguages[0];
updateURL("lang=" + myLang, true);
}
// Show the toggle UI
var langToggleContainer = document.getElementById("langToggleContainer");
var langToggleBtn = document.getElementById("langToggleBtn");
var langToggleCurrent = document.getElementById("langToggleCurrent");
if (langToggleContainer && langToggleBtn && langToggleCurrent) {
langToggleContainer.classList.remove("hidden");
// Display language code (e.g., "EN" from "en-US")
function updateToggleDisplay() {
var displayCode = myLang.split("-")[0].toUpperCase();
langToggleCurrent.textContent = displayCode;
langToggleBtn.title = "Current: " + myLang + " - Click or Ctrl+L to switch";
}
updateToggleDisplay();
// Switch to next language in the list
function switchLanguage() {
currentLangIndex = (currentLangIndex + 1) % toggleLanguages.length;
myLang = toggleLanguages[currentLangIndex];
updateURL("lang=" + myLang, true);
updateToggleDisplay();
console.log("Switched language to: " + myLang);
// Restart speech recognition with new language
if (recognition) {
recognition.lang = myLang;
// Stop and restart to apply new language
try {
recognition.stop();
} catch(e) {
console.log("Recognition stop error (expected):", e);
}
// Recognition will auto-restart via onend handler
}
}
// Click handler
langToggleBtn.addEventListener("click", switchLanguage);
// Keyboard shortcut: Ctrl+L
document.addEventListener("keydown", function(e) {
if (e.ctrlKey && e.key.toLowerCase() === "l") {
e.preventDefault();
switchLanguage();
}
});
}
}
}
// Option 1: Silence-based auto-finalization (ms, 0=disabled)
var autoFinalMs = 0;
if (urlParams.has("autofinal")){
autoFinalMs = parseInt(urlParams.get("autofinal")) || 800;