-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
648 lines (532 loc) · 26 KB
/
main.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=M+PLUS+Rounded+1c" rel="stylesheet">
<title>Jamakssi: jimakuChan fork</title>
<style type="text/css">
@font-face {
font-family: 'NanumSquareRound';
src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/NanumSquareRound.woff') format('woff');
font-weight: normal;
font-style: normal;
}
button,
input,
select,
textarea {
/* font-family : inherit; */
/* font-family: 'メイリオ', Meiryo,sans-serif; */
/* font-size : 300%; */
/* color : black; */
font-weight: 0;
/*text-align : center; /* left, center, right */
vertical-align: top;
/* top, middle, bottom */
-webkit-text-stroke-color: rgb(21, 0, 141);
-webkit-text-stroke-width: 0px;
}
html {
height: 100%;
width: 100%;
}
body {
height: 100%;
width: 100%;
margin: 0;
overflow: hidden;
font-family: 'M PLUS Rounded 1c', sans-serif;
/* font-family:'07NikumaruFont'; */
}
table {
width: 100%;
overflow: hidden;
/* table-layout: fixed; */
}
table.btm_table {
position: absolute;
/* bottom:0; */
}
table td {
/*word-break: break-all;*/
overflow-wrap: break-word;
}
</style>
<style>
/* prepare the selectors to add a stroke to */
.stroke-single-imb {
/* position: absolute; */
left: 0;
right: 0;
margin: 0;
margin-left: 5px;
/* -webkit-text-stroke: 0px #0000FF; */
}
.stroke-single-bg {
position: absolute;
left: 0;
right: 0;
margin: auto;
margin-left: 5px;
/* -webkit-text-stroke: 3px #FF0000; */
}
/* add a single stroke */
.stroke-single-fg {
position: absolute;
left: 0;
right: 0;
margin: auto;
margin-left: 5px;
/* -webkit-text-stroke: 0px #FFFFFF; */
}
</style>
<script>
// URLパラメータ取得用関数 ---------------------------
function getParam(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&]*)|&|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// 一定時間変化がなかったら消す ------------------------------------
var fn_del = function () {
document.getElementById('speech_text-imb').innerHTML = '';
document.getElementById('speech_text-bg').innerHTML = '';
document.getElementById('speech_text-fg').innerHTML = '';
document.getElementById('trans_text-imb').innerHTML = '';
document.getElementById('trans_text-bg').innerHTML = '';
document.getElementById('trans_text-fg').innerHTML = '';
document.getElementById('trans_text2-imb').innerHTML = '';
document.getElementById('trans_text2-bg').innerHTML = '';
document.getElementById('trans_text2-fg').innerHTML = '';
// 各フラグをリセット
isSpeechRecognitionComplete = false;
isTextTranslation1Complete = false;
isTextTranslation2Complete = false;
};
// URLからの値読み込み(削除タイマー) -------------------
var timer = getParam('timer');
//////////////////////////////////////////////////////////
// URLからの値読み込み -------------------
var arg_recog = getParam('recog');
var arg_trans = getParam('trans');
var arg_trans2 = getParam('trans2');
/////////////////////////////////////////////////////////
// 翻訳API用設定 ---------------------------
if (arg_trans != null) var request = new XMLHttpRequest();
if (arg_trans2 != null) var request2 = new XMLHttpRequest();
// 翻訳用設定 ---------------------------
var trans_sourcelang = 'ja';
var trans_destlang = 'en';
var trans2_destlang = '';
var transService = getParam('transService');
var papagoURL = getParam('papago_url');
var deeplxURL = getParam('deeplx_url');
var gas_key = getParam('gas_key');
var TRANS_URL = 'https://script.google.com/macros/s/' + gas_key + '/exec';
var query = ''
// その他の設定 -----------------------
var anti_sexual = getParam('anti_sexual');
// 一定時間認識結果がなかったら,そこで認識終了 --------------------
var short_pause = getParam('short_pause');
// if(short_pause == null) {
// short_pause = 0;
// }
var stop_recog;
var id_stop_recog;
var count = 0;
// URLから Bad/Good 単語リストをリスト形式で読み込む -----------------------
let languageId = arg_recog;
const baseURL = "https://cdn.jsdelivr.net/gh/sayonari/goodBadWordlist@main/";
const badListPath = `/BadList.txt`; // 禁止ワードリストのパス
const goodListPath = `/GoodList.txt`; // 許可ワードリストのパス
var badWords_forRecog = [];
var goodWords_forRecog = [];
console.log("url: " + baseURL + languageId + badListPath);
if (anti_sexual !== 'false') {
// 禁止ワードリストを読み込む
fetch(baseURL + languageId + badListPath)
.then(r => r.text())
.then(t => {
badWords_forRecog = t.split("\n").filter(Boolean);
console.log("loaded Bad Words num: " + badWords_forRecog.length);
});
// 許可ワードリストを読み込む
fetch(baseURL + languageId + goodListPath)
.then(r => r.text())
.then(t => {
goodWords_forRecog = t.split("\n").filter(Boolean);
});
}
// 音声認識本体 /////////////////////////////////////////////////
window.SpeechRecognition = window.SpeechRecognition || webkitSpeechRecognition;
// 音声認識用設定 ----------------------
var recognition = new webkitSpeechRecognition();
recognition.lang = 'ko';
recognition.interimResults = true;
// recognition.continuous = true;
var recog_text = '';
var recog_IM_text = '';
var recog_conf = 0;
var trans_text = '';
var trans2_text = '';
var my_count = count;
count = count + 1;
// その他設定 ----------------------------
var isSpeechRecognitionComplete = false;
var isTextTranslation1Complete = false;
var isTextTranslation2Complete = false;
function shouldClearText() {
// Check if each process is enabled and if it's complete
var recogComplete = arg_recog != null ? isSpeechRecognitionComplete : true;
var trans1Complete = arg_trans != null ? isTextTranslation1Complete : true;
var trans2Complete = arg_trans2 != null ? isTextTranslation2Complete : true;
return recogComplete && trans1Complete && trans2Complete;
}
stop_recog = function () {
console.log("stop by short pause!");
recognition.stop();
};
///////////////////////////////////////////////////////////
// 各種イベントへの対応 ---------------------------------
// 音声・認識 開始
recognition.onstart = () => {
console.log("onstart cnt:" + String(my_count));
}
recognition.onaudiostart = () => {
console.log("onaudiostart cnt:" + String(my_count));
}
recognition.onsoundstart = () => {
console.log("onsoundstart cnt:" + String(my_count));
}
recognition.onspeechstart = () => {
console.log("onspeechstart cnt:" + String(my_count));
}
// 音声・認識 終了
recognition.onspeechend = () => {
console.log("onspeechend cnt:" + String(my_count));
}
recognition.onsoundend = () => {
console.log("onsoundend cnt:" + String(my_count));
}
recognition.onaudioend = () => {
console.log("onaudioend cnt:" + String(my_count));
}
recognition.onend = () => {
console.log("onend cnt:" + String(my_count));
recognition.start();
my_count = count;
count = count + 1;
}
// エラー等
recognition.onerror = () => {
console.log("onerror cnt:" + String(my_count));
recognition.stop();
}
recognition.onnomatch = () => {
console.log("onnomatch cnt:" + String(my_count));
recognition.stop();
}
// 言語設定 ----------------------------
if (arg_recog != null) {
recognition.lang = arg_recog;
trans_sourcelang = recognition.lang;
}
if (arg_trans != null) {
trans_destlang = arg_trans;
}
if (arg_trans2 != null) {
trans2_destlang = arg_trans2;
}
// 認識結果が返ってきたとき ------------------
recognition.onresult = async function (event) {
var results = event.results;
for (var i = event.resultIndex; i < results.length; i++) {
console.log("onresult confidence: " + results[i][0].confidence);
// 認識結果をget (途中結果 or 最終結果) ------------
var recog_text = results[i][0].transcript;
// #############################################################
// 危険単語を検知して,結果を***に置き換える #########################
// 保護する単語を一時的なプレースホルダーに置き換える --------
goodWords_forRecog.forEach((word, index) => {
let placeholder = `{{GOOD_WORD_${index}}}`;
recog_text = recog_text.replace(new RegExp(word, "gi"), placeholder);
});
// 認識結果の中の危険単語を検知して,結果を***に置き換える ---
if (anti_sexual != 'false') {
badWords_forRecog.forEach(word => {
let regex = new RegExp(word, "gi");
recog_text = recog_text.replace(regex, "*".repeat(word.length));
});
}
// console.log("bad:" + badWords_forRecog.length);
// console.log(badWords_forRecog, goodWords_forRecog);
// 一時的なプレースホルダーを保護する単語に戻す -------------
goodWords_forRecog.forEach((word, index) => {
let placeholder = `{{GOOD_WORD_${index}}}`;
recog_text = recog_text.replace(new RegExp(placeholder, "g"), word);
});
// #############################################################
// #################################################################
// 認識最終結果が来たら ###############################################
if (results[i].isFinal) {
// 認識結果を表示する ---------------------
document.getElementById('speech_text-imb').innerHTML = recog_text;
document.getElementById('speech_text-bg').innerHTML = recog_text;
document.getElementById('speech_text-fg').innerHTML = recog_text;
isSpeechRecognitionComplete = true; // フラグを更新
// すべての処理が完了した後に内容を消す
if (timer != null && shouldClearText()) {
setTimeout(fn_del, timer);
}
if (deeplxURL != null || papagoURL != null) {
// 翻訳1言語目
if (arg_trans != null) {
const trans1 = await fetch(transService === "papago" ? papagoURL : deeplxURL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
text: recog_text,
source_lang: trans_sourcelang,
target_lang: trans_destlang
})
});
if (trans1.ok && trans1.status === 200) {
var jsonResponse = await trans1.json();
var responseText1 = jsonResponse.data;
document.getElementById('speech_text-imb').innerHTML = recog_text;
document.getElementById('speech_text-bg').innerHTML = recog_text;
document.getElementById('speech_text-fg').innerHTML = recog_text;
document.getElementById('trans_text-imb').innerHTML = responseText1;
document.getElementById('trans_text-bg').innerHTML = responseText1;
document.getElementById('trans_text-fg').innerHTML = responseText1;
isTextTranslation1Complete = true; // フラグを更新
// すべての処理が完了した後に内容を消す
if (timer != null && shouldClearText()) {
setTimeout(fn_del, timer);
}
}
}
if (arg_trans2 != null) {
const trans2 = await fetch(transService === "papago" ? papagoURL : deeplxURL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
text: recog_text,
source_lang: trans_sourcelang,
target_lang: trans2_destlang
})
});
if (trans2.ok && trans2.status === 200) {
var jsonResponse = await trans2.json();
var responseText2 = jsonResponse.data;
document.getElementById('speech_text-imb').innerHTML = recog_text;
document.getElementById('speech_text-bg').innerHTML = recog_text;
document.getElementById('speech_text-fg').innerHTML = recog_text;
document.getElementById('trans_text2-imb').innerHTML = responseText2;
document.getElementById('trans_text2-bg').innerHTML = responseText2;
document.getElementById('trans_text2-fg').innerHTML = responseText2;
isTextTranslation2Complete = true; // フラグを更新
// すべての処理が完了した後に内容を消す
if (timer != null && shouldClearText()) {
setTimeout(fn_del, timer);
}
}
}
} else {
document.getElementById('speech_text-imb').innerHTML = recog_text;
document.getElementById('speech_text-bg').innerHTML = recog_text;
document.getElementById('speech_text-fg').innerHTML = recog_text;
}
}
// #################################################################
// 認識途中結果が来たら ###############################################
else {
// 「ショートポースが来たら,音声認識を強制的に止める」のタイムアウト処理を削除する -------
if (short_pause != null) clearTimeout(id_stop_recog);
// ショートポーズストップ用タイムアウト
if (short_pause != null) id_stop_recog = setTimeout(stop_recog, short_pause);
// 認識結果を変数に格納
recog_IM_text = recog_text;
// 画面表示テキスト更新 ---
if (recog_IM_text != "") {
document.getElementById('speech_text-imb').innerHTML = "<< " + recog_IM_text + " >>";
document.getElementById('speech_text-bg').innerHTML = "<< " + recog_IM_text + " >>";
document.getElementById('speech_text-fg').innerHTML = "<< " + recog_IM_text + " >>";
}
}
}
}
recognition.start();
console.log("recog start: cnt:" + String(my_count));
</script>
</head>
<body>
<div class="big" id="result_text">
<table id="text_table" class="btm_table" style="overflow:hidden;">
<tr>
<td id="tbl_td" align="center" valign='bottom'>
<div id="speech_text">
<div class="stroke-single-bg" id="speech_text-bg"></div>
<div class="stroke-single-fg" id="speech_text-fg"></div>
<div class="stroke-single-imb" id="speech_text-imb"></div>
</div>
<div id="trans_text">
<div class="stroke-single-bg" id="trans_text-bg"></div>
<div class="stroke-single-fg" id="trans_text-fg"></div>
<div class="stroke-single-imb" id="trans_text-imb"></div>
</div>
<div id="trans_text2">
<div class="stroke-single-bg" id="trans_text2-bg"></div>
<div class="stroke-single-fg" id="trans_text2-fg"></div>
<div class="stroke-single-imb" id="trans_text2-imb"></div>
</div>
</td>
</tr>
</table>
</div>
<!-- 翻訳回数管理 -->
<div id="translationCount" style="display: none;"></div>
</body>
<script type="text/javascript">
// バージョン情報の表示 ---------------------------------
const SoftwareTitle = "Jamakssi: jimakuChan fork";
const SoftwareVersion = "1.0.0";
const SoftwareDeveloper = "[made by: sayonari, aeongdesu]"
const speech_text_first = "[" + SoftwareTitle + " (Ver:" + SoftwareVersion + ")" + "]";
document.getElementById('speech_text-bg').innerHTML = speech_text_first;
document.getElementById('speech_text-fg').innerHTML = speech_text_first;
document.getElementById('speech_text-imb').innerHTML = speech_text_first;
const trans1_text_first = SoftwareDeveloper;
document.getElementById('trans_text-bg').innerHTML = trans1_text_first
document.getElementById('trans_text-fg').innerHTML = trans1_text_first
document.getElementById('trans_text-imb').innerHTML = trans1_text_first
const trans2_text_first = "[번역2 결과 예시]";
document.getElementById('trans_text2-bg').innerHTML = trans2_text_first;
document.getElementById('trans_text2-fg').innerHTML = trans2_text_first;
document.getElementById('trans_text2-imb').innerHTML = trans2_text_first;
// 対象言語を利用しない場合,初期表示文の削除 /////
if (getParam('trans') == null) {
document.getElementById('trans_text-bg').innerHTML = '';
document.getElementById('trans_text-fg').innerHTML = '';
document.getElementById('trans_text-imb').innerHTML = '';
}
if (getParam('trans2') == null) {
document.getElementById('trans_text2-bg').innerHTML = '';
document.getElementById('trans_text2-fg').innerHTML = '';
document.getElementById('trans_text2-imb').innerHTML = '';
}
// 表示スタイル変更 ---------------------------------
if (getParam('bgcolor') != null) {
document.bgColor = getParam('bgcolor');
}
if (getParam('v_align') == "top") {
document.getElementById("text_table").style.bottom = -1;
} else if (getParam('v_align') == "bottom") {
document.getElementById("text_table").style.bottom = 0;
}
if (getParam('textAlign') != null) {
document.getElementById("text_table").style.textAlign = getParam('textAlign');
document.getElementById("tbl_td").style.textAlign = getParam('textAlign');
if (getParam('textAlign') == "right") {
document.getElementById("text_table").style.direction = "rtl";
document.getElementById("tbl_td").style.direction = "rtl";
document.body.style.direction = "rtl";
}
}
if (getParam('whiteSpace') != null) {
document.getElementById("text_table").style.whiteSpace = getParam('whiteSpace');
}
// 高さ合わせ用フォント(色を背景色と同じにする) ############################################
// 音声認識テキスト -------
if (getParam('bgcolor') != null) {
document.getElementById("speech_text-imb").style.webkitTextStrokeColor = getParam('bgcolor');
document.getElementById("speech_text-imb").style.color = getParam('bgcolor');
}
if (getParam('st_width1') != null) {
document.getElementById("speech_text-imb").style.webkitTextStrokeWidth = getParam('st_width1') + 'pt';
}
// 翻訳結果テキスト -------
if (getParam('bgcolor') != null) {
document.getElementById("trans_text-imb").style.webkitTextStrokeColor = getParam('bgcolor');
document.getElementById("trans_text-imb").style.color = getParam('bgcolor');
}
if (getParam('st_width2') != null) {
document.getElementById("trans_text-imb").style.webkitTextStrokeWidth = getParam('st_width2') + 'pt';
}
// 翻訳結果テキスト(第2言語) -------
if (getParam('bgcolor') != null) {
document.getElementById("trans_text2-imb").style.webkitTextStrokeColor = getParam('bgcolor');
document.getElementById("trans_text2-imb").style.color = getParam('bgcolor');
}
if (getParam('st_width3') != null) {
document.getElementById("trans_text2-imb").style.webkitTextStrokeWidth = getParam('st_width3') + 'pt';
}
// 表示設定 ############################################
// 全体共通 ----------------
// 音声認識結果 ----------------
if (getParam('speech_text_font') != null) {
document.getElementById("speech_text").style.fontFamily = "'" + getParam('speech_text_font') + "'";
}
if (getParam('size1') != null) {
document.getElementById("speech_text").style.fontSize = getParam('size1') + 'pt';
}
if (getParam('weight1') != null) {
document.getElementById("speech_text").style.fontWeight = getParam('weight1');
}
if (getParam('color1') != null) {
document.getElementById("speech_text-fg").style.color = getParam('color1');
}
if (getParam('st_color1') != null) {
document.getElementById("speech_text-bg").style.webkitTextStrokeColor = getParam('st_color1');
}
if (getParam('st_width1') != null) {
document.getElementById("speech_text-bg").style.webkitTextStrokeWidth = getParam('st_width1') + 'pt';
}
// 翻訳結果テキスト ----------------
if (getParam('trans_text_font') != null) {
document.getElementById("trans_text").style.fontFamily = "'" + getParam('trans_text_font') + "'";
}
if (getParam('size2') != null) {
document.getElementById("trans_text").style.fontSize = getParam('size2') + 'pt';
}
if (getParam('weight2') != null) {
document.getElementById("trans_text").style.fontWeight = getParam('weight2');
}
if (getParam('color2') != null) {
document.getElementById("trans_text-fg").style.color = getParam('color2');
}
if (getParam('st_color2') != null) {
document.getElementById("trans_text-bg").style.webkitTextStrokeColor = getParam('st_color2');
}
if (getParam('st_width2') != null) {
document.getElementById("trans_text-bg").style.webkitTextStrokeWidth = getParam('st_width2') + 'pt';
}
// 翻訳結果テキスト(第2言語) -----------
if (getParam('trans_text2_font') != null) {
document.getElementById("trans_text2").style.fontFamily = "'" + getParam('trans_text2_font') + "'";
}
if (getParam('size3') != null) {
document.getElementById("trans_text2").style.fontSize = getParam('size3') + 'pt';
}
if (getParam('weight3') != null) {
document.getElementById("trans_text2").style.fontWeight = getParam('weight3');
}
if (getParam('color3') != null) {
document.getElementById("trans_text2-fg").style.color = getParam('color3');
}
if (getParam('st_color3') != null) {
document.getElementById("trans_text2-bg").style.webkitTextStrokeColor = getParam('st_color3');
}
if (getParam('st_width3') != null) {
document.getElementById("trans_text2-bg").style.webkitTextStrokeWidth = getParam('st_width3') + 'pt';
}
</script>
</html>