-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
565 lines (374 loc) · 25.2 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=0">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/w3.css">
<link rel="stylesheet" href="assets/css/w3-theme-black.css">
<link rel="stylesheet" href="assets/css/main.css">
<style>
* {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.footer {
background-color: #000000;
padding: 10px;
text-align: center;
padding: 14px 16px;
font-size: 10px;
color: rgb(167, 167, 167);
}
.center-content {
max-width: 1200px;
margin: auto;
}
.slider {
-webkit-appearance: none;
width: 28px;
height: 10px;
background: #0a1d3f;
outline: none;
}
.slider:hover {
width: 70px;
height: 16px;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 4px;
height: 16px;
background: #ffffff;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 4px;
height: 16px;
background: #ffffff;
cursor: pointer;
}
.hide {
display: none;
}
.hideDiv:hover + .hide {
display: inline-table;
color:white;
}
canvas {
border: 1px inset rgb(46, 46, 46);
-webkit-transition: all 1s;
}
</style>
<title>Speech Analyzer</title>
</head>
<body class="w3-black">
<div class="topnav">
<a href="https://github.com/tabahi/WebSpeechAnalyzer">Github</a>
</div>
<div class="w3-container w3-center w3-opacity">
<h5 id="app_title">Web Speech Analyzer</h5>
</div>
<div class="w3-container w3-bottombar w3-border-dark-gray"> <!-- Main body container -->
<div class="w3-row w3-center w3-animate-zoom" id="canvas_div" style="display: none;">
<canvas id="SpectrumCanvas" width="1200" height="300" ></canvas>
</div>
<div class="w3-row w3-center">
<p id="msg">Loading...</p>
</div>
<!-- Settings Modal -->
<div id="settings_model" class="w3-modal w3-animate-opacity">
<div class="w3-modal-content w3-card-4 w3-animate-zoom">
<header class="w3-container w3-theme-d1">
<span onclick="document.getElementById('settings_model').style.display='none'"
class="w3-button w3-red w3-xlarge w3-display-topright">×</span>
<h2>Settings</h2>
</header>
<div class="w3-container w3-theme-d2 w3-small"> <!-- Spectrum settings-->
<div class="w3-row w3-padding-16">
<h5>Mode</h5>
<div class="w3-col m2">
<input class="w3-check" id="offline" title="Process files in the background without playing it out loud on the speakers. Better for quick processing." type="checkbox">
<label for="offline" >Silent play</label>
</div>
<div class="w3-col m2">
<input class="w3-check" id="plot_enable" title="Enable or disable real-time plotting. Uncheck for quick processing of larger files." type="checkbox" checked>
<label for="plot_enable" >Enable plot</label>
</div>
<div class="w3-col m2">
<label>Input</label>
<select class="w3-select w3-dark-input" id="spec_type" style="width:90%">
<option value="1" selected>Mel-bands</option>
<option value="2">Power</option>
<option value="3">DFFT</option>
</select>
</div>
<div class="w3-col m2">
<label>Output level</label>
<select class="w3-select w3-dark-input" id="output_level" style="width:90%">
<option value="1">1. Bars</option>
<option value="2">2. Spectrum</option>
<option value="3">3. Segments</option>
<option value="4">4. Segment Formants</option>
<option value="5">5. Segment Features [ML]</option>
<option value="10">10. Syllable Formants [ML]</option>
<option value="11">11. Distributions 264x [ML]</option>
<option value="12">12. Syllable Curves 23x [ML]</option>
<option value="13" selected>13. Syllable 53x [ML]</option>
</select>
</div>
</div>
</div>
<div class="w3-container w3-theme-d3 w3-small"> <!-- Speech segmentation settings-->
<div class="w3-row w3-padding-16">
<h5>Segmentation</h5>
<div class="w3-col m2">
<label>Pause Length (ms)</label>
<input class="w3-input w3-dark-input" type="number" id="pause_length" placeholder="250" style="width:90%" title="Duration of pause (in milliseconds) at which the current speech segment is truncated and a new segment is started.">
</div>
<div class="w3-col m2">
<label>Min Length (ms)</label>
<input class="w3-input w3-dark-input" type="number" id="min_seg_length" placeholder="250" style="width:90%" title="Minimum duration of a speech segment (in milliseconds). Shorter than this speech segments will be ignored. Set a smaller value for fast languages e.g., espanol">
</div>
<div class="w3-col m2">
<input class="w3-check" id="auto_noise_gate" title="If enabled, noise gate will automatically adjust the input volume threshold to separate silence from voice. If disabled, Voiced Min and Max will be used." type="checkbox">
<label for="auto_noise_gate" title="If enabled, noise gate will automatically adjust the input volume threshold to separate silence from voice. If disabled, Voiced Min and Max will be used.">Auto Noise-Gate</label>
</div>
<div class="w3-col m2">
<label>Voiced Min</label>
<input class="w3-input w3-dark-input" type="number" id="voiced_min_dB" placeholder="10" style="width:90%" title="Minimum amplitude for voiced segments in dB. Any sound below this amplitude limit will be ignored as silence.">
</div>
<div class="w3-col m2">
<label>Voiced Max</label>
<input class="w3-input w3-dark-input" type="number" id="voiced_max_dB" placeholder="150" style="width:90%" title="Maximum amplitude for voiced segments in dB. Any sound above this amplitude limit will be floored to this value.">
</div>
</div>
</div>
<div class="w3-container w3-theme-d4 w3-small"> <!-- Plot settings-->
<div class="w3-row w3-padding-16">
<h5>Plotting</h5>
<div class="w3-col m2">
<label>Plot Latency</label>
<input class="w3-input w3-dark-input" type="number" id="plot_lag" placeholder="5" style="width:90%" title="Set a lag in plot to avoid jitters caused by the plotting process. High latency in the rendering of plot decreases the jitter in audio playback. This only applies to the real-time plotting of Spectrum-Type or Bar-Type plotting. Segments and formants are plotted whenever there is a pause.">
</div>
<div class="w3-col m2">
<label>Length</label>
<input class="w3-input w3-dark-input" type="number" id="plot_len" placeholder="300" style="width:90%" title="Number of frames to plot on the spectrum canvas. In seconds, the total canvas size is Window Step size (ms) * 1000 * this Length.">
</div>
</div>
</div>
<div class="w3-container w3-theme-d1 w3-small"> <!-- Sampling settings-->
<div class="w3-row w3-padding-16">
<h5>Sampling</h5>
<div class="w3-col m2">
<label>F min (Hz)</label>
<input class="w3-input w3-dark-input" type="number" id="f_min" placeholder="50" style="width:90%" title="Minimum frequency of Mel filter.">
</div>
<div class="w3-col m2">
<label>F max (Hz)</label>
<input class="w3-input w3-dark-input" type="number" id="f_max" placeholder="4000" style="width:90%" title="Maximum frequency of FFT, power spectrum amd Mel-filters.">
</div>
<div class="w3-col m2">
<label>Width (ms)</label>
<input class="w3-input w3-dark-input" type="number" id="window_width" placeholder="40" style="width:90%" title="Window size in milliseconds for sampling.">
</div>
<div class="w3-col m2">
<label>Step (ms)</label>
<input class="w3-input w3-dark-input" type="number" id="window_step" placeholder="25" style="width:90%" title="Step size for sampling window in milliseconds. Keep it same as window width for 0% overlap, or half the size of window width to create 50% overlapping windows. Setting it higher than the window width will skip samples in between the steps.">
</div>
</div>
<div class="w3-row w3-padding-16">
<div class="w3-col m2">
<label>FFT bins</label>
<input class="w3-input w3-dark-input" type="number" id="N_fft_bins" placeholder="128" style="width:90%" title="Number of FFT bins within 0Hz to F_max range. This is not the FFT size, because FFT size depends on the sampling rate of the browser (usually 48kHz). This variable only sets the number of bins within the 0Hz-F_max frequency range. F_min is ignored for FFT bins.">
</div>
<div class="w3-col m2">
<label>Mel filters</label>
<input class="w3-input w3-dark-input" type="number" id="N_mel_bins" placeholder="64" style="width:90%" title="Number of Mel filters (bins). Keep it less or equal to FFT bins. F_min is the starting range for first Mel-filter, F_max is the end frequency of the last mel filter.">
</div>
<div class="w3-col m2">
<label>Pre Gain</label>
<input class="w3-input w3-dark-input" type="number" id="pre_norm_gain" placeholder="1000" style="width:90%" title="Preprocessing Gain multiplier for FFT bins to avoid loosing floating point precision and the color brightness of spectrum.">
</div>
<div class="w3-col m2">
<label>High-freq-emphasis</label>
<input class="w3-input w3-dark-input" type="number" step="0.01" id="high_f_emph" placeholder="0.1" style="width:90%" title="Pre-emphasis constant. High frequencies have low amplitude, this increases their amplitude to increase their significance on the spectrum. By this equation, higher the frequency, higher will be the emphasis factor: out_amp = real_amp + (real_amp * f_mel_bin * high_f_emph)">
</div>
</div>
</div>
<div class="w3-container w3-theme-d1 w3-padding">
<button class="w3-button w3-right w3-blue-grey w3-border w3-round-large w3-margin-left" onclick="document.getElementById('settings_model').style.display='none'" >Close</button>
<button class="w3-button w3-right w3-amber w3-border w3-round-large w3-margin-right" onclick="SA.update_settings()">Set</button>
</div>
</div>
</div>
<div id="speedometers_div" class="center-content w3-row w3-center w3-padding-small w3-animate-top" style="display: none;"></div>
<div class="w3-row w3-center w3-padding-small"> <!-- Buttons -->
<input type="button" id="demo_button" value="Demo" class="w3-button w3-wide w3-border w3-border-amber w3-padding" disabled>
<input type="button" id="mic_button" value="Mic" class="w3-button w3-wide w3-border w3-border-amber w3-padding" disabled>
<button onclick="document.getElementById('settings_model').style.display='block'" class="w3-button w3-small w3-border w3-border-brown" id="settings_button" disabled>Settings</button>
<input class="w3-check w3-margin-left" id="pred_emo_en" onchange="SA.prediction_meter_enable(this.checked)" type="checkbox" title="Currently only works at output level: Syllable 53x." checked hidden> <label for="pred_emo_en" title="Currently only works at output level: Syllable 53x." id="pred_emo_en_lbl" hidden>Predict Emotion</label>
</div>
<div class="w3-row w3-center w3-padding-small"> <!-- File loading zone -->
<div id="dropZone" class="w3-card-4">
<p>
<label for="filesx" class="w3-hover-text-amber">Load Audio: </label>
<input type="file" id="filesx" name="filesx[]" onchange="SA.readmultifiles(this.files)" multiple="" class="w3-button w3-hover-border-khaki w3-padding" placeholder="Audio files" accept="audio/*" />
<input type="button" id="play_button" value="Play" class="w3-button w3-wide w3-border w3-border-light-blue w3-padding" disabled>
</p>
</div>
</div>
</div> <!-- Main body container ends -->
<div id="dev_div" class="center-content w3-row w3-center w3-padding-32 w3-small" style="display: none;">
<input class="w3-check w3-margin-left" id="data_collect_en" onchange="SA.data_collect_en(this.checked)" type="checkbox" title="Collect output features in browser's memory to download and analyze." > <label for="data_collect_en">Data Collect</label>
<input class="w3-check w3-margin-left" id="ML_train_en" onchange="SA.ML_train_en(this.checked)" type="checkbox" title="Only supports the [ML] output levels" disabled > <label for="ML_train_en" >ML Training </label>
</div>
<div id="data_main_div" class="w3-container w3-border-bottom" style="display: none;"> <!-- DB Table container -->
<div class="center-content w3-row w3-center w3-padding-32" id="table_btns_div">
<h3 class="w3-opacity">Data Collection & Labeling</h3>
<button onclick="document.getElementById('db_settings_model').style.display='block'" class="w3-button w3-tiny w3-border w3-border-gray w3-margin-right">Data settings</button>
<button onclick="SA.refresh_db_table()" class="w3-button w3-tiny w3-border w3-border-yellow w3-margin-left">Refresh</button>
</div>
<!-- DB settings Modal -->
<div id="db_settings_model" class="w3-modal w3-animate-opacity">
<div class="w3-modal-content w3-card-4 w3-animate-zoom">
<header class="w3-container w3-theme-d1">
<span onclick="document.getElementById('db_settings_model').style.display='none'"
class="w3-button w3-red w3-xlarge w3-display-topright">×</span>
<h2>Data Settings</h2>
</header>
<div class="w3-container w3-theme-d2"> <!-- DB settings buttons-->
<div class="w3-row w3-padding-16">
<div class="w3-col m2">
<label>DB ID</label>
<input class="w3-input w3-dark-input" type="number" id="db_id" placeholder='1' value='1' style="width:80%" title='To create multiple databases, use different ID for each one.'>
</div>
<div class="w3-col m4">
<label for="up_data_file" class="w3-margin-left w3-tiny"> Reload Data:</label>
<input type="file" id="up_data_file" name="up_data_file" accept="application/JSON" class="w3-margin-right w3-button w3-tiny" title="Reload the JSON data file that was downloaded from here before.">
</div>
<div class="w3-col m2 w3-tiny">
<button onclick="SA.download_db_table('JSON', document.getElementById('download_only_selected').checked)" class="w3-button w3-border w3-border-gray w3-green">Download JSON</button>
</div>
<div class="w3-col m2 w3-tiny">
<button onclick="SA.download_db_table('CSV', document.getElementById('download_only_selected').checked)" class="w3-button w3-border w3-border-gray w3-green">Download CSV</button>
</div>
</div>
<div class="w3-row w3-padding-16">
<div class="w3-col m2">
<button onclick="SA.clear_db_table()" class="w3-button w3-border w3-border-gray w3-black">Clear all</button>
</div>
<div class="w3-col m2">
<button onclick="SA.clear_labels(false, true)" class="w3-button w3-border w3-border-gray w3-black">Clear Predictions</button>
</div>
<div class="w3-col m2">
<button onclick="SA.clear_labels(false, false)" class="w3-button w3-border w3-border-gray w3-black">Clear Wrong</button>
</div>
<div class="w3-col m2">
<button onclick="SA.clear_labels(true, false)" class="w3-button w3-border w3-border-gray w3-black">Clear Labels</button>
</div>
<div class="w3-col m2 w3-tiny">
<input class="w3-check w3-margin-left" id="download_only_selected" type="checkbox" title='When checked, only the samples with labels from "Class Labels" will be downloaded.' checked> <label for="download_only_selected" >Selected Download</label>
</div>
</div>
</div>
<div class="w3-container w3-theme-d4 "> <!-- DB settings-->
<h5>Select Labels</h5>
<div class="w3-row w3-padding-small">
<div class="w3-col m12">
<label>Class Labels (Array of JSON objects)</label>
<input class="w3-input w3-dark-input" type="text" id="class_labels" placeholder='[{ "emotion": ["A","H","N","S"] }, {"gender": ["M","F"] } , {"spkr": ["*"] } ]'
value='[{ "emotion": ["A","H","N","S","U","T","D","F"] }, {"sex":["F", "M"]}, {"spkr":["*"]}, {"E":["*"]}, {"U":["*"]}]' style="width:90%" title='Enter the possible classes for categorical labels. Format: Array of objects as [{"gender" : ["M", "F"]}, {"label" : ["X", "Y"]}]. To select all possible classes for a label, use * as {"gender" : ["*"]} '>
</div>
</div>
<div class="w3-row w3-padding-small">
<div class="w3-col m12">
<label>Ordinal Labels (Array of Strings)</label>
<input class="w3-input w3-dark-input" type="text" id="ordinal_labels" placeholder='["X", "Y", "Z"]' value='' style="width:90%" title='Independent continuous scale variables between 0 and 1. Format: Array of Strings ["var1", "var2"]'>
</div>
</div>
<div class="w3-row w3-padding-16">
<h5>Parse labels</h5>
<p>Upload a label file. Only the labels prototyped above will be parsed. Use JSON format, where "i" gives the filename followed by labels. Example:
</p>
<pre class="w3-text-amber">[{"i": "file001.wav", "gender": "F", "spkr": 1}, {"i": "file002.wav", "gender": "M", "spkr": 2}]</pre>
<div class="w3-col m3">
<label for="up_labels_file" class="w3-margin-left w3-tiny"> Load Labels:</label>
<input type="file" id="up_labels_file" name="up_labels_file" accept="application/JSON" class="w3-margin-right w3-button w3-tiny">
</div>
</div>
</div>
<div class="w3-container w3-theme-d1 w3-padding">
<button class="w3-button w3-right w3-blue-grey w3-border w3-round-large w3-margin-left" onclick="document.getElementById('db_settings_model').style.display='none'">Close</button>
<button class="w3-button w3-right w3-amber w3-border w3-round-large w3-margin-left" onclick="SA.refresh_db_table()">Set</button>
</div>
</div>
</div>
<!-- DB table div -->
<div class="center-content w3-responsive" id="table_div">
<table class="center w3-table w3-bordered ">
</table>
</div>
<div id="results_div" class="w3-container">
</div>
<!-- ML training buttons div-->
<div class="center-content w3-row w3-center w3-padding-small" id="ML_training_div">
<!--
<h3 class="w3-opacity">ML Training</h3>
<div class="w3-container w3-border w3-border-blue w3-cell w3-cell-middle w3-padding-16">
<h5>YYY</h5>
<div class="w3-row w3-margin-top">
<button onclick="SA.start_nn_training()" class="w3-button w3-tiny w3-border w3-border-indigo">Train</button>
</div>
<div class="w3-row w3-margin-top">
<button onclick="SA.start_nn_prediction()" class="w3-button w3-tiny w3-border w3-border-indigo">Predict</button>
</div>
<div class="w3-row w3-margin-top">
<button onclick="SA.download_nn_model()" class="w3-button w3-tiny w3-border w3-border-deep-purple">Download</button>
</div>
<div class="w3-row w3-margin-top">
<button onclick="console.log('Load '+ 1);" class="w3-button w3-tiny w3-border w3-border-deep-purple">Load</button>
</div>
</div>
-->
</div>
<div id="ML_training_div_modals"></div>
<!-- ML training status text-->
<pre id="nn_msg" class="w3-text-blue w3-wide"></pre>
</div> <!-- DB Table container ends -->
<div class="footer">
<a href="https://github.com/tabahi">
<span>
<!--- <b>Tabahi - Abdul Rehman</b> -->
</span>
<span>© Tabahi - Abdul Rehman 2021</span>
</a>
</div>
<!--- <script src="./dist/ml5.min.js"></script> -->
<script src="https://realtime-speech-emotion.netlify.app/webapp/assets/ml5.min.js"></script>
<script src="./dist/main.js"></script>
<script>
</script>
</body>
</html>