-
Notifications
You must be signed in to change notification settings - Fork 2
/
v2.buildme.html
524 lines (489 loc) · 28.3 KB
/
v2.buildme.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no" />
<meta name="renderer" content="webkit" />
<meta name="force-rendering" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- MDUI CSS -->
<link rel="stylesheet" href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/mdui/1.0.2/css/mdui.min.css" />
<title>VideoTogether</title>
</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-pink mdui-theme-layout-auto">
<!-- Toolbar -->
<div class="mdui-toolbar mdui-color-theme">
<span class="mdui-typo-title">VideoTogether</span>
<div class="mdui-toolbar-spacer"></div>
<a class="mdui-btn mdui-btn-icon">
<i class="mdui-icon material-icons" id="brightness">brightness_4</i>
</a>
<a class="mdui-btn mdui-btn-icon" mdui-menu="{target: '#menu'}">
<i class="mdui-icon material-icons">more_vert</i>
</a>
<ul class="mdui-menu" id="menu">
<li class="mdui-menu-item">
<a class="mdui-ripple" id="Refresh" onClick="window.location.reload()"></a>
<a class="mdui-ripple" id="Return" onClick="window.history.back()"></a>
</li>
</ul>
</div>
<div class="mdui-container mdui-p-t-3">
<div class="mdui-row">
<div class="mdui-col-md-6 mdui-col-sm-12">
<div class="mdui-card" style="padding: 10px">
<div class="mdui-card-primary">
<div class="mdui-card-primary-title" id="Setting"></div>
</div>
<script>
function emptyStrIfUdf(s) {
return s == undefined ? "" : s;
}
let settingItems = [
{
key: "EnableMiniBar",
defaultVal: true
},
{
key: "EnableTextMessage",
defaultVal: true
}
]
let languageDicts = {
/**VT_DELETE_THIS_LINE
"zh-cn": {{{ {"": "./localization/zh-cn.json", "order":0} }}},
"en-us": {{{ {"": "./localization/en-us.json", "order":0} }}},
'ja-jp': {{{ {"": "./localization/ja-jp.json", "order":0} }}},
VT_DELETE_THIS_LINE **/
}
let currentExtensionLanguages = undefined;
function getExtensionLanguages() {
let languages = ['en-us', 'zh-cn'];
try{
if(currentExtensionLanguages.length > 0){
languages = currentExtensionLanguages;
}
}finally{
return languages;
}
}
function getDisplayLanguage(settingLanguage = undefined) {
let languages = Object.keys(languageDicts);
let language = 'en-us';
let prefixLen = 0;
if (typeof settingLanguage != 'string') {
settingLanguage = navigator.language;
}
if (typeof settingLanguage == 'string') {
settingLanguage = settingLanguage.toLowerCase();
if (languages.includes(settingLanguage)) {
language = settingLanguage;
} else {
const settingLanguagePrefix = settingLanguage.split('-')[0];
for (let i = 0; i < languages.length; i++) {
const languagePrefix = languages[i].split('-')[0];
if (settingLanguagePrefix === languagePrefix) {
language = languages[i];
break;
}
}
}
}
return language;
}
let _settingLanguage = undefined;
let _lastExtensionLanguages = ['en-us', 'zh-cn'];
function updateDisplayLanguage(settingLanguage = undefined) {
lastExtensionLanguages = getExtensionLanguages();
if (lastExtensionLanguages.toString() != _lastExtensionLanguages.toString()) {
_lastExtensionLanguages = lastExtensionLanguages;
// update the select options
const select = document.querySelector("#DisplayLanguage");
select.innerHTML = "<option style='display: none'></option>";
for (let i = 0; i < lastExtensionLanguages.length; i++) {
const language = lastExtensionLanguages[i];
const option = document.createElement("option");
option.value = language;
option.innerText = languageDicts[language]["LanguageName"];
select.appendChild(option);
}
}
_settingLanguage = settingLanguage;
const displayLanguage = getDisplayLanguage(settingLanguage);
let languageDict = languageDicts[getDisplayLanguage(settingLanguage)];
for (let key in languageDict) {
try {
document.querySelector("#" + key).innerHTML = languageDict[key];
} catch (e) {
}
}
if (displayLanguage == "zh-cn") {
document.getElementById('voicePannel').style.display = "none"
} else {
document.getElementById('voicePannel').style.display = "none"
}
}
function getLanguageText(key) {
return languageDicts[getDisplayLanguage(_settingLanguage)][key];
}
let extensionEnabled = false;
window.addEventListener("message", e => {
if (e.data.type == 16) {
extensionEnabled = true;
document.querySelector("#MinimiseDefault").checked = e.data.data.MinimiseDefault;
document.querySelector("#DisableRedirectJoin").checked = e.data.data.DisableRedirectJoin;
document.querySelector("#PasswordProtectedRoom").checked = (e.data.data.PasswordProtectedRoom != false);
document.querySelector("#WaitForLoadding").checked = (e.data.data.WaitForLoadding != false);
document.querySelector("#EchoCancellation").checked = !(e.data.data.EchoCancellation === false);
let isDisplayLanguageUpdated = false;
try {
let newValue = e.data.data.DisplayLanguage ? e.data.data.DisplayLanguage : "";
if (newValue != document.querySelector("#DisplayLanguage").value) {
isDisplayLanguageUpdated = true;
}
} catch { };
document.querySelector("#DisplayLanguage").value = e.data.data.DisplayLanguage;
try {
if (isDisplayLanguageUpdated) {
DisplayLanguageSelect.handleUpdate();
}
} catch { }
document.querySelector("#SkipIntroLength").value = emptyStrIfUdf(e.data.data.SkipIntroLength);
document.querySelector("#SkipIntro").checked = e.data.data.SkipIntro;
document.querySelector("#EasyShare").checked = (e.data.data.EasyShare != false);
document.querySelector("#SuperEasyShare").checked = e.data.data.SuperEasyShare;
document.querySelector("#DisableNativeM3u8Player").checked = (e.data.data.DisableNativeM3u8Player != false);
if (e.data.data.PublicReechoVoiceId) {
updateInnerText(document.getElementById('voiceIdLabel'), "语音角色ID: " + e.data.data.PublicReechoVoiceId)
} else {
updateInnerText(document.getElementById('voiceIdLabel'), "没有真人语音角色")
}
for (let i in settingItems) {
let item = settingItems[i]
document.querySelector(`#${item.key}`).checked = e.data.data[item.key] == undefined ? item.defaultVal : e.data.data[item.key];
}
currentExtensionLanguages = e.data.data.ExtensionLanguages;
updateDisplayLanguage(e.data.data.DisplayLanguage);
}
});
setTimeout(() => {
if (!extensionEnabled) {
alert(getLanguageText('ExtensionIsDisabled'));
}
}, 4000);
</script>
<!-- Rectangular switch -->
<div class="mdui-card-content" style="padding-top: 0px">
<div class="mdui-clearfix mdui-p-t-2">
Language / 语言
<div class="mdui-float-right">
<select id="DisplayLanguage">
<option style='display: none'></option>
<option value="zh-cn">简体中文</option>
<option value="en-us">English</option>
</select>
</div>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<span onclick="mdui.snackbar({message: getLanguageText('MinimiseDefaultLabelHelp')})">
<a id="MinimiseDefaultLabel"></a>
<i class="mdui-icon material-icons mdui-ripple">help_outline</i>
</span>
<label class="mdui-switch mdui-float-right">
<input id="MinimiseDefault" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="EchoCancellationLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="EchoCancellation" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<span onclick="mdui.snackbar({message: getLanguageText('DisableRedirectJoinLabelHelp')})">
<a id="DisableRedirectJoinLabel"></a>
<i class="mdui-icon material-icons mdui-ripple">help_outline</i>
</span>
<label class="mdui-switch mdui-float-right">
<input id="DisableRedirectJoin" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<span onclick="mdui.snackbar({message: getLanguageText('PasswordProtectedRoomLabelHelp')})">
<a id="PasswordProtectedRoomLabel"></a>
<i class="mdui-icon material-icons mdui-ripple">help_outline</i>
</span>
<label class="mdui-switch mdui-float-right">
<input id="PasswordProtectedRoom" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="WaitForLoaddingLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="WaitForLoadding" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<button class="mdui-btn" onclick="checkUpdate()" id="CheckUpdateLabel"></button>
</div>
</div>
</div>
</div>
<div class="mdui-col-md-6 mdui-col-sm-12">
<div class="mdui-card" style="padding: 10px">
<div class="mdui-card-primary">
<div class="mdui-card-primary-title" id="ExperimentalFeature"></div>
</div>
<div class="mdui-card-content" style="padding-top: 0px">
<div class="mdui-clearfix mdui-p-t-2">
<a id="SkipIntroLabel"></a>
<a>,</a>
<a id="SkipIntroLengthLabel"></a>
<span class="mdui-textfield">
<input id="SkipIntroLength" style="display: inline-block; width: 3em;"
class="mdui-textfield-input" type="text" placeholder="0"
onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
</span>
<a id="SkipIntroSecondLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="SkipIntro" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="EasyShareLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="EasyShare" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="SuperEasyShareLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="SuperEasyShare" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="DisableNativeM3u8PlayerLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="DisableNativeM3u8Player" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="EnableTextMessageLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="EnableTextMessage" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div class="mdui-clearfix mdui-p-t-2">
<a id="EnableMiniBarLabel"></a>
<label class="mdui-switch mdui-float-right">
<input id="EnableMiniBar" type="checkbox">
<span class="mdui-switch-icon"></span>
</label>
</div>
<div id="voicePannel" class="mdui-clearfix mdui-p-t-2">
<div>
<label id="voiceAlertLabel" class="mdui-float-left">
开启真人语音播报后,房间内的文字消息将会通过AI技术,模拟真人语音播报。
注意:AI语音的生成需要一定的时间,一条消息发送最长需要等待10秒,单条消息超过10个字就不会使用AI语音了。
<br><br>
<h3>该功能内测中。有问题欢迎加QQ群反馈:204015847 </h3>
<h3>请录制10秒左右没有背景噪音的人声。</h3>
</label>
<label id="voiceIdLabel" class="mdui-float-left">
没有真人语音角色
</label>
<div class="mdui-float-right">
<label class="mdui-float-left" id="voiceRecordSeconds"></label>
<button class="mdui-btn-raised mdui-btn mdui-color-theme-accent"
id="voiceRecordBtn">录制语音角色</button>
<button class="mdui-btn-raised mdui-btn mdui-color-theme-accent"
id="voiceDeleteBtn">删除语音角色</button>
</div>
<script>
let startRecordTime = undefined;
let endRecordTime = undefined;
const voiceRecordBtn = document.getElementById('voiceRecordBtn')
voiceRecordBtn.onclick = startRecording;
document.getElementById('voiceDeleteBtn').onclick = function () {
setStorageValue('PublicReechoVoiceId', "")
}
let mediaRecorder;
let audioChunks = [];
async function startRecording() {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = event => {
audioChunks.push(event.data);
};
mediaRecorder.onstop = convertToBase64;
mediaRecorder.start();
startRecordTime = new Date().getTime();
endRecordTime = undefined;
voiceRecordBtn.innerText = '停止录制并创建语音角色';
voiceRecordBtn.onclick = stopRecording;
}
function stopRecording() {
mediaRecorder.stop();
endRecordTime = new Date().getTime();
mediaRecorder.stream.getTracks().forEach(track => track.stop()); // Stop each track to release the microphone
mediaRecorder = undefined;
voiceRecordBtn.innerText = '录制语音角色';
voiceRecordBtn.onclick = startRecording;
}
function convertToBase64() {
const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
const reader = new FileReader();
reader.readAsDataURL(audioBlob);
reader.onloadend = () => {
const base64String = reader.result;
console.log(base64String); // This is your base64-encoded string
// base64String smaller than 5MB
if (base64String.length > 5 * 1024 * 1024) {
document.getElementById('voiceRecordSeconds').innerText = '录制的语音文件过大,请重新录制';
return;
}
const recordDuration = (endRecordTime - startRecordTime) / 1000
if (recordDuration < 2.5) {
document.getElementById('voiceRecordSeconds').innerText = '录制的语音文件过短,请重新录制';
return;
}
document.getElementById('voiceRecordSeconds').innerText = "录音长度" + (endRecordTime - startRecordTime) / 1000 + '秒, 上传中';
const url = "https://vt.panghair.com:5000/reecho/new_voice"
const data = {
voiceAudioBase64: base64String,
}
fetch(url, {
method: 'POST',
body: JSON.stringify(data)
}).then(response => response.json()).then(data => {
console.log(data)
const voiceId = data.voiceId
setStorageValue('PublicReechoVoiceId', voiceId)
}).catch((error) => {
console.error('Error:', error);
});
};
audioChunks = [];
}
</script>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var DisplayLanguageSelect = undefined;
setInterval(() => {
if (DisplayLanguageSelect == undefined) {
DisplayLanguageSelect = new mdui.Select(document.querySelector('#DisplayLanguage'))
}
}, 500);
updateDisplayLanguage();
function checkBoxChanged(e) {
console.log(e.target.id);
let value = e.target.checked;
if (e.target.id == "DisplayLanguage" || e.target.id == "SkipIntroLength") {
value = e.target.value;
}
window.postMessage(
{
type: 15,
source: "VideoTogether",
data: {
key: e.target.id,
value: value
}
}, "*")
}
function setStorageValue(key, value) {
window.postMessage(
{
type: 15,
source: "VideoTogether",
data: {
key: key,
value: value
}
}, "*")
}
document.querySelector("#MinimiseDefault").addEventListener("change", checkBoxChanged);
document.querySelector("#DisableRedirectJoin").addEventListener("change", checkBoxChanged);
document.querySelector("#PasswordProtectedRoom").addEventListener("change", checkBoxChanged);
document.querySelector("#EchoCancellation").addEventListener("change", checkBoxChanged);
document.querySelector("#DisplayLanguage").addEventListener("change", checkBoxChanged);
document.querySelector("#WaitForLoadding").addEventListener("change", checkBoxChanged);
document.querySelector("#SkipIntro").addEventListener("change", checkBoxChanged);
document.querySelector("#EasyShare").addEventListener("change", checkBoxChanged);
document.querySelector("#SuperEasyShare").addEventListener("change", checkBoxChanged);
document.querySelector("#DisableNativeM3u8Player").addEventListener("change", checkBoxChanged);
document.querySelector("#SkipIntroLength").addEventListener("input", checkBoxChanged);
for (let i in settingItems) {
let item = settingItems[i]
document.querySelector(`#${item.key}`).addEventListener("change", checkBoxChanged);
}
// Dark Mode
var body = document.querySelector("body");
var button = document.getElementById("brightness");
button.addEventListener("click", function () {
var isDark = body.classList.contains("mdui-theme-layout-dark");
if (isDark) {
body.classList.remove("mdui-theme-layout-dark");
body.classList.remove("mdui-theme-layout-auto");
}
else {
body.classList.add("mdui-theme-layout-dark");
body.classList.remove("mdui-theme-layout-auto");
}
});
function sendMessageToTop(type, data) {
window.top.postMessage({
source: "VideoTogether",
type: type,
data: data
}, "*")
}
function checkUpdate() {
sendMessageToTop(15, { key: "PublicVtVersion", value: Date.now() });
mdui.snackbar({ message: getLanguageText('CheckUpdateSucc') })
}
function updateInnerText(element, text) {
try {
if (element.innerText != text) {
element.innerText = text;
}
} catch (e) {
}
}
</script>
<!-- MDUI JavaScript -->
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/mdui/1.0.2/js/mdui.min.js"></script>
<style>
.mdui-card {
border-radius: 12px;
box-shadow: 0 2px 2px 0 rgb(0 0 0 / 16%), 0 1px 5px 0 rgb(0 0 0 / 16%);
margin-top: 10px;
}
.mdui-menu {
border-radius: 12px;
}
.mdui-snackbar {
border-radius: 12px;
}
.mdui-select-menu {
border-radius: 12px;
}
</style>
</body>
</html>