speaker-calibration 2.2.82 → 2.2.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.eslintignore +71 -71
  2. package/.eslintrc.json +40 -40
  3. package/.gitignore +81 -0
  4. package/.prettierignore +69 -69
  5. package/.prettierrc +14 -14
  6. package/LICENSE +20 -20
  7. package/README.md +133 -133
  8. package/__mocks__/fileMock.js +1 -1
  9. package/__mocks__/styleMock.js +1 -1
  10. package/babel.config.js +3 -3
  11. package/coverage/clover.xml +71 -71
  12. package/coverage/coverage-final.json +224 -224
  13. package/coverage/lcov-report/PythonServerInterface.js.html +265 -265
  14. package/coverage/lcov-report/base.css +354 -354
  15. package/coverage/lcov-report/block-navigation.js +82 -82
  16. package/coverage/lcov-report/index.html +123 -123
  17. package/coverage/lcov-report/prettify.css +101 -101
  18. package/coverage/lcov-report/prettify.js +937 -937
  19. package/coverage/lcov-report/sorter.js +189 -189
  20. package/coverage/lcov-report/src/index.html +121 -121
  21. package/coverage/lcov-report/src/server/PythonServerInterface.js.html +268 -268
  22. package/coverage/lcov-report/src/server/index.html +123 -123
  23. package/coverage/lcov-report/src/tasks/audioCalibrator.js.html +499 -499
  24. package/coverage/lcov-report/src/tasks/audioRecorder.js.html +412 -412
  25. package/coverage/lcov-report/src/tasks/index.html +143 -143
  26. package/coverage/lcov-report/src/tasks/volume/index.html +123 -123
  27. package/coverage/lcov-report/src/tasks/volume/volume.js.html +409 -409
  28. package/coverage/lcov-report/src/utils.js.html +172 -172
  29. package/coverage/lcov.info +91 -91
  30. package/dist/example/fetch-languages-sheets.js +77 -77
  31. package/dist/example/i18n.js +35846 -35846
  32. package/dist/example/index.html +47 -47
  33. package/dist/example/listener.html +62 -62
  34. package/dist/example/listener.js +95 -95
  35. package/dist/example/server.js +51 -51
  36. package/dist/example/speaker.html +145 -145
  37. package/dist/example/speakerUI.js +273 -273
  38. package/dist/example/styles.css +92 -92
  39. package/dist/main.js +17 -17
  40. package/dist/mlsGen.js +6814 -6814
  41. package/dist/mlsGen.wasm +0 -0
  42. package/dist/package-lock.json +1018 -1018
  43. package/dist/package.json +18 -18
  44. package/doc/AudioCalibrator.html +417 -417
  45. package/doc/AudioPeer.html +251 -251
  46. package/doc/AudioRecorder.html +195 -195
  47. package/doc/ImpulseResponse.html +215 -215
  48. package/doc/Listener.html +308 -308
  49. package/doc/MlsGenInterface.html +226 -226
  50. package/doc/MyEventEmitter.html +274 -274
  51. package/doc/PythonServerAPI.html +109 -109
  52. package/doc/Speaker.html +276 -276
  53. package/doc/Takes%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +128 -128
  54. package/doc/Takes%20the%20url%20of%20the%20current%20site%0Aand%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +138 -138
  55. package/doc/Takes%20the%20url%20of%20the%20current%20site%20and%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +137 -137
  56. package/doc/Volume.html +88 -88
  57. package/doc/audioCalibrator.js.html +179 -179
  58. package/doc/audioPeer.js.html +175 -175
  59. package/doc/audioRecorder.js.html +163 -163
  60. package/doc/creates%20a%20new%20AudioRecorder%20instance.%20%0ASets%20up%20the%20audio%20context%20and%20file%20reader..html +114 -114
  61. package/doc/fonts/OpenSans-Bold-webfont.svg +1829 -1829
  62. package/doc/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
  63. package/doc/fonts/OpenSans-Italic-webfont.svg +1829 -1829
  64. package/doc/fonts/OpenSans-Light-webfont.svg +1830 -1830
  65. package/doc/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
  66. package/doc/fonts/OpenSans-Regular-webfont.svg +1830 -1830
  67. package/doc/global.html +308 -308
  68. package/doc/index.html +58 -58
  69. package/doc/listener.js.html +170 -170
  70. package/doc/mlsGen_mlsGenInterface.js.html +117 -117
  71. package/doc/myEventEmitter.js.html +124 -124
  72. package/doc/peer-connection_audioPeer.js.html +188 -188
  73. package/doc/peer-connection_listener.js.html +311 -311
  74. package/doc/peer-connection_speaker.js.html +381 -381
  75. package/doc/scripts/linenumber.js +25 -25
  76. package/doc/scripts/prettify/Apache-License-2.0.txt +202 -202
  77. package/doc/scripts/prettify/lang-css.js +24 -24
  78. package/doc/scripts/prettify/prettify.js +640 -640
  79. package/doc/server_PythonServerAPI.js.html +160 -160
  80. package/doc/speaker.js.html +248 -248
  81. package/doc/styles/jsdoc-default.css +371 -371
  82. package/doc/styles/prettify-jsdoc.css +111 -111
  83. package/doc/styles/prettify-tomorrow.css +163 -163
  84. package/doc/tasks_audioCalibrator.js.html +207 -207
  85. package/doc/tasks_audioRecorder.js.html +190 -190
  86. package/doc/tasks_impulse-response_impulseResponse.js.html +442 -442
  87. package/doc/tasks_impulse-response_mlsGen_mlsGenInterface.js.html +175 -175
  88. package/doc/tasks_volume_volume.js.html +185 -185
  89. package/doc/utils.js.html +105 -105
  90. package/jest.config.js +173 -173
  91. package/netlify.toml +26 -26
  92. package/package.json +69 -69
  93. package/src/config/firebase.js +26 -26
  94. package/src/index.html +21 -21
  95. package/src/main.js +23 -23
  96. package/src/myEventEmitter.js +83 -83
  97. package/src/peer-connection/audioPeer.js +151 -151
  98. package/src/peer-connection/listener.js +310 -310
  99. package/src/peer-connection/peerErrors.js +25 -25
  100. package/src/peer-connection/speaker.js +454 -453
  101. package/src/server/PythonServerAPI.js +595 -591
  102. package/src/tasks/audioCalibrator.js +308 -308
  103. package/src/tasks/audioRecorder.js +281 -281
  104. package/src/tasks/combination/combination.js +2173 -2168
  105. package/src/tasks/combination/mlsGen/mlsGen.cpp +98 -98
  106. package/src/tasks/combination/mlsGen/mlsGen.hpp +303 -303
  107. package/src/tasks/combination/mlsGen/mlsGenInterface.js +131 -131
  108. package/src/tasks/combination/mlsGen/mlsGenTest.cpp +180 -180
  109. package/src/tasks/impulse-response/impulseResponse.js +610 -610
  110. package/src/tasks/impulse-response/mlsGen/mlsGen.cpp +98 -98
  111. package/src/tasks/impulse-response/mlsGen/mlsGen.hpp +303 -303
  112. package/src/tasks/impulse-response/mlsGen/mlsGenInterface.js +131 -131
  113. package/src/tasks/impulse-response/mlsGen/mlsGenTest.cpp +180 -180
  114. package/src/tasks/volume/volume.cpp +2 -2
  115. package/src/tasks/volume/volume.hpp +22 -22
  116. package/src/tasks/volume/volume.js +279 -279
  117. package/src/utils.js +88 -88
  118. package/webpack.config.js +37 -37
  119. package/makefile +0 -74
@@ -1,591 +1,595 @@
1
- import axios from 'axios';
2
- /**
3
- *
4
- */
5
- class PythonServerAPI {
6
- static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
7
-
8
- static TEST_SERVER_URL = 'http://127.0.0.1:5000';
9
- // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
10
-
11
- /** @private */
12
- MAX_RETRY_COUNT = 3;
13
- /** @private */
14
- RETRY_DELAY_MS = 1000;
15
- /**
16
- * @param data- -
17
- * g = inverted impulse response, when convolved with the impulse
18
- * reponse, they cancel out.
19
- * @param data.payload
20
- * @param data.sampleRate
21
- * @param data.P
22
- * @param data-.payload
23
- * @param data-.sampleRate
24
- * @param data-.P
25
- * @returns
26
- * @example
27
- */
28
- getImpulseResponse = async ({mls, payload, sampleRate, P, numPeriods}) => {
29
- const task = 'impulse-response';
30
- let res = null;
31
-
32
- console.log({payload});
33
-
34
- const data = JSON.stringify({
35
- task,
36
- payload,
37
- 'sample-rate': sampleRate,
38
- mls,
39
- P,
40
- numPeriods,
41
- });
42
-
43
- await axios({
44
- method: 'post',
45
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
46
- url: `/task/${task}`,
47
- headers: {
48
- 'Content-Type': 'application/json',
49
- },
50
- data,
51
- })
52
- .then(response => {
53
- res = response;
54
- })
55
- .catch(error => {
56
- throw error;
57
- });
58
- return res.data[task];
59
- };
60
-
61
- getMLS = async ({length,calibrateSoundBurstDb}) => {
62
- const task = 'mls';
63
- let res = null;
64
-
65
- const data = JSON.stringify({
66
- task,
67
- length: length,
68
- calibrateSoundBurstDb: calibrateSoundBurstDb
69
- });
70
-
71
- await axios({
72
- method: 'post',
73
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
74
- url: `/task/${task}`,
75
- headers: {
76
- 'Content-Type': 'application/json',
77
- },
78
- data,
79
- })
80
- .then(response => {
81
- res = response;
82
- })
83
- .catch(error => {
84
- throw error;
85
- });
86
-
87
- return res.data[task];
88
- };
89
- getMLSWithRetry = async ({length,calibrateSoundBurstDb}) => {
90
- let retryCount = 0;
91
- let response = null;
92
-
93
- while (retryCount < this.MAX_RETRY_COUNT) {
94
- try {
95
- response = await this.getMLS({length,calibrateSoundBurstDb});
96
- // If the request is successful, break out of the loop
97
- break;
98
- } catch (error) {
99
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
100
- retryCount++;
101
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
102
- }
103
- }
104
-
105
- if (response) {
106
- return response;
107
- } else {
108
- throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
109
- }
110
- };
111
-
112
- getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
113
- const task = 'psd';
114
- let res = null;
115
-
116
- const data = JSON.stringify({
117
- task,
118
- unconv_rec,
119
- conv_rec,
120
- sampleRate,
121
- });
122
-
123
- await axios({
124
- method: 'post',
125
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
126
- url: `/task/${task}`,
127
- headers: {
128
- 'Content-Type': 'application/json',
129
- },
130
- data,
131
- })
132
- .then(response => {
133
- res = response;
134
- })
135
- .catch(error => {
136
- throw error;
137
- });
138
- return res.data[task];
139
- };
140
-
141
- getBackgroundNoisePSD = async ({background_rec, sampleRate}) => {
142
- const task = 'background-psd';
143
- let res = null;
144
-
145
- const data = JSON.stringify({
146
- task,
147
- background_rec,
148
- sampleRate,
149
- });
150
-
151
- await axios({
152
- method: 'post',
153
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
154
- url: `/task/${task}`,
155
- headers: {
156
- 'Content-Type': 'application/json',
157
- },
158
- data,
159
- })
160
- .then(response => {
161
- res = response;
162
- })
163
- .catch(error => {
164
- throw error;
165
- });
166
- return res.data[task];
167
- };
168
-
169
- getBackgroundNoisePSDWithRetry = async ({background_rec, sampleRate}) => {
170
- let retryCount = 0;
171
- let response = null;
172
-
173
- while (retryCount < this.MAX_RETRY_COUNT) {
174
- try {
175
- response = await this.getBackgroundNoisePSD({background_rec, sampleRate});
176
- // If the request is successful, break out of the loop
177
- break;
178
- } catch (error) {
179
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
180
- retryCount++;
181
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
182
- }
183
- }
184
-
185
- if (response) {
186
- return response;
187
- } else {
188
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
189
- }
190
- };
191
-
192
- getSubtractedPSD = async (rec, knownGains, knownFrequencies, sampleRate) => {
193
- const task = 'subtracted-psd';
194
- let res = null;
195
-
196
- const data = JSON.stringify({
197
- task,
198
- rec,
199
- knownGains,
200
- knownFrequencies,
201
- sampleRate,
202
- });
203
-
204
- await axios({
205
- method: 'post',
206
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
207
- url: `/task/${task}`,
208
- headers: {
209
- 'Content-Type': 'application/json',
210
- },
211
- data,
212
- })
213
- .then(response => {
214
- res = response;
215
- })
216
- .catch(error => {
217
- throw error;
218
- });
219
- return res.data[task];
220
- };
221
-
222
- getSubtractedPSDWithRetry = async (rec, knownGains, knownFrequencies, sampleRate) => {
223
- let retryCount = 0;
224
- let response = null;
225
-
226
- while (retryCount < this.MAX_RETRY_COUNT) {
227
- try {
228
- response = await this.getSubtractedPSD(rec, knownGains, knownFrequencies, sampleRate);
229
- // If the request is successful, break out of the loop
230
- break;
231
- } catch (error) {
232
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
233
- retryCount++;
234
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
235
- }
236
- }
237
-
238
- if (response) {
239
- return response;
240
- } else {
241
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
242
- }
243
- };
244
-
245
- getPSDWithRetry = async ({unconv_rec, conv_rec, sampleRate}) => {
246
- let retryCount = 0;
247
- let response = null;
248
-
249
- while (retryCount < this.MAX_RETRY_COUNT) {
250
- try {
251
- response = await this.getPSD({unconv_rec, conv_rec, sampleRate});
252
- // If the request is successful, break out of the loop
253
- break;
254
- } catch (error) {
255
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
256
- retryCount++;
257
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
258
- }
259
- }
260
-
261
- if (response) {
262
- return response;
263
- } else {
264
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
265
- }
266
- };
267
-
268
- getComponentInverseImpulseResponse = async ({
269
- payload,
270
- mls,
271
- lowHz,
272
- highHz,
273
- componentIRGains,
274
- iirLength,
275
- componentIRFreqs,
276
- num_periods,
277
- sampleRate,
278
- calibrateSoundBurstDb,
279
- irLength
280
- }) => {
281
- const task = 'component-inverse-impulse-response';
282
- let res = null;
283
-
284
- console.log({payload});
285
-
286
- const data = JSON.stringify({
287
- task,
288
- payload,
289
- mls,
290
- lowHz,
291
- highHz,
292
- iirLength,
293
- componentIRGains,
294
- componentIRFreqs,
295
- num_periods,
296
- sampleRate,
297
- calibrateSoundBurstDb,
298
- irLength
299
- });
300
-
301
- await axios({
302
- method: 'post',
303
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
304
- url: `/task/${task}`,
305
- headers: {
306
- 'Content-Type': 'application/json',
307
- },
308
- data,
309
- })
310
- .then(response => {
311
- res = response;
312
- })
313
- .catch(error => {
314
- throw error;
315
- });
316
-
317
- return res.data[task];
318
- };
319
- getSystemInverseImpulseResponse = async ({
320
- payload,
321
- mls,
322
- lowHz,
323
- highHz,
324
- iirLength,
325
- num_periods,
326
- sampleRate,
327
- calibrateSoundBurstDb
328
- }) => {
329
- const task = 'system-inverse-impulse-response';
330
- let res = null;
331
-
332
- console.log({payload});
333
-
334
- const data = JSON.stringify({
335
- task,
336
- payload,
337
- mls,
338
- lowHz,
339
- iirLength,
340
- highHz,
341
- num_periods,
342
- sampleRate,
343
- calibrateSoundBurstDb
344
- });
345
-
346
- await axios({
347
- method: 'post',
348
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
349
- url: `/task/${task}`,
350
- headers: {
351
- 'Content-Type': 'application/json',
352
- },
353
- data,
354
- })
355
- .then(response => {
356
- res = response;
357
- })
358
- .catch(error => {
359
- throw error;
360
- });
361
-
362
- return res.data[task];
363
- };
364
-
365
- getMLSPSD = async ({mls, sampleRate}) => {
366
- const task = 'mls-psd';
367
- let res = null;
368
-
369
- const data = JSON.stringify({
370
- task,
371
- mls,
372
- sampleRate,
373
- });
374
-
375
- await axios({
376
- method: 'post',
377
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
378
- url: `/task/${task}`,
379
- headers: {
380
- 'Content-Type': 'application/json',
381
- },
382
- data,
383
- })
384
- .then(response => {
385
- res = response;
386
- })
387
- .catch(error => {
388
- throw error;
389
- });
390
-
391
- return res.data[task];
392
- };
393
-
394
- getMLSPSDWithRetry = async ({mls, sampleRate}) => {
395
- let retryCount = 0;
396
- let response = null;
397
-
398
- while (retryCount < this.MAX_RETRY_COUNT) {
399
- try {
400
- response = await this.getMLSPSD({mls, sampleRate});
401
- // If the request is successful, break out of the loop
402
- break;
403
- } catch (error) {
404
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
405
- retryCount++;
406
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
407
- }
408
- }
409
-
410
- if (response) {
411
- return response;
412
- } else {
413
- throw new Error(
414
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
415
- );
416
- }
417
- };
418
-
419
- getComponentInverseImpulseResponseWithRetry = async ({
420
- payload,
421
- mls,
422
- lowHz,
423
- highHz,
424
- componentIRGains,
425
- iirLength,
426
- componentIRFreqs,
427
- num_periods,
428
- sampleRate,
429
- calibrateSoundBurstDb,
430
- irLength
431
- }) => {
432
- let retryCount = 0;
433
- let response = null;
434
-
435
- while (retryCount < this.MAX_RETRY_COUNT) {
436
- try {
437
- response = await this.getComponentInverseImpulseResponse({
438
- payload,
439
- mls,
440
- lowHz,
441
- highHz,
442
- componentIRGains,
443
- iirLength,
444
- componentIRFreqs,
445
- num_periods,
446
- sampleRate,
447
- calibrateSoundBurstDb,
448
- irLength
449
- });
450
- // If the request is successful, break out of the loop
451
- break;
452
- } catch (error) {
453
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
454
- retryCount++;
455
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
456
- }
457
- }
458
-
459
- if (response) {
460
- return response;
461
- } else {
462
- throw new Error(
463
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
464
- );
465
- }
466
- };
467
-
468
- getSystemInverseImpulseResponseWithRetry = async ({
469
- payload,
470
- mls,
471
- lowHz,
472
- highHz,
473
- iirLength,
474
- num_periods,
475
- sampleRate,
476
- calibrateSoundBurstDb
477
- }) => {
478
- let retryCount = 0;
479
- let response = null;
480
-
481
- while (retryCount < this.MAX_RETRY_COUNT) {
482
- try {
483
- response = await this.getSystemInverseImpulseResponse({
484
- payload,
485
- mls,
486
- lowHz,
487
- highHz,
488
- iirLength,
489
- num_periods,
490
- sampleRate,
491
- calibrateSoundBurstDb
492
- });
493
- // If the request is successful, break out of the loop
494
- break;
495
- } catch (error) {
496
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
497
- retryCount++;
498
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
499
- }
500
- }
501
-
502
- if (response) {
503
- return response;
504
- } else {
505
- throw new Error(
506
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
507
- );
508
- }
509
- };
510
-
511
- getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
512
- const task = 'volume';
513
- let res = null;
514
-
515
- console.log({payload});
516
-
517
- const data = JSON.stringify({
518
- task,
519
- payload,
520
- 'sample-rate': sampleRate,
521
- lCalib,
522
- });
523
-
524
- await axios({
525
- method: 'post',
526
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
527
- url: `/task/${task}`,
528
- headers: {
529
- 'Content-Type': 'application/json',
530
- },
531
- data,
532
- })
533
- .then(response => {
534
- res = response;
535
- })
536
- .catch(error => {
537
- throw error;
538
- });
539
-
540
- return res.data[task];
541
- };
542
-
543
- getVolumeCalibrationParameters = async ({
544
- inDBValues,
545
- outDBSPLValues,
546
- lCalib,
547
- componentGainDBSPL,
548
- }) => {
549
- const task = 'volume-parameters';
550
- let res = null;
551
-
552
- const data = JSON.stringify({
553
- task,
554
- inDBValues,
555
- outDBSPLValues,
556
- lCalib,
557
- componentGainDBSPL,
558
- });
559
-
560
- await axios({
561
- method: 'post',
562
- baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
563
- url: `/task/${task}`,
564
- headers: {
565
- 'Content-Type': 'application/json',
566
- },
567
- data,
568
- })
569
- .then(response => {
570
- res = response;
571
- console.log(res.data[task]);
572
- })
573
- .catch(error => {
574
- throw error;
575
- });
576
-
577
- // console.log(res.data[task]);
578
- //below is an example of res.data[task]
579
- //{
580
- // R: 16.56981076554259,
581
- // RMSError: 1.9289162528535229
582
- // T: -47.79799120884434,
583
- // W: 61.0485247483732,
584
- // backgroundDBSPL: 43.88233142069752,
585
- // gainDBSPL: -128.24742161208985
586
- //}
587
- return res.data[task];
588
- };
589
- }
590
-
591
- export default PythonServerAPI;
1
+ import axios from 'axios';
2
+ /**
3
+ *
4
+ */
5
+ class PythonServerAPI {
6
+ static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
7
+
8
+ static TEST_SERVER_URL = 'http://127.0.0.1:5000';
9
+ // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
10
+
11
+ /** @private */
12
+ MAX_RETRY_COUNT = 3;
13
+ /** @private */
14
+ RETRY_DELAY_MS = 1000;
15
+ /**
16
+ * @param data- -
17
+ * g = inverted impulse response, when convolved with the impulse
18
+ * reponse, they cancel out.
19
+ * @param data.payload
20
+ * @param data.sampleRate
21
+ * @param data.P
22
+ * @param data-.payload
23
+ * @param data-.sampleRate
24
+ * @param data-.P
25
+ * @returns
26
+ * @example
27
+ */
28
+ getImpulseResponse = async ({mls, payload, sampleRate, P, numPeriods}) => {
29
+ const task = 'impulse-response';
30
+ let res = null;
31
+
32
+ console.log({payload});
33
+
34
+ const data = JSON.stringify({
35
+ task,
36
+ payload,
37
+ 'sample-rate': sampleRate,
38
+ mls,
39
+ P,
40
+ numPeriods,
41
+ });
42
+
43
+ await axios({
44
+ method: 'post',
45
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
46
+ url: `/task/${task}`,
47
+ headers: {
48
+ 'Content-Type': 'application/json',
49
+ },
50
+ data,
51
+ })
52
+ .then(response => {
53
+ res = response;
54
+ })
55
+ .catch(error => {
56
+ throw error;
57
+ });
58
+ return res.data[task];
59
+ };
60
+
61
+ getMLS = async ({length,calibrateSoundBurstDb}) => {
62
+ const task = 'mls';
63
+ let res = null;
64
+
65
+ const data = JSON.stringify({
66
+ task,
67
+ length: length,
68
+ calibrateSoundBurstDb: calibrateSoundBurstDb
69
+ });
70
+
71
+ await axios({
72
+ method: 'post',
73
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
74
+ url: `/task/${task}`,
75
+ headers: {
76
+ 'Content-Type': 'application/json',
77
+ },
78
+ data,
79
+ })
80
+ .then(response => {
81
+ res = response;
82
+ })
83
+ .catch(error => {
84
+ throw error;
85
+ });
86
+
87
+ return res.data[task];
88
+ };
89
+ getMLSWithRetry = async ({length,calibrateSoundBurstDb}) => {
90
+ let retryCount = 0;
91
+ let response = null;
92
+
93
+ while (retryCount < this.MAX_RETRY_COUNT) {
94
+ try {
95
+ response = await this.getMLS({length,calibrateSoundBurstDb});
96
+ // If the request is successful, break out of the loop
97
+ break;
98
+ } catch (error) {
99
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
100
+ retryCount++;
101
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
102
+ }
103
+ }
104
+
105
+ if (response) {
106
+ return response;
107
+ } else {
108
+ throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
109
+ }
110
+ };
111
+
112
+ getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
113
+ const task = 'psd';
114
+ let res = null;
115
+
116
+ const data = JSON.stringify({
117
+ task,
118
+ unconv_rec,
119
+ conv_rec,
120
+ sampleRate,
121
+ });
122
+
123
+ await axios({
124
+ method: 'post',
125
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
126
+ url: `/task/${task}`,
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ },
130
+ data,
131
+ })
132
+ .then(response => {
133
+ res = response;
134
+ })
135
+ .catch(error => {
136
+ throw error;
137
+ });
138
+ return res.data[task];
139
+ };
140
+
141
+ getBackgroundNoisePSD = async ({background_rec, sampleRate}) => {
142
+ const task = 'background-psd';
143
+ let res = null;
144
+
145
+ const data = JSON.stringify({
146
+ task,
147
+ background_rec,
148
+ sampleRate,
149
+ });
150
+
151
+ await axios({
152
+ method: 'post',
153
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
154
+ url: `/task/${task}`,
155
+ headers: {
156
+ 'Content-Type': 'application/json',
157
+ },
158
+ data,
159
+ })
160
+ .then(response => {
161
+ res = response;
162
+ })
163
+ .catch(error => {
164
+ throw error;
165
+ });
166
+ return res.data[task];
167
+ };
168
+
169
+ getBackgroundNoisePSDWithRetry = async ({background_rec, sampleRate}) => {
170
+ let retryCount = 0;
171
+ let response = null;
172
+
173
+ while (retryCount < this.MAX_RETRY_COUNT) {
174
+ try {
175
+ response = await this.getBackgroundNoisePSD({background_rec, sampleRate});
176
+ // If the request is successful, break out of the loop
177
+ break;
178
+ } catch (error) {
179
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
180
+ retryCount++;
181
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
182
+ }
183
+ }
184
+
185
+ if (response) {
186
+ return response;
187
+ } else {
188
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
189
+ }
190
+ };
191
+
192
+ getSubtractedPSD = async (rec, knownGains, knownFrequencies, sampleRate) => {
193
+ const task = 'subtracted-psd';
194
+ let res = null;
195
+
196
+ const data = JSON.stringify({
197
+ task,
198
+ rec,
199
+ knownGains,
200
+ knownFrequencies,
201
+ sampleRate,
202
+ });
203
+
204
+ await axios({
205
+ method: 'post',
206
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
207
+ url: `/task/${task}`,
208
+ headers: {
209
+ 'Content-Type': 'application/json',
210
+ },
211
+ data,
212
+ })
213
+ .then(response => {
214
+ res = response;
215
+ })
216
+ .catch(error => {
217
+ throw error;
218
+ });
219
+ return res.data[task];
220
+ };
221
+
222
+ getSubtractedPSDWithRetry = async (rec, knownGains, knownFrequencies, sampleRate) => {
223
+ let retryCount = 0;
224
+ let response = null;
225
+
226
+ while (retryCount < this.MAX_RETRY_COUNT) {
227
+ try {
228
+ response = await this.getSubtractedPSD(rec, knownGains, knownFrequencies, sampleRate);
229
+ // If the request is successful, break out of the loop
230
+ break;
231
+ } catch (error) {
232
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
233
+ retryCount++;
234
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
235
+ }
236
+ }
237
+
238
+ if (response) {
239
+ return response;
240
+ } else {
241
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
242
+ }
243
+ };
244
+
245
+ getPSDWithRetry = async ({unconv_rec, conv_rec, sampleRate}) => {
246
+ let retryCount = 0;
247
+ let response = null;
248
+
249
+ while (retryCount < this.MAX_RETRY_COUNT) {
250
+ try {
251
+ response = await this.getPSD({unconv_rec, conv_rec, sampleRate});
252
+ // If the request is successful, break out of the loop
253
+ break;
254
+ } catch (error) {
255
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
256
+ retryCount++;
257
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
258
+ }
259
+ }
260
+
261
+ if (response) {
262
+ return response;
263
+ } else {
264
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
265
+ }
266
+ };
267
+
268
+ getComponentInverseImpulseResponse = async ({
269
+ payload,
270
+ mls,
271
+ lowHz,
272
+ highHz,
273
+ componentIRGains,
274
+ iirLength,
275
+ componentIRFreqs,
276
+ num_periods,
277
+ sampleRate,
278
+ calibrateSoundBurstDb,
279
+ irLength,
280
+ calibrateSoundSmoothOctaves
281
+ }) => {
282
+ const task = 'component-inverse-impulse-response';
283
+ let res = null;
284
+
285
+ console.log({payload});
286
+
287
+ const data = JSON.stringify({
288
+ task,
289
+ payload,
290
+ mls,
291
+ lowHz,
292
+ highHz,
293
+ iirLength,
294
+ componentIRGains,
295
+ componentIRFreqs,
296
+ num_periods,
297
+ sampleRate,
298
+ calibrateSoundBurstDb,
299
+ irLength,
300
+ calibrateSoundSmoothOctaves
301
+ });
302
+
303
+ await axios({
304
+ method: 'post',
305
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
306
+ url: `/task/${task}`,
307
+ headers: {
308
+ 'Content-Type': 'application/json',
309
+ },
310
+ data,
311
+ })
312
+ .then(response => {
313
+ res = response;
314
+ })
315
+ .catch(error => {
316
+ throw error;
317
+ });
318
+
319
+ return res.data[task];
320
+ };
321
+ getSystemInverseImpulseResponse = async ({
322
+ payload,
323
+ mls,
324
+ lowHz,
325
+ highHz,
326
+ iirLength,
327
+ num_periods,
328
+ sampleRate,
329
+ calibrateSoundBurstDb
330
+ }) => {
331
+ const task = 'system-inverse-impulse-response';
332
+ let res = null;
333
+
334
+ console.log({payload});
335
+
336
+ const data = JSON.stringify({
337
+ task,
338
+ payload,
339
+ mls,
340
+ lowHz,
341
+ iirLength,
342
+ highHz,
343
+ num_periods,
344
+ sampleRate,
345
+ calibrateSoundBurstDb
346
+ });
347
+
348
+ await axios({
349
+ method: 'post',
350
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
351
+ url: `/task/${task}`,
352
+ headers: {
353
+ 'Content-Type': 'application/json',
354
+ },
355
+ data,
356
+ })
357
+ .then(response => {
358
+ res = response;
359
+ })
360
+ .catch(error => {
361
+ throw error;
362
+ });
363
+
364
+ return res.data[task];
365
+ };
366
+
367
+ getMLSPSD = async ({mls, sampleRate}) => {
368
+ const task = 'mls-psd';
369
+ let res = null;
370
+
371
+ const data = JSON.stringify({
372
+ task,
373
+ mls,
374
+ sampleRate,
375
+ });
376
+
377
+ await axios({
378
+ method: 'post',
379
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
380
+ url: `/task/${task}`,
381
+ headers: {
382
+ 'Content-Type': 'application/json',
383
+ },
384
+ data,
385
+ })
386
+ .then(response => {
387
+ res = response;
388
+ })
389
+ .catch(error => {
390
+ throw error;
391
+ });
392
+
393
+ return res.data[task];
394
+ };
395
+
396
+ getMLSPSDWithRetry = async ({mls, sampleRate}) => {
397
+ let retryCount = 0;
398
+ let response = null;
399
+
400
+ while (retryCount < this.MAX_RETRY_COUNT) {
401
+ try {
402
+ response = await this.getMLSPSD({mls, sampleRate});
403
+ // If the request is successful, break out of the loop
404
+ break;
405
+ } catch (error) {
406
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
407
+ retryCount++;
408
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
409
+ }
410
+ }
411
+
412
+ if (response) {
413
+ return response;
414
+ } else {
415
+ throw new Error(
416
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
417
+ );
418
+ }
419
+ };
420
+
421
+ getComponentInverseImpulseResponseWithRetry = async ({
422
+ payload,
423
+ mls,
424
+ lowHz,
425
+ highHz,
426
+ componentIRGains,
427
+ iirLength,
428
+ componentIRFreqs,
429
+ num_periods,
430
+ sampleRate,
431
+ calibrateSoundBurstDb,
432
+ irLength,
433
+ calibrateSoundSmoothOctaves
434
+ }) => {
435
+ let retryCount = 0;
436
+ let response = null;
437
+
438
+ while (retryCount < this.MAX_RETRY_COUNT) {
439
+ try {
440
+ response = await this.getComponentInverseImpulseResponse({
441
+ payload,
442
+ mls,
443
+ lowHz,
444
+ highHz,
445
+ componentIRGains,
446
+ iirLength,
447
+ componentIRFreqs,
448
+ num_periods,
449
+ sampleRate,
450
+ calibrateSoundBurstDb,
451
+ irLength,
452
+ calibrateSoundSmoothOctaves
453
+ });
454
+ // If the request is successful, break out of the loop
455
+ break;
456
+ } catch (error) {
457
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
458
+ retryCount++;
459
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
460
+ }
461
+ }
462
+
463
+ if (response) {
464
+ return response;
465
+ } else {
466
+ throw new Error(
467
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
468
+ );
469
+ }
470
+ };
471
+
472
+ getSystemInverseImpulseResponseWithRetry = async ({
473
+ payload,
474
+ mls,
475
+ lowHz,
476
+ highHz,
477
+ iirLength,
478
+ num_periods,
479
+ sampleRate,
480
+ calibrateSoundBurstDb
481
+ }) => {
482
+ let retryCount = 0;
483
+ let response = null;
484
+
485
+ while (retryCount < this.MAX_RETRY_COUNT) {
486
+ try {
487
+ response = await this.getSystemInverseImpulseResponse({
488
+ payload,
489
+ mls,
490
+ lowHz,
491
+ highHz,
492
+ iirLength,
493
+ num_periods,
494
+ sampleRate,
495
+ calibrateSoundBurstDb
496
+ });
497
+ // If the request is successful, break out of the loop
498
+ break;
499
+ } catch (error) {
500
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
501
+ retryCount++;
502
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
503
+ }
504
+ }
505
+
506
+ if (response) {
507
+ return response;
508
+ } else {
509
+ throw new Error(
510
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
511
+ );
512
+ }
513
+ };
514
+
515
+ getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
516
+ const task = 'volume';
517
+ let res = null;
518
+
519
+ console.log({payload});
520
+
521
+ const data = JSON.stringify({
522
+ task,
523
+ payload,
524
+ 'sample-rate': sampleRate,
525
+ lCalib,
526
+ });
527
+
528
+ await axios({
529
+ method: 'post',
530
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
531
+ url: `/task/${task}`,
532
+ headers: {
533
+ 'Content-Type': 'application/json',
534
+ },
535
+ data,
536
+ })
537
+ .then(response => {
538
+ res = response;
539
+ })
540
+ .catch(error => {
541
+ throw error;
542
+ });
543
+
544
+ return res.data[task];
545
+ };
546
+
547
+ getVolumeCalibrationParameters = async ({
548
+ inDBValues,
549
+ outDBSPLValues,
550
+ lCalib,
551
+ componentGainDBSPL,
552
+ }) => {
553
+ const task = 'volume-parameters';
554
+ let res = null;
555
+
556
+ const data = JSON.stringify({
557
+ task,
558
+ inDBValues,
559
+ outDBSPLValues,
560
+ lCalib,
561
+ componentGainDBSPL,
562
+ });
563
+
564
+ await axios({
565
+ method: 'post',
566
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
567
+ url: `/task/${task}`,
568
+ headers: {
569
+ 'Content-Type': 'application/json',
570
+ },
571
+ data,
572
+ })
573
+ .then(response => {
574
+ res = response;
575
+ console.log(res.data[task]);
576
+ })
577
+ .catch(error => {
578
+ throw error;
579
+ });
580
+
581
+ // console.log(res.data[task]);
582
+ //below is an example of res.data[task]
583
+ //{
584
+ // R: 16.56981076554259,
585
+ // RMSError: 1.9289162528535229
586
+ // T: -47.79799120884434,
587
+ // W: 61.0485247483732,
588
+ // backgroundDBSPL: 43.88233142069752,
589
+ // gainDBSPL: -128.24742161208985
590
+ //}
591
+ return res.data[task];
592
+ };
593
+ }
594
+
595
+ export default PythonServerAPI;